From e3930e77fc5b626a3c6b95f08ed25a3f8807c579 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Thu, 12 Jan 2023 15:30:24 -0800 Subject: [PATCH] [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 --- lldb/examples/darwin/heap_find/heap.py | 12 ++++++------ lldb/examples/python/bsd.py | 2 +- lldb/examples/python/cmdtemplate.py | 2 +- lldb/examples/python/delta.py | 2 +- lldb/examples/python/diagnose_nsstring.py | 2 +- lldb/examples/python/diagnose_unwind.py | 2 +- lldb/examples/python/disassembly_mode.py | 2 +- lldb/examples/python/gdb_disassemble.py | 2 +- lldb/examples/python/gdbremote.py | 4 ++-- lldb/examples/python/jump.py | 2 +- lldb/examples/python/lldb_module_utils.py | 4 ++-- lldb/examples/python/memory.py | 2 +- lldb/examples/python/sources.py | 2 +- lldb/examples/python/stacks.py | 2 +- lldb/examples/python/step_and_print.py | 2 +- lldb/examples/python/types.py | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lldb/examples/darwin/heap_find/heap.py b/lldb/examples/darwin/heap_find/heap.py index 2021b9e..38b549c 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 34716a3..6dc5f73 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 9ce930d..439452a 100644 --- a/lldb/examples/python/cmdtemplate.py +++ b/lldb/examples/python/cmdtemplate.py @@ -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) diff --git a/lldb/examples/python/delta.py b/lldb/examples/python/delta.py index 3e8ece2..3fcd090 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 1e91e86..7515815 100644 --- a/lldb/examples/python/diagnose_nsstring.py +++ b/lldb/examples/python/diagnose_nsstring.py @@ -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.') diff --git a/lldb/examples/python/diagnose_unwind.py b/lldb/examples/python/diagnose_unwind.py index 65de6f1..0b99427 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 19647cc..18a1527 100644 --- a/lldb/examples/python/disassembly_mode.py +++ b/lldb/examples/python/disassembly_mode.py @@ -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") diff --git a/lldb/examples/python/gdb_disassemble.py b/lldb/examples/python/gdb_disassemble.py index 08d1ef5..345277e 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 13ec30a..8d000c4 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 cfa8342..0dc6515 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 " for detailed help.') diff --git a/lldb/examples/python/lldb_module_utils.py b/lldb/examples/python/lldb_module_utils.py index c647be2..9a9b92b 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 17fce3f..ffa0bb4 100755 --- a/lldb/examples/python/memory.py +++ b/lldb/examples/python/memory.py @@ -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') diff --git a/lldb/examples/python/sources.py b/lldb/examples/python/sources.py index 427937a..4fbfea4 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 3b9a85a..6bcf254 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 41364ef9..62a612e 100644 --- a/lldb/examples/python/step_and_print.py +++ b/lldb/examples/python/step_and_print.py @@ -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") diff --git a/lldb/examples/python/types.py b/lldb/examples/python/types.py index e327877..6110d11 100755 --- a/lldb/examples/python/types.py +++ b/lldb/examples/python/types.py @@ -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') -- 2.7.4