aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-08[lldb][NFC] clang-format DisassemblerLLVMC.cppDavid Spickett1-4/+3
Noticed these bits in a PR I'm reviewing. Might as well fix them now.
2025-09-08MC: Add Triple overloads for more MC constructors (#157321)Matt Arsenault1-1/+4
Avoids more Triple->string->Triple round trip. This is a continuation of f137c3d592e96330e450a8fd63ef7e8877fc1908
2025-07-15[lldb] Fix Disasembler build error on 32-bit systemsDavid Spickett1-7/+5
After changes in https://github.com/llvm/llvm-project/pull/145793. /home/david.spickett/llvm-project/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp:1360:49: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned int') 1360 | status = m_disasm_up->getInstruction(mc_inst, size, data, pc, llvm::nulls()); | ^~~~ /home/david.spickett/llvm-project/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h:135:64: note: passing argument to parameter 'Size' here 135 | virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, | ^ 1 error generated. The type used in the LLVM method we call is uin64_t so use that instead. It's overkill for what it is, but that's a separate issue if anyone cares. Also removed the unused form of GetMCInst.
2025-07-14[lldb] Improve disassembly of unknown instructions (#145793)tedwoodward1-23/+35
LLDB uses the LLVM disassembler to determine the size of instructions and to do the actual disassembly. Currently, if the LLVM disassembler can't disassemble an instruction, LLDB will ignore the instruction size, assume the instruction size is the minimum size for that device, print no useful opcode, and print nothing for the instruction. This patch changes this behavior to separate the instruction size and "can't disassemble". If the LLVM disassembler knows the size, but can't dissasemble the instruction, LLDB will use that size. It will print out the opcode, and will print "<unknown>" for the instruction. This is much more useful to both a user and a script. The impetus behind this change is to clean up RISC-V disassembly when the LLVM disassembler doesn't understand all of the instructions. RISC-V supports proprietary extensions, where the TD files don't know about certain instructions, and the disassembler can't disassemble them. Internal users want to be able to disassemble these instructions. With llvm-objdump, the solution is to pipe the output of the disassembly through a filter program. This patch modifies LLDB's disassembly to look more like llvm-objdump's, and includes an example python script that adds a command "fdis" that will disassemble, then pipe the output through a specified filter program. This has been tested with crustfilt, a sample filter located at https://github.com/quic/crustfilt . Changes in this PR: - Decouple "can't disassemble" with "instruction size". DisassemblerLLVMC::MCDisasmInstance::GetMCInst now returns a bool for valid disassembly, and has the size as an out paramter. Use the size even if the disassembly is invalid. Disassemble if disassemby is valid. - Always print out the opcode when -b is specified. Previously it wouldn't print out the opcode if it couldn't disassemble. - Print out RISC-V opcodes the way llvm-objdump does. Code for the new Opcode Type eType16_32Tuples by Jason Molenda. - Print <unknown> for instructions that can't be disassembled, matching llvm-objdump, instead of printing nothing. - Update max riscv32 and riscv64 instruction size to 8. - Add example "fdis" command script. - Added disassembly byte test for x86 with known and unknown instructions. - Added disassembly byte test for riscv32 with known and unknown instructions, with and without filtering. - Added test from Jason Molenda to RISC-V disassembly unit tests.
2025-07-11[LLDB][NVIDIA] Add Disassembler log channel (#148290)Andrew Gontarek1-1/+1
This commit introduces a new log channel for the disassembler in LLDB, allowing for better logging of disassembler related activities. The `LLDBLOG` enum has been updated to include the `Disassembler` channel, and the relevant logging in the `DisassemblerLLVMC` plugin has been modified to utilize this new channel. This is in preparation for adding additional disassembler implementations. Key Changes: - Added `Disassembler` to the `LLDBLog` enum. - Updated logging in `DisassemblerLLVMC.cpp` to use the new `Disassembler` log channel.
2025-05-10[lldb] Simplify string comparisons (NFC) (#139394)Kazu Hirata1-1/+1
2025-02-13[lldb] Correctly resolve (discontinuous) function offsets when disassembling ↵Pavel Labath1-4/+8
(#126925) We need to iterate through the all symbol context ranges returned by (since #126505) SymbolContext::GetAddressRange. This also includes a fix to print the function offsets as signed values. I've also wanted to check that the addresses which are in the middle of the function do *not* resolve to the function, but that's not entirely the case right now. This appears to be a separate issue though, so I've just left a TODO for now.
2025-01-14[lldb][NFC] Make the target's SectionLoadList private. (#113278)Greg Clayton1-3/+3
Lots of code around LLDB was directly accessing the target's section load list. This NFC patch makes the section load list private so the Target class can access it, but everyone else now uses accessor functions. This allows us to control the resolving of addresses and will allow for functionality in LLDB which can lazily resolve addresses in JIT plug-ins with a future patch.
2024-11-11[lldb] Support overriding the disassembly CPU & features (#115382)Jonas Devlieghere1-55/+65
Add the ability to override the disassembly CPU and CPU features through a target setting (`target.disassembly-cpu` and `target.disassembly-features`) and a `disassemble` command option (`--cpu` and `--features`). This is especially relevant for architectures like RISC-V which relies heavily on CPU extensions. The majority of this patch is plumbing the options through. I recommend looking at DisassemblerLLVMC and the test for the observable change in behavior.
2024-11-11[lldb] Have disassembler show load addresses when using a core file (#115453)Pavel Labath1-7/+4
We got a bug report that the disassember output was not relocated (i.e. a load address) for a core file (like it is for a live process). It turns out this behavior it depends on whether the instructions were read from an executable file or from process memory (a core file will not typically contain the memory image for segments backed by an executable file). It's unclear whether this behavior is intentional, or if it was just trying to handle the case where we're dissassembling a module without a process, but I think it's undesirable. What makes it particularly confusing is that the instruction addresses are relocated in this case (unlike the when we don't have a process), so with large files and adresses it gets very hard to see whether the relocation has been applied or not. This patch removes the data_from_file check so that the instruction is relocated regardless of where it was read from. It will still not get relocated for the raw module use case, as those can't be relocated anywhere as they don't have a load address.
2024-09-16[lldb] Nits on uses of llvm::raw_string_ostream (NFC) (#108745)Youngsuk Kim1-2/+0
As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b13610a5226b84889b923bae884ba395ad084d for further reference ) * Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2023-09-29[RISC-V] Add RISC-V ABI pluginTed Woodward1-0/+2
Also default to disassembling a and m features Some code taken from https://reviews.llvm.org/D62732 , which hasn't been updated in a year. Tested with 32 and 64 bit Linux user space QEMU Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D159101
2023-09-01[lldb] Add syntax color highlighting for disassemblyJonas Devlieghere1-0/+26
Add support for syntax color highlighting disassembly in LLDB. This patch relies on 77d1032516e7, which introduces support for syntax highlighting in MC. Currently only AArch64 and X86 have color support, but other interested backends can adopt WithColor in their respective MCInstPrinter. Differential revision: https://reviews.llvm.org/D159164
2023-08-22Add support for llvm::MCInstPrinter::setPrintBranchImmAsAddressTed Woodward1-5/+7
llvm::MCInstPrinter has an option, controlled by setPrintBranchImmAsAddress, to print branch targets as immediate addresses instead of offsets. Turn this on in lldb, so targets that support this flag will print addresses instead of offsets. This requires the address of the instruction be provided, but fortunately it's calculated right before the call to PrintMCInst. Reviewed By: jasonmolenda, DavidSpickett Differential Revision: https://reviews.llvm.org/D155107
2023-08-14[lldb][NFC] Use MCInstrAnalysis when available in the disassembler pluginVenkata Ramanaiah Nalamothu1-8/+21
Since the info in MCInstrDesc is based on opcodes only, it is often quite inaccurate. The MCInstrAnalysis has been added so that targets can provide accurate info, which is based on registers used by the instruction, through the own versions of MCInstrDesc functions. The RISCVMCInstrAnalysis, which needs to refine several MCInstrDesc methods, is a good example for this. Given the llvm-objdump also uses MCInstrAnalysis, I think this change is in the right direction. The default implementation of MCInstrAnalysis methods forward the query to MCInstrDesc functions. Hence, no functional change is intended/expected. To avoid bloating up MCInstrAnalysis, only the methods provided by it and the ones used by disassembler plugin are changed to use MCInstrAnalysis when available. Though I am not sure if it will be useful, making MCInstrAnalysis available in the disassembler plugin would allow enabling symbolize operands (D84191) feature in lldb's disassembler as well. Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D156086
2023-05-15[lldb] Change definition of DisassemblerCreateInstanceAlex Langford1-8/+6
DissassemblerCreateInstance is a function pointer whos return type is `Disassembler *`. But Disassembler::FindPlugin always returns a DisassemblerSP, so there's no reason why we can't just create a DisassemblerSP in the first place. Differential Revision: https://reviews.llvm.org/D150235
2023-02-03[NFC][TargetParser] Remove llvm/Support/AArch64TargetParser.hArchibald Elliott1-1/+1
Removes the forwarding header `llvm/Support/AArch64TargetParser.h`. I am proposing to do this for all the forwarding headers left after rGf09cf34d00625e57dea5317a3ac0412c07292148 - for each header: - Update all relevant in-tree includes - Remove the forwarding Header Differential Revision: https://reviews.llvm.org/D140999
2023-01-23[LLDB] Fix build error after D142214Jay Foad1-1/+1
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-2/+2
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-17[lldb] llvm::Optional::value => operator*/operator->Fangrui Song1-4/+4
std::optional::value() has undesired exception checking semantics and is unavailable in some older Xcode. The call sites block std::optional migration.
2022-12-04[lldb] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-1/+1
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04[lldb] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-20Remove redundant initialization of Optional (NFC)Kazu Hirata1-1/+1
2022-07-26Move GetControlFlowKind's logic to DisassemblerLLVMC.cppWalter Erquinigo1-0/+331
This diff move the logic of `GetControlFlowKind()` from Disassembler.cpp to DisassemblerLLVMC.cpp. Here's details: - Actual logic of GetControlFlowKind() move to `DisassemblerLLVMC.cpp`, and we can check underlying architecture using `DisassemblerScope` there. - With this change, passing 'triple' to `GetControlFlowKind()` is no more required. Reviewed By: wallace Differential Revision: https://reviews.llvm.org/D130320
2022-07-15Use value instead of getValue (NFC)Kazu Hirata1-3/+3
2022-07-06[lldb][AArch64] Use "+all" feature for the disassemblerDavid Spickett1-5/+1
The "+all" feature name was added in https://reviews.llvm.org/D128029. This feature means we don't have to generate a list of features or use a base architecture feature. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D129177
2022-06-26[lld] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
This patch replaces x.hasValue() with x where x is contextually convertible to bool.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-4/+4
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-4/+4
2022-04-12[lldb][AArch64] Automatically add all extensions to disassemblerDavid Spickett1-5/+8
This means we don't have to remember to update this code as much. This is all tested in lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s which I added previously. We don't have a way to get the latest base architecture yet so that remains manual. Having all the extensions specified will probably be equivalent to the latest architecture version in any case. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D123582
2022-04-04[lldb][AArch64] Update disassembler feature list and add tests for all ↵David Spickett1-1/+3
extensions This updates the disassembler to enable every optional extension. Previously we had added things that we added "support" for in lldb. (where support means significant work like new registers, fault types, etc.) Something like TME (transactional memory) wasn't added because there are no new lldb features for it. However we should still be disassembling the instructions. So I went through the AArch64 extensions and added all the missing ones. The new test won't prevent us missing a new extension but it does at least document our current settings. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D121999
2022-03-14[LLDB] Applying clang-tidy modernize-use-default-member-init over LLDBShafik Yaghmour1-3/+2
Applied modernize-use-default-member-init clang-tidy check over LLDB. It appears in many files we had already switched to in class member init but never updated the constructors to reflect that. This check is already present in the lldb/.clang-tidy config. Differential Revision: https://reviews.llvm.org/D121481
2022-03-10lldb/ObjectFile,Disassembler: read some state from the executableSaleem Abdulrasool1-0/+18
Add support to inspect the ELF headers for RISCV targets to determine if RVC or RVE are enabled and the floating point support to enable. As per the RISCV specification, d implies f, q implies d implies f, which gives us the cascading effect that is used to enable the features when setting up the disassembler. With this change, it is now possible to attach the debugger to a remote process and be able to disassemble the instruction stream. ~~~ $ bin/lldb tmp/reduced (lldb) target create "reduced" Current executable set to '/tmp/reduced' (riscv64). (lldb) gdb-remote localhost:1234 (lldb) Process 5737 stopped * thread #1, name = 'reduced', stop reason = signal SIGTRAP frame #0: 0x0000003ff7fe1b20 -> 0x3ff7fe1b20: mv a0, sp 0x3ff7fe1b22: jal 1936 0x3ff7fe1b26: mv s0, a0 0x3ff7fe1b28: auipc a0, 27 ~~~
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath1-0/+1
Most of our code was including Log.h even though that is not where the "lldb" log channel is defined (Log.h defines the generic logging infrastructure). This worked because Log.h included Logging.h, even though it should. After the recent refactor, it became impossible the two files include each other in this direction (the opposite inclusion is needed), so this patch removes the workaround that was put in place and cleans up all files to include the right thing. It also renames the file to LLDBLog to better reflect its purpose.
2022-02-02[lldb] Convert "LLDB" log channel to the new APIPavel Labath1-2/+1
2022-01-28[lldb][ARM/AArch64] Update dissembler to v9.3-aDavid Spickett1-8/+8
This means sve2 is enabled by default and the v8.8 mops (memcpy and memset acceleration instructions) and HBC (hinted conditional branch) extensions can be disassembled. v9.3-a is equivalent to v8.8-a except that in v9.0-a sve2 was enabled by default so v9.3-a includes that too. MTE remains an optional extension, only enabled for specific CPUs. Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D118358
2021-12-26Remove redundant string initialization (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-string-init.
2021-10-22[lldb] Remove ConstString from ABI, Architecture and Disassembler plugin namesPavel Labath1-5/+0
2021-10-18[lldb] Return StringRef from PluginInterface::GetPluginNamePavel Labath1-3/+0
There is no reason why this function should be returning a ConstString. While modifying these files, I also fixed several instances where GetPluginName and GetPluginNameStatic were returning different strings. I am not changing the return type of GetPluginNameStatic in this patch, as that would necessitate additional changes, and this patch is big enough as it is. Differential Revision: https://reviews.llvm.org/D111877
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-1/+1
This moves the registry higher in the LLVM library dependency stack. Every client of the target registry needs to link against MC anyway to actually use the target, so we might as well move this out of Support. This allows us to ensure that Support doesn't have includes from MC/*. Differential Revision: https://reviews.llvm.org/D111454
2021-09-14[StopInfoMachException] Summarize arm64e BLRAx/LDRAx auth failuresVedant Kumar1-0/+39
Upstream lldb support for summarizing BLRAx and LDRAx auth failures. rdar://41615322 Differential Revision: https://reviews.llvm.org/D102428
2021-09-13[lldb] Remove PluginInterface::GetPluginVersionPavel Labath1-2/+0
In all these years, we haven't found a use for this function (it has zero callers). Lets just remove the boilerplate. Differential Revision: https://reviews.llvm.org/D109600
2021-08-12Symbolicate aarch64 adrp+add pc-relative addr in disassJason Molenda1-1/+48
On aarch64 a two instruction sequence is used to calculate a pc-relative address, add some state to the DisassemblerLLVMC symbolicator so it can track the necessary data across the two instructions and compute the address being calculated. Differential Revision: https://reviews.llvm.org/D107213 rdar://49119253
2021-05-23[MC] Refactor MCObjectFileInfo initialization and allow targets to create ↵Philipp Krones1-3/+3
MCObjectFileInfo This makes it possible for targets to define their own MCObjectFileInfo. This MCObjectFileInfo is then used to determine things like section alignment. This is a follow up to D101462 and prepares for the RISCV backend defining the text section alignment depending on the enabled extensions. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D101921
2021-05-05[MC] Untangle MCContext and MCObjectFileInfoPhilipp Krones1-2/+3
This untangles the MCContext and the MCObjectFileInfo. There is a circular dependency between MCContext and MCObjectFileInfo. Currently this dependency also exists during construction: You can't contruct a MOFI without a MCContext without constructing the MCContext with a dummy version of that MOFI first. This removes this dependency during construction. In a perfect world, MCObjectFileInfo wouldn't depend on MCContext at all, but only be stored in the MCContext, like other MC information. This is future work. This also shifts/adds more information to the MCContext making it more available to the different targets. Namely: - TargetTriple - ObjectFileType - SubtargetInfo Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D101462
2021-01-07[lldb][ARM/AArch64] Update disasm flags to latest v8.7a ISADavid Spickett1-11/+8
Add optional memory tagging extension on AArch64. Use isAArch64() instead of listing the AArch64 triples, which fixes us not recognising aarch64_be. Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D94084
2020-02-14[lldb/Plugin] s/LLDB_PLUGIN/LLDB_PLUGIN_DEFINE/ (NFC)Jonas Devlieghere1-1/+1
Rename LLDB_PLUGIN to LLDB_PLUGIN_DEFINE as Pavel suggested in D73067 to avoid name conflict.
2020-02-11[lldb][NFC] Remove several inefficient ConstString -> const char * -> ↵Raphael Isemann1-1/+1
StringRef conversions StringRef will call strlen on the C string which is inefficient (as ConstString already knows the string lenght and so does StringRef). This patch replaces all those calls with GetStringRef() which doesn't recompute the length.
2020-02-10[LLDB] Fix GCC warnings about extra semicolons. NFC.Martin Storsjö1-1/+1