https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/148823
>From ba64d72e000bd14125b202a70bd7d34831e12cc0 Mon Sep 17 00:00:00 2001 From: David Spickett <david.spick...@linaro.org> Date: Tue, 15 Jul 2025 10:30:21 +0000 Subject: [PATCH] [lldb] Improve setting of program for filtering disassembly This changes the example command added in https://github.com/llvm/llvm-project/pull/145793 so that the fdis program does not have to be a single program name. Doing so also means we can run the test on Windows where the program needs to be "python.exe script_name". I've changed "fdis set" to treat the rest of the command as the program. Then store that as a list to be passed to subprocess. If we just use a string, Python will think that "python.exe foo" is the name of an actual program. This will still break if the paths have spaces in, but I'm trying to do just enough to fix the test here without rewriting all the option handling. --- lldb/examples/python/filter_disasm.py | 26 ++++++++++++++----- .../command-disassemble-riscv32-bytes.s | 5 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lldb/examples/python/filter_disasm.py b/lldb/examples/python/filter_disasm.py index de99d4031a7fd..46c9f794b25a2 100644 --- a/lldb/examples/python/filter_disasm.py +++ b/lldb/examples/python/filter_disasm.py @@ -11,8 +11,13 @@ import lldb import subprocess -filter_program = "crustfilt" +class Program(list): + def __str__(self): + return " ".join(self) + + +filter_program = Program(["crustfilt"]) def __lldb_init_module(debugger, dict): debugger.HandleCommand("command script add -f filter_disasm.fdis fdis") @@ -51,13 +56,20 @@ def fdis(debugger, args, exe_ctx, result, dict): result.Clear() if len(args_list) == 1 and args_list[0] == "get": - result.PutCString(filter_program) + result.PutCString(str(filter_program)) result.SetStatus(lldb.eReturnStatusSuccessFinishResult) return - if len(args_list) == 2 and args_list[0] == "set": - filter_program = args_list[1] - result.PutCString("Filter program set to %s" % filter_program) + if args_list[0] == "set": + # Assume the rest is a program to run and any arguments to be passed to + # it. + if len(args_list) <= 1: + result.PutCString('"set" command requires a program argument') + result.SetStatus(lldb.eReturnStatusFailed) + return + + filter_program = Program(args_list[1:]) + result.PutCString('Filter program set to "{}"'.format(filter_program)) result.SetStatus(lldb.eReturnStatusSuccessFinishResult) return @@ -70,7 +82,9 @@ def fdis(debugger, args, exe_ctx, result, dict): output = res.GetOutput() try: - proc = subprocess.run([filter_program], capture_output=True, text=True, input=output) + proc = subprocess.run( + filter_program, capture_output=True, text=True, input=output + ) except (subprocess.SubprocessError, OSError) as e: result.PutCString("Error occurred. Original disassembly:\n\n" + output) result.SetError(str(e)) diff --git a/lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s b/lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s index bd40baf2643a0..78be614e3af15 100644 --- a/lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s +++ b/lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s @@ -1,6 +1,5 @@ # REQUIRES: riscv -# Unsupported until we fix launching the filter program on Windows. -# UNSUPPORTED: system-windows +# REQUIRES: python # This test verifies that disassemble -b prints out the correct bytes and # format for standard and unknown riscv instructions of various sizes, @@ -11,7 +10,7 @@ # RUN: llvm-mc -filetype=obj -mattr=+c --triple=riscv32-unknown-unknown %s -o %t # RUN: %lldb -b %t "-o" "disassemble -b -n main" | FileCheck %s -# RUN: %lldb -b %t -o "command script import %S/../../../examples/python/filter_disasm.py" -o "fdis set %S/Inputs/dis_filt.py" -o "fdis -n main" | FileCheck --check-prefix=FILTER %s +# RUN: %lldb -b %t -o "command script import %S/../../../examples/python/filter_disasm.py" -o "fdis set %python %S/Inputs/dis_filt.py" -o "fdis -n main" | FileCheck --check-prefix=FILTER %s main: addi sp, sp, -0x20 # 16 bit standard instruction _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits