Skip to content

Commit ab98d8d

Browse files
committed
[lldb] Improve setting of program for filtering disassembly
This changes the example command added in #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.
1 parent 97d44e3 commit ab98d8d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lldb/examples/python/filter_disasm.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111
import lldb
1212
import subprocess
1313

14-
filter_program = "crustfilt"
1514

15+
class Program(list):
16+
def __str__(self):
17+
return " ".join(self)
18+
19+
20+
filter_program = Program(["crustfilt"])
1621

1722
def __lldb_init_module(debugger, dict):
1823
debugger.HandleCommand("command script add -f filter_disasm.fdis fdis")
@@ -51,13 +56,20 @@ def fdis(debugger, args, exe_ctx, result, dict):
5156
result.Clear()
5257

5358
if len(args_list) == 1 and args_list[0] == "get":
54-
result.PutCString(filter_program)
59+
result.PutCString(str(filter_program))
5560
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
5661
return
5762

58-
if len(args_list) == 2 and args_list[0] == "set":
59-
filter_program = args_list[1]
60-
result.PutCString("Filter program set to %s" % filter_program)
63+
if args_list[0] == "set":
64+
# Assume the rest is a program to run, which might be a path containing spaces
65+
# or an interpreter and a file path.
66+
if len(args_list) <= 1:
67+
result.PutCString('"set" command requires a program argument')
68+
result.SetStatus(lldb.eReturnStatusFailed)
69+
return
70+
71+
filter_program = Program(args_list[1:])
72+
result.PutCString('Filter program set to "{}"'.format(filter_program))
6173
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
6274
return
6375

@@ -70,7 +82,9 @@ def fdis(debugger, args, exe_ctx, result, dict):
7082
output = res.GetOutput()
7183

7284
try:
73-
proc = subprocess.run([filter_program], capture_output=True, text=True, input=output)
85+
proc = subprocess.run(
86+
filter_program, capture_output=True, text=True, input=output
87+
)
7488
except (subprocess.SubprocessError, OSError) as e:
7589
result.PutCString("Error occurred. Original disassembly:\n\n" + output)
7690
result.SetError(str(e))

lldb/test/Shell/Commands/command-disassemble-riscv32-bytes.s

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# REQUIRES: riscv
2-
# Unsupported until we fix launching the filter program on Windows.
3-
# UNSUPPORTED: system-windows
2+
# REQUIRES: python
43

54
# This test verifies that disassemble -b prints out the correct bytes and
65
# format for standard and unknown riscv instructions of various sizes,
@@ -11,7 +10,7 @@
1110

1211
# RUN: llvm-mc -filetype=obj -mattr=+c --triple=riscv32-unknown-unknown %s -o %t
1312
# RUN: %lldb -b %t "-o" "disassemble -b -n main" | FileCheck %s
14-
# 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
13+
# 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
1514

1615
main:
1716
addi sp, sp, -0x20 # 16 bit standard instruction

0 commit comments

Comments
 (0)