-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb] Support disassembling RISC-V proprietary instructions #145793
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a7ee42
Support disassembling RISC-V proprietary insns
eee2048
[lldb] Improve disassembly of unknown instructions
2fe2115
[lldb] Improve disassembly of unknown instructions
1ec2424
[lldb] Improve disassembly of unknown instructions
2966de6
[lldb] Improve disassembly of unknown instructions
afedb0f
[lldb] Improve disassembly of unknown instructions
9cf0fa3
[lldb] Improve disassembly of unknown instructions
63f417c
[lldb] Improve disassembly of unknown instructions
c58c4da
[lldb] Improve disassembly of unknown instructions
1a4c94a
[lldb] Improve disassembly of unknown instructions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| Defines a command, fdis, that does filtered disassembly. The command does the | ||
| lldb disassemble command with -b and any other arguments passed in, and | ||
| pipes that through a provided filter program. | ||
|
|
||
| The intention is to support disassembly of RISC-V proprietary instructions. | ||
| This is handled with llvm-objdump by piping the output of llvm-objdump through | ||
| a filter program. This script is intended to mimic that workflow. | ||
| """ | ||
|
|
||
| import lldb | ||
| import subprocess | ||
|
|
||
| filter_program = "crustfilt" | ||
|
|
||
|
|
||
| def __lldb_init_module(debugger, dict): | ||
| debugger.HandleCommand("command script add -f filter_disasm.fdis fdis") | ||
| print("Disassembly filter command (fdis) loaded") | ||
| print("Filter program set to %s" % filter_program) | ||
|
|
||
|
|
||
| def fdis(debugger, args, exe_ctx, result, dict): | ||
| """ | ||
| Call the built in disassembler, then pass its output to a filter program | ||
| to add in disassembly for hidden opcodes. | ||
| Except for get and set, use the fdis command like the disassemble command. | ||
| By default, the filter program is crustfilt, from | ||
| https://github.com/quic/crustfilt . This can be changed by changing | ||
| the global variable filter_program. | ||
|
|
||
| Usage: | ||
| fdis [[get] [set <program>] [<disassembly options>]] | ||
|
|
||
| Choose one of the following: | ||
| get | ||
| Gets the current filter program | ||
|
|
||
| set <program> | ||
| Sets the current filter program. This can be an executable, which | ||
| will be found on PATH, or an absolute path. | ||
|
|
||
| <disassembly options> | ||
| If the first argument is not get or set, the args will be passed | ||
| to the disassemble command as is. | ||
|
|
||
| """ | ||
|
|
||
| global filter_program | ||
| args_list = args.split(" ") | ||
| result.Clear() | ||
|
|
||
| if len(args_list) == 1 and args_list[0] == "get": | ||
| result.PutCString(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) | ||
| result.SetStatus(lldb.eReturnStatusSuccessFinishResult) | ||
| return | ||
|
|
||
| res = lldb.SBCommandReturnObject() | ||
| debugger.GetCommandInterpreter().HandleCommand("disassemble -b " + args, exe_ctx, res) | ||
| if len(res.GetError()) > 0: | ||
| result.SetError(res.GetError()) | ||
| result.SetStatus(lldb.eReturnStatusFailed) | ||
| return | ||
| output = res.GetOutput() | ||
|
|
||
| try: | ||
| 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)) | ||
| result.SetStatus(lldb.eReturnStatusFailed) | ||
| return | ||
|
|
||
| if proc.returncode: | ||
| result.PutCString("warning: {} returned non-zero value {}".format(filter_program, proc.returncode)) | ||
|
|
||
| result.PutCString(proc.stdout) | ||
| result.SetStatus(lldb.eReturnStatusSuccessFinishResult) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #! /usr/bin/env python3 | ||
|
|
||
| import sys | ||
|
|
||
| for line in sys.stdin: | ||
| if "0940003f 00200020" in line and "<unknown>" in line: | ||
| line = line.replace("<unknown>", "Fake64") | ||
| print(line, end="") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.