[Lldb-commits] [lldb] e3930e7 - [lldb] Update custom commands to always be overrriden

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 12 19:21:18 PST 2023


Author: Med Ismail Bennani
Date: 2023-01-12T19:20:51-08:00
New Revision: e3930e77fc5b626a3c6b95f08ed25a3f8807c579

URL: https://github.com/llvm/llvm-project/commit/e3930e77fc5b626a3c6b95f08ed25a3f8807c579
DIFF: https://github.com/llvm/llvm-project/commit/e3930e77fc5b626a3c6b95f08ed25a3f8807c579.diff

LOG: [lldb] Update custom commands to always be overrriden

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 at gmail.com>

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/examples/darwin/heap_find/heap.py b/lldb/examples/darwin/heap_find/heap.py
index 2021b9ebc8e2..38b549ca330b 100644
--- a/lldb/examples/darwin/heap_find/heap.py
+++ b/lldb/examples/darwin/heap_find/heap.py
@@ -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.')

diff  --git a/lldb/examples/python/bsd.py b/lldb/examples/python/bsd.py
index 34716a3d9003..6dc5f735dc98 100755
--- a/lldb/examples/python/bsd.py
+++ b/lldb/examples/python/bsd.py
@@ -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))

diff  --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py
index 9ce930d4ef76..439452a86cad 100644
--- a/lldb/examples/python/cmdtemplate.py
+++ b/lldb/examples/python/cmdtemplate.py
@@ -24,7 +24,7 @@ def register_lldb_command(cls, debugger, module_name):
         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)

diff  --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py
index 3e8ece214131..3fcd090bae63 100755
--- a/lldb/examples/python/delta.py
+++ b/lldb/examples/python/delta.py
@@ -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')

diff  --git a/lldb/examples/python/diagnose_nsstring.py b/lldb/examples/python/diagnose_nsstring.py
index 1e91e860894f..75158153e3be 100644
--- a/lldb/examples/python/diagnose_nsstring.py
+++ b/lldb/examples/python/diagnose_nsstring.py
@@ -175,7 +175,7 @@ def diagnose_nsstring_Command_Impl(debugger, command, result, internal_dict):
 
 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.')
 

diff  --git a/lldb/examples/python/diagnose_unwind.py b/lldb/examples/python/diagnose_unwind.py
index 65de6f1625c2..0b9942770730 100644
--- a/lldb/examples/python/diagnose_unwind.py
+++ b/lldb/examples/python/diagnose_unwind.py
@@ -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.')

diff  --git a/lldb/examples/python/disassembly_mode.py b/lldb/examples/python/disassembly_mode.py
index 19647cc6555e..18a1527dbd2a 100644
--- a/lldb/examples/python/disassembly_mode.py
+++ b/lldb/examples/python/disassembly_mode.py
@@ -45,4 +45,4 @@ def get_short_help(self):
         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")

diff  --git a/lldb/examples/python/gdb_disassemble.py b/lldb/examples/python/gdb_disassemble.py
index 08d1ef561107..345277e85f18 100755
--- a/lldb/examples/python/gdb_disassemble.py
+++ b/lldb/examples/python/gdb_disassemble.py
@@ -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')

diff  --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index 13ec30abbe18..8d000c4792b4 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -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')

diff  --git a/lldb/examples/python/jump.py b/lldb/examples/python/jump.py
index cfa8342d0690..0dc651538109 100644
--- a/lldb/examples/python/jump.py
+++ b/lldb/examples/python/jump.py
@@ -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.')

diff  --git a/lldb/examples/python/lldb_module_utils.py b/lldb/examples/python/lldb_module_utils.py
index c647be25728a..9a9b92b60659 100644
--- a/lldb/examples/python/lldb_module_utils.py
+++ b/lldb/examples/python/lldb_module_utils.py
@@ -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))

diff  --git a/lldb/examples/python/memory.py b/lldb/examples/python/memory.py
index 17fce3fb0d9e..ffa0bb410dbd 100755
--- a/lldb/examples/python/memory.py
+++ b/lldb/examples/python/memory.py
@@ -272,5 +272,5 @@ def memfind(target, options, args, result):
 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')

diff  --git a/lldb/examples/python/sources.py b/lldb/examples/python/sources.py
index 427937abd13a..4fbfea48e156 100644
--- a/lldb/examples/python/sources.py
+++ b/lldb/examples/python/sources.py
@@ -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.')

diff  --git a/lldb/examples/python/stacks.py b/lldb/examples/python/stacks.py
index 3b9a85a2bd95..6bcf2547c3e6 100755
--- a/lldb/examples/python/stacks.py
+++ b/lldb/examples/python/stacks.py
@@ -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.")

diff  --git a/lldb/examples/python/step_and_print.py b/lldb/examples/python/step_and_print.py
index 41364ef97ba8..62a612eac186 100644
--- a/lldb/examples/python/step_and_print.py
+++ b/lldb/examples/python/step_and_print.py
@@ -21,4 +21,4 @@ def get_short_help(self):
         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")

diff  --git a/lldb/examples/python/types.py b/lldb/examples/python/types.py
index e32787731e63..6110d1107138 100755
--- a/lldb/examples/python/types.py
+++ b/lldb/examples/python/types.py
@@ -351,5 +351,5 @@ def verify_types(target, options):
 
 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')


        


More information about the lldb-commits mailing list