[Lldb-commits] [PATCH] D80848: [lldb/Bindings] Raise a Runtime error when using SBAddress properties that rely on lldb.target

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri May 29 15:20:23 PDT 2020


JDevlieghere created this revision.
JDevlieghere added reviewers: jingham, jasonmolenda, labath.

Several SBAddress properties use the `lldb.target` or `lldb.process` convenience variables which are only set under the interactive script interpreter. Unfortunately, users have been using these properties in Python script and commands. This patch raises a Python exception to force users to use `GetLoadAddress` instead.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D80848

Files:
  lldb/bindings/interface/SBAddress.i


Index: lldb/bindings/interface/SBAddress.i
===================================================================
--- lldb/bindings/interface/SBAddress.i
+++ lldb/bindings/interface/SBAddress.i
@@ -144,27 +144,34 @@
 
 #ifdef SWIGPYTHON
     %pythoncode %{
+        __runtime_error_str = 'This resolves 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) and not in Python based commands, or breakpoint commands.'
+
         def __get_load_addr_property__ (self):
-            '''Get the load address for a lldb.SBAddress using the current target.'''
+            '''Get the load address for a lldb.SBAddress using the current target. This resolves 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) and not in Python based commands, or breakpoint commands.'''
+            if not target:
+                raise RuntimeError(__runtime_error_str)
             return self.GetLoadAddress (target)
 
         def __set_load_addr_property__ (self, load_addr):
-            '''Set the load address for a lldb.SBAddress using the current target.'''
+            '''Set the load address for a lldb.SBAddress using the current target. This resolves 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) and not in Python based commands, or breakpoint commands.'''
+            if not target:
+                raise RuntimeError(__runtime_error_str)
             return self.SetLoadAddress (load_addr, target)
 
         def __int__(self):
-            '''Convert an address to a load address if there is a process and that process is alive, or to a file address otherwise.'''
-            if process and process.is_alive:
+            '''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 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) and not in Python based commands, or breakpoint commands.'''
+            if not process or not target:
+                raise RuntimeError(__runtime_error_str)
+            if process.is_alive:
                 return self.GetLoadAddress (target)
-            else:
-                return self.GetFileAddress ()
+            return self.GetFileAddress ()
 
         def __oct__(self):
-            '''Convert the address to an octal string'''
+            '''Convert the address to an octal string. This resolves 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) and not in Python based commands, or breakpoint commands.'''
             return '%o' % int(self)
 
         def __hex__(self):
-            '''Convert the address to an hex string'''
+            '''Convert the address to an hex string. This resolves 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) and not in Python based commands, or breakpoint commands.'''
             return '0x%x' % int(self)
 
         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.''')
@@ -176,7 +183,7 @@
         offset = property(GetOffset, None, doc='''A read only property that returns the section offset in bytes as an integer.''')
         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.''')
         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.''')
-        load_addr = property(__get_load_addr_property__, __set_load_addr_property__, doc='''A read/write property that gets/sets the SBAddress using load address. The setter resolves 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) and not in Python based commands, or breakpoint commands.''')
+        load_addr = property(__get_load_addr_property__, __set_load_addr_property__, doc='''A read/write property that gets/sets the SBAddress using load address. The resolves 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) and not in Python based commands, or breakpoint commands.''')
     %}
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80848.267382.patch
Type: text/x-patch
Size: 4972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200529/021a0a16/attachment-0001.bin>


More information about the lldb-commits mailing list