Skip to content

[lldb] Improve setting of program for filtering disassembly #148823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions lldb/examples/python/filter_disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
Loading