Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fe3703def2dadf5ee7543a8625215fbd7d7a9cc6 (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
# *******************************************************************************
# * 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
# *******************************************************************************

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

from tcf import services

NAME = "LineNumbers"

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, 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 file: h += hash(file)
        return h + self.start_line + self.start_column + self.end_line + self.end_column

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

class LineNumbersService(services.Service):
    def getName(self):
        return NAME

    def mapToSource(self, context_id, start_address, end_address, done):
        raise NotImplementedError("Abstract method")

    def mapToMemory(self, context_id, file, line, column, done):
        raise NotImplementedError("Abstract method")

class DoneMapToSource(object):
    def doneMapToSource(self, token, error, areas):
        pass

class DoneMapToMemory(object):
    def doneMapToMemory(self, token, error, areas):
        pass

Back to the top