Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e32ae3deee2edcb7f0c0a6c1393ac3da6d529624 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# *****************************************************************************
# * Copyright (c) 2011, 2013-2014, 2016 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
# *****************************************************************************

"""Line numbers service associates locations in the source files with the
corresponding machine instruction addresses in the executable object.

Service Methods
---------------
.. autodata:: NAME
.. autoclass:: LineNumbersService

getName
^^^^^^^
.. automethod:: LineNumbersService.getName

mapToMemory
^^^^^^^^^^^
.. automethod:: LineNumbersService.mapToMemory

mapToSource
^^^^^^^^^^^
.. automethod:: LineNumbersService.mapToSource

Callback Classes
----------------
DoneMapToMemory
^^^^^^^^^^^^^^^
.. autoclass:: DoneMapToMemory
    :members:

DoneMapToSource
^^^^^^^^^^^^^^^
.. autoclass:: DoneMapToSource
    :members:

Helper Classes
--------------
CodeArea
^^^^^^^^
.. autoclass:: CodeArea
    :members:
"""

from .. import services

NAME = "LineNumbers"
"""LineNumbers service name."""


class CodeArea(object):
    """A CodeArea represents a continues area in source text mapped to
    continues range of code addresses.

    Line and columns are counted starting from 1.

    File name can be a relative path, in this case the client should use the
    CodeArea directory name as origin for the path.

    File and directory names are valid on a host where code was compiled.

    It is client responsibility to map names to local host file system.
    """
    def __init__(self, directory, file, start_line,  # @ReservedAssignment
                 start_column, end_line, end_column, start_address,
                 end_address, isa, is_statement, basic_block, prologue_end,
                 epilogue_begin):
        self.directory = directory
        self.file = file
        self.start_line = start_line
        self.start_column = start_column
        self.end_line = end_line
        self.end_column = end_column
        self.start_address = start_address
        self.end_address = end_address
        self.isa = isa
        self.is_statement = is_statement
        self.basic_block = basic_block
        self.prologue_end = prologue_end
        self.epilogue_begin = epilogue_begin

    def __eq__(self, o):
        if self is o:
            return True
        if not isinstance(o, CodeArea):
            return False
        if self.start_line != o.start_line:
            return False
        if self.start_column != o.start_column:
            return False
        if self.end_line != o.end_line:
            return False
        if self.end_column != o.end_column:
            return False
        if self.isa != o.isa:
            return False
        if self.is_statement != o.is_statement:
            return False
        if self.basic_block != o.basic_block:
            return False
        if self.prologue_end != o.prologue_end:
            return False
        if self.epilogue_begin != o.epilogue_begin:
            return False
        if self.start_address != o.start_address:
            return False
        if self.end_address != o.end_address:
            return False
        if self.file != o.file:
            return False
        if self.directory != o.directory:
            return False
        return True

    def __hash__(self):
        h = 0
        if self.file:
            h += hash(self.file)
        return h + self.start_line + self.start_column + self.end_line + \
            self.end_column

    def __str__(self):
        res = '['
        if self.directory:
            res += str(self.directory) + ':'
        if self.file:
            res += str(self.file) + ':'
        res += str(self.start_line)
        if self.start_column:
            res += '.' + str(self.start_column)
        res += '..' + str(self.end_line)
        if self.end_column:
            res += '.' + str(self.end_column)
        res += ' -> '
        if self.start_address:
            res += '0x' + str(hex(self.start_address))
        else:
            res += '0'
        res += '..'
        if self.end_address:
            res += '0x' + str(hex(self.end_address))
        else:
            res += '0'
        if self.isa:
            res += ',isa ' + str(self.isa)
        if self.is_statement:
            res += ',statement'
        if self.basic_block:
            res += ',basic block'
        if self.prologue_end:
            res += ',prologue end'
        if self.epilogue_begin:
            res += ',epilogue begin'
        res += ']'
        return res


class LineNumbersService(services.Service):
    """TCF LineNumbers service interface."""

    def getName(self):
        """Get this service name.

        :returns: The value of string :const:`NAME`
        """
        return NAME

    def mapToSource(self, context_id, start_address, end_address, done):
        """Get the line numbers source for a context ID and a memory address.

        :param context_id: ID of the context to get source map for.
        :type context_id: |basestring|
        :param start_address: Memory start address to get source map for.
        :type start_address: |int|
        :param end_address: Memory end address to get source map for.
        :type end_address: |int|
        :param done: Call back interface called when operation is completed
        :type done: :class:`DoneMapToSource`
        """
        raise NotImplementedError("Abstract method")

    def mapToMemory(self, context_id, fileName, line, column, done):
        """Get the the memory address of a context ID for a given file and line
        number.

        :param context_id: ID of the context to get source map for.
        :type context_id: |basestring|
        :param fileName: Name of the file to map memory for.
        :type fileName: |basestring|
        :param line: Source file line to map to a memory address.
        :type line: |int|
        :param column: Source file column to map to a memory address.
        :type column: |int|
        :param done: Call back interface called when operation is completed.
        :type done: :class:`DoneMapToMemory`
        """
        raise NotImplementedError("Abstract method")


class DoneMapToSource(object):
    """
    Client callback interface for :meth:`~LineNumbersService.mapToSource`.
    """

    def doneMapToSource(self, token, error, areas):
        """Called when context data retrieval is done.

        :param token: pending command handle
        :param error: error description if operation failed, **None** if
                      succeeded.
        :param areas: A |list| of :class:`CodeArea` objects.
        """
        pass


class DoneMapToMemory(object):
    """
    Client callback interface for :meth:`~LineNumbersService.mapToMemory`.
    """
    def doneMapToMemory(self, token, error, areas):
        """Called when context data retrieval is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param areas: A |list| of :class:`CodeArea` objects.
        """
        pass

Back to the top