Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1cb47b363bdcf1a2cd57727655fcbfbaf8c7dd84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#******************************************************************************
# * Copyright (c) 2011 Wind River Systems, Inc. and others.
# * All rights reserved. This program and the accompanying materials
# * are made available under the terms of the Eclipse Public License v1.0
# * which accompanies this distribution, and is available at
# * http://www.eclipse.org/legal/epl-v10.html
# * 
# * Contributors:
# *     Wind River Systems - initial API and implementation
#******************************************************************************

import exceptions
from tcf import services

NAME = "StackTrace"

#
# Stack frame context property names.
#
PROP_ID = "ID"                         # String, stack frame ID
PROP_PARENT_ID = "ParentID"            # String, stack frame parent ID
PROP_PROCESS_ID = "ProcessID"          # String, stack frame process ID
PROP_NAME = "Name"                     # String, human readable name
PROP_TOP_FRAME = "TopFrame"            # Boolean, true if the frame is top frame on a stack
PROP_LEVEL = "Level"                   # Integer, stack frame level, starting from stack bottom
PROP_FRAME_ADDRESS = "FP"              # Number, stack frame memory address
PROP_RETURN_ADDRESS = "RP"             # Number, return address
PROP_INSTRUCTION_ADDRESS = "IP"        # Number, instruction pointer
PROP_ARGUMENTS_COUNT = "ArgsCnt"       # Integer, number of function arguments
PROP_ARGUMENTS_ADDRESS = "ArgsAddr"    # Number, memory address of function arguments

class StackTraceService(services.Service):
    def getName(self):
        return NAME
    
    def getContext(self, ids, done):
        """
        Retrieve context info for given context IDs.
        
        The command will fail if parent thread is not suspended.
        Client can use Run Control service to suspend a thread.
        
        @param ids - array of context IDs.
        @param done - call back interface called when operation is completed.
        """
        raise exceptions.NotImplementedError("Abstract method")
        
    def getChildren(self, parent_context_id, done):
        """
        Retrieve stack trace context list.
        Parent context usually corresponds to an execution thread.
        Some targets have more then one stack. In such case children of a thread
        are stacks, and stack frames are deeper in the hierarchy - they can be
        retrieved with additional getChildren commands.
        
        The command will fail if parent thread is not suspended.
        Client can use Run Control service to suspend a thread.
        
        @param parent_context_id - parent context ID.
        @param done - call back interface called when operation is completed.
        """
        raise exceptions.NotImplementedError("Abstract method")

class DoneGetContext(object):
    """
    Client call back interface for getContext().
    """
    def doneGetContext(self, token, error, contexts):
        """
        Called when context data retrieval is done.
        @param error - error description if operation failed, null if succeeded.
        @param contexts - array of context data or null if error.
        """
        pass

class DoneGetChildren(object):
    """
    Client call back interface for getChildren().
    """
    def doneGetChildren(self, token, error, context_ids):
        """
        Called when context list retrieval is done.
        @param error - error description if operation failed, null if succeeded.
        @param context_ids - array of available context IDs.
        Stack frames are ordered from stack bottom to top.
        """
        pass

class StackTraceContext(object):
    """
    StackTraceContext represents stack trace objects - stacks and stack frames.
    """
    def __init__(self, props):
        self._props = props or {}
    
    def __str__(self):
        return "[Stack Trace Context %s]" % self._props

    def getID(self):
        """
        Get Context ID.
        @return context ID.
        """
        return self._props.get(PROP_ID)
    
    def getParentID(self):
        """
        Get parent context ID.
        @return parent context ID.
        """
        return self._props.get(PROP_PARENT_ID)

    def getName(self):
        """
        Get context name - if context represents a stack.
        @return context name or null.
        """
        return self._props.get(PROP_NAME)

    def getFrameAddress(self):
        """
        Get memory address of this frame.
        @return address or None if not a stack frame.
        """
        return self._props.get(PROP_FRAME_ADDRESS)

    def getReturnAddress(self):
        """
        Get program counter saved in this stack frame -
        it is address of instruction to be executed when the function returns.
        @return return address or null if not a stack frame.
        """
        return self._props.get(PROP_RETURN_ADDRESS)

    def getInstructionAddress(self):
        """
        Get address of the next instruction to be executed in this stack frame.
        For top frame it is same as PC register value.
        For other frames it is same as return address of the next frame.
        @return instruction address or null if not a stack frame.
        """
        return self._props.get(PROP_INSTRUCTION_ADDRESS)

    def getArgumentsCount(self):
        """
        Get number of function arguments for this frame.
        @return function arguments count.
        """
        return self._props.get(PROP_ARGUMENTS_COUNT)

    def getArgumentsAddress(self):
        """
        Get address of function arguments area in memory.
        @return function arguments address or null if not available.
        """
        return self._props.get(PROP_ARGUMENTS_ADDRESS, 0)

    def getProperties(self):
        """
        Get complete map of context properties.
        @return map of context properties.
        """
        return self._props

Back to the top