xref: /freebsd/contrib/llvm-project/lldb/bindings/interface/SBAddressExtensions.i (revision c57c26179033f64c2011a2d2a904ee3fa62e826a)
1 STRING_EXTENSION_OUTSIDE(SBAddress)
2 
3 %extend lldb::SBAddress {
4 #ifdef SWIGPYTHON
5     %pythoncode%{
6     # operator== is a free function, which swig does not handle, so we inject
7     # our own equality operator here
8     def __eq__(self, other):
9       return not self.__ne__(other)
10     %}
11 
12     %pythoncode %{
13         __runtime_error_str = 'This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'
14 
15         def __get_load_addr_property__ (self):
16             '''Get the load address for a lldb.SBAddress using the current target. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'''
17             if not target:
18                 raise RuntimeError(self.__runtime_error_str)
19             return self.GetLoadAddress (target)
20 
21         def __set_load_addr_property__ (self, load_addr):
22             '''Set the load address for a lldb.SBAddress using the current target. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'''
23             if not target:
24                 raise RuntimeError(self.__runtime_error_str)
25             return self.SetLoadAddress (load_addr, target)
26 
27         def __int__(self):
28             '''Convert an address to a load address if there is a process and that process is alive, or to a file address otherwise. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'''
29             if not process or not target:
30                 raise RuntimeError(self.__runtime_error_str)
31             if process.is_alive:
32                 return self.GetLoadAddress (target)
33             return self.GetFileAddress ()
34 
35         def __oct__(self):
36             '''Convert the address to an octal string. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'''
37             return '%o' % int(self)
38 
39         def __hex__(self):
40             '''Convert the address to an hex string. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.'''
41             return '0x%x' % int(self)
42 
43         module = property(GetModule, None, doc='''A read only property that returns an lldb object that represents the module (lldb.SBModule) that this address resides within.''')
44         compile_unit = property(GetCompileUnit, None, doc='''A read only property that returns an lldb object that represents the compile unit (lldb.SBCompileUnit) that this address resides within.''')
45         line_entry = property(GetLineEntry, None, doc='''A read only property that returns an lldb object that represents the line entry (lldb.SBLineEntry) that this address resides within.''')
46         function = property(GetFunction, None, doc='''A read only property that returns an lldb object that represents the function (lldb.SBFunction) that this address resides within.''')
47         block = property(GetBlock, None, doc='''A read only property that returns an lldb object that represents the block (lldb.SBBlock) that this address resides within.''')
48         symbol = property(GetSymbol, None, doc='''A read only property that returns an lldb object that represents the symbol (lldb.SBSymbol) that this address resides within.''')
49         offset = property(GetOffset, None, doc='''A read only property that returns the section offset in bytes as an integer.''')
50         section = property(GetSection, None, doc='''A read only property that returns an lldb object that represents the section (lldb.SBSection) that this address resides within.''')
51         file_addr = property(GetFileAddress, None, doc='''A read only property that returns file address for the section as an integer. This is the address that represents the address as it is found in the object file that defines it.''')
52         load_addr = property(__get_load_addr_property__, __set_load_addr_property__, doc='''A read/write property that gets/sets the SBAddress using load address. This resolves the SBAddress using the SBTarget from lldb.target so this property can ONLY be used in the interactive script interpreter (i.e. under the lldb script command). For things like Python based commands and breakpoint callbacks use GetLoadAddress instead.''')
53     %}
54 #endif
55 }
56