[lldb] Update custom commands to always be overrriden
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Thu, 12 Jan 2023 23:30:24 +0000 (15:30 -0800)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Fri, 13 Jan 2023 03:20:51 +0000 (19:20 -0800)
This is a follow-up patch to 6f7835f309b9.

As explained previously, when running from an IDE, it can happen that
the IDE imports some lldb scripts by itself. If the user also tries to
import these commands, lldb will show the following message:

```
error: cannot add command: user command exists and force replace not set
```

This message is confusing to the user, because it suggests that the
command import failed and that the execution should stop. However, in
this case, lldb will continue the execution with the command added
previously by the user.

To prevent that, this patch updates every first-party lldb-packaged
custom commands to override commands that were pre-imported in lldb.

Differential Revision: https://reviews.llvm.org/D140293

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
16 files changed:
lldb/examples/darwin/heap_find/heap.py
lldb/examples/python/bsd.py
lldb/examples/python/cmdtemplate.py
lldb/examples/python/delta.py
lldb/examples/python/diagnose_nsstring.py
lldb/examples/python/diagnose_unwind.py
lldb/examples/python/disassembly_mode.py
lldb/examples/python/gdb_disassemble.py
lldb/examples/python/gdbremote.py
lldb/examples/python/jump.py
lldb/examples/python/lldb_module_utils.py
lldb/examples/python/memory.py
lldb/examples/python/sources.py
lldb/examples/python/stacks.py
lldb/examples/python/step_and_print.py
lldb/examples/python/types.py

index 2021b9e..38b549c 100644 (file)
@@ -1503,19 +1503,19 @@ def __lldb_init_module(debugger, internal_dict):
     malloc_info.__doc__ = get_malloc_info_options().format_help()
     objc_refs.__doc__ = get_objc_refs_options().format_help()
     debugger.HandleCommand(
-        'command script add -f %s.ptr_refs ptr_refs' %
+        'command script add -o -f %s.ptr_refs ptr_refs' %
         __name__)
     debugger.HandleCommand(
-        'command script add -f %s.cstr_refs cstr_refs' %
+        'command script add -o -f %s.cstr_refs cstr_refs' %
         __name__)
     debugger.HandleCommand(
-        'command script add -f %s.malloc_info malloc_info' %
+        'command script add -o -f %s.malloc_info malloc_info' %
         __name__)
     debugger.HandleCommand(
-        'command script add -f %s.find_variable find_variable' %
+        'command script add -o -f %s.find_variable find_variable' %
         __name__)
-    # debugger.HandleCommand('command script add -f %s.section_ptr_refs section_ptr_refs' % package_name)
+    # debugger.HandleCommand('command script add -o -f %s.section_ptr_refs section_ptr_refs' % package_name)
     debugger.HandleCommand(
-        'command script add -f %s.objc_refs objc_refs' %
+        'command script add -o -f %s.objc_refs objc_refs' %
         __name__)
     print('"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.')
index 34716a3..6dc5f73 100755 (executable)
@@ -558,7 +558,7 @@ def __lldb_init_module(debugger, dict):
     # interpreter.
     # Add any commands contained in this module to LLDB
     debugger.HandleCommand(
-        'command script add -c %s.VerifyDebugMapCommand %s' % (
+        'command script add -o -c %s.VerifyDebugMapCommand %s' % (
             __name__, VerifyDebugMapCommand.name))
     print('The "%s" command has been installed, type "help %s" for detailed '
           'help.' % (VerifyDebugMapCommand.name, VerifyDebugMapCommand.name))
index 9ce930d..439452a 100644 (file)
@@ -24,7 +24,7 @@ class FrameStatCommand:
         parser = cls.create_options()
         cls.__doc__ = parser.format_help()
         # Add any commands contained in this module to LLDB
-        command = 'command script add -c %s.%s %s' % (module_name,
+        command = 'command script add -o -c %s.%s %s' % (module_name,
                                                       cls.__name__,
                                                       cls.program)
         debugger.HandleCommand(command)
index 3e8ece2..3fcd090 100755 (executable)
@@ -128,5 +128,5 @@ def __lldb_init_module(debugger, internal_dict):
         # This initializer is being run from LLDB in the embedded command interpreter
         # Add any commands contained in this module to LLDB
         debugger.HandleCommand(
-            'command script add -f delta.parse_time_log parse_time_log')
+            'command script add -o -f delta.parse_time_log parse_time_log')
         print('The "parse_time_log" command is now installed and ready for use, type "parse_time_log --help" for more information')
index 1e91e86..7515815 100644 (file)
@@ -175,7 +175,7 @@ struct $__lldb__CFString {\
 
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand(
-        "command script add -f %s.diagnose_nsstring_Command_Impl diagnose-nsstring" %
+        "command script add -o -f %s.diagnose_nsstring_Command_Impl diagnose-nsstring" %
         __name__)
     print('The "diagnose-nsstring" command has been installed, type "help diagnose-nsstring" for detailed help.')
 
index 65de6f1..0b99427 100644 (file)
@@ -309,6 +309,6 @@ def create_diagnose_unwind_options():
 
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand(
-        'command script add -f %s.diagnose_unwind diagnose-unwind' %
+        'command script add -o -f %s.diagnose_unwind diagnose-unwind' %
         __name__)
     print('The "diagnose-unwind" command has been installed, type "help diagnose-unwind" for detailed help.')
index 19647cc..18a1527 100644 (file)
@@ -45,4 +45,4 @@ class DisassemblyMode:
         return "Toggles between a disassembly only mode and normal source mode\n"
 
 def __lldb_init_module(debugger, unused):
-    debugger.HandleCommand("command script add -c disassembly_mode.DisassemblyMode toggle-disassembly")
+    debugger.HandleCommand("command script add -o -c disassembly_mode.DisassemblyMode toggle-disassembly")
index 08d1ef5..345277e 100755 (executable)
@@ -23,5 +23,5 @@ def disassemble(debugger, command, result, dict):
 # Install the command when the module gets imported
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand(
-        'command script add -f gdb_disassemble.disassemble gdb-disassemble')
+        'command script add -o -f gdb_disassemble.disassemble gdb-disassemble')
     print('Installed "gdb-disassemble" command for disassembly')
index 13ec30a..8d000c4 100755 (executable)
@@ -1626,7 +1626,7 @@ def __lldb_init_module(debugger, internal_dict):
     # This initializer is being run from LLDB in the embedded command interpreter
     # Add any commands contained in this module to LLDB
     debugger.HandleCommand(
-        'command script add -f gdbremote.start_gdb_log start_gdb_log')
+        'command script add -o -f gdbremote.start_gdb_log start_gdb_log')
     debugger.HandleCommand(
-        'command script add -f gdbremote.stop_gdb_log stop_gdb_log')
+        'command script add -o -f gdbremote.stop_gdb_log stop_gdb_log')
     print('The "start_gdb_log" and "stop_gdb_log" commands are now installed and ready for use, type "start_gdb_log --help" or "stop_gdb_log --help" for more information')
index cfa8342..0dc6515 100644 (file)
@@ -192,5 +192,5 @@ def jump(debugger, command, result, internal_dict):
 def __lldb_init_module(debugger, internal_dict):
     # Module is being run inside the LLDB interpreter
     jump.__doc__ = usage_string()
-    debugger.HandleCommand('command script add -f jump.jump jump')
+    debugger.HandleCommand('command script add -o -f jump.jump jump')
     print('The "jump" command has been installed, type "help jump" or "jump <ENTER>" for detailed help.')
index c647be2..9a9b92b 100644 (file)
@@ -183,9 +183,9 @@ def __lldb_init_module(debugger, dict):
 
     # Add any commands contained in this module to LLDB
     debugger.HandleCommand(
-        'command script add -c %s.DumpLineTables %s' % (__name__,
+        'command script add -o -c %s.DumpLineTables %s' % (__name__,
                                                         DumpLineTables.command_name))
     debugger.HandleCommand(
-        'command script add -c %s.DumpFiles %s' % (__name__, DumpFiles.command_name))
+        'command script add -o -c %s.DumpFiles %s' % (__name__, DumpFiles.command_name))
     print('The "%s" and "%s" commands have been installed.' % (DumpLineTables.command_name,
                                                                DumpFiles.command_name))
index 17fce3f..ffa0bb4 100755 (executable)
@@ -272,5 +272,5 @@ if __name__ == '__main__':
 def __lldb_init_module(debugger, internal_dict):
     memfind_command.__doc__ = create_memfind_options().format_help()
     debugger.HandleCommand(
-        'command script add -f memory.memfind_command memfind')
+        'command script add -o -f memory.memfind_command memfind')
     print('"memfind" command installed, use the "--help" option for detailed help')
index 427937a..4fbfea4 100644 (file)
@@ -27,5 +27,5 @@ def info_sources(debugger, command, result, dict):
 def __lldb_init_module(debugger, dict):
     # Add any commands contained in this module to LLDB
     debugger.HandleCommand(
-        'command script add -f sources.info_sources info_sources')
+        'command script add -o -f sources.info_sources info_sources')
     print('The "info_sources" command has been installed, type "help info_sources" or "info_sources --help" for detailed help.')
index 3b9a85a..6bcf254 100755 (executable)
@@ -64,5 +64,5 @@ def stack_frames(debugger, command, result, dict):
 
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand(
-        "command script add -f stacks.stack_frames stack_frames")
+        "command script add -o -f stacks.stack_frames stack_frames")
     print("A new command called 'stack_frames' was added, type 'stack_frames --help' for more information.")
index 41364ef..62a612e 100644 (file)
@@ -21,4 +21,4 @@ class StepAndPrint:
         return "Does a step-over then runs frame variable passing the command args to it\n"
 
 def __lldb_init_module(debugger, unused):
-    debugger.HandleCommand("command script add -c step_and_print.StepAndPrint sap")
+    debugger.HandleCommand("command script add -o -c step_and_print.StepAndPrint sap")
index e327877..6110d11 100755 (executable)
@@ -351,5 +351,5 @@ if __name__ == '__main__':
 
 def __lldb_init_module(debugger, internal_dict):
     debugger.HandleCommand(
-        'command script add -f types.check_padding_command check_padding')
+        'command script add -o -f types.check_padding_command check_padding')
     print('"check_padding" command installed, use the "--help" option for detailed help')