1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
7 """A dictionary of symbols indexed by the key 'exec_path+0xoffset'."""
10 self.symbols = {} # 'foo.so+0x1234' -> |Symbol|
12 def Add(self, exec_file_rel_path, offset, symbol):
13 assert(isinstance(symbol, Symbol))
14 self.symbols[Symbols._GetKey(exec_file_rel_path, offset)] = symbol
16 def Lookup(self, exec_file_rel_path, offset):
17 return self.symbols.get(Symbols._GetKey(exec_file_rel_path, offset))
19 def Merge(self, other):
20 assert(isinstance(other, Symbols))
21 self.symbols.update(other.symbols) # pylint: disable=W0212
24 return len(self.symbols)
27 def _GetKey(exec_file_rel_path, offset):
28 return '%s+0x%x' % (exec_file_rel_path, offset)
32 """Debug information relative to a symbol.
34 Note: a symbol can have more than one source line associated to it.
37 def __init__(self, name, source_file_path=None, line_number=None):
41 self.AddSourceLineInfo(source_file_path, line_number or 0)
43 def AddSourceLineInfo(self, source_file_path, line_number):
44 self.source_info += [SourceInfo(source_file_path, line_number)]
49 self.source_info[0] if len(self.source_info) else '')
52 class SourceInfo(object):
53 """Source file + line information for a given |Symbol|."""
55 def __init__(self, source_file_path, line_number):
56 assert(isinstance(line_number, int))
57 self.source_file_path = source_file_path
58 self.line_number = line_number
61 return '%s:%d' % (self.source_file_path, self.line_number)