summaryrefslogtreecommitdiff
path: root/lldb/source/Expression/DWARFExpression.cpp
AgeCommit message (Collapse)Author
2025-06-27Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… ↵Sterling-Augustine
(#145959) (#146112) Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… (#145959) This reapplies cbf781f0bdf2f680abbe784faedeefd6f84c246e, with fixes for the shared-library build and the unconventional sanitizer-runtime build. Original Description: This is the culmination of a series of changes described in [1]. Although somewhat large by line count, it is almost entirely mechanical, creating a new library in DebugInfo/DWARF/LowLevel. This new library has very minimal dependencies, allowing it to be used from more places than the normal DebugInfo/DWARF library--in particular from MC. 1. https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-26Revert "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… ↵Sterling-Augustine
(#145959) …145081)" This reverts commit cbf781f0bdf2f680abbe784faedeefd6f84c246e. Breaks a couple of buildbots.
2025-06-26[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#145081)Sterling-Augustine
This is the culmination of a series of changes described in [1]. Although somewhat large by line count, it is almost entirely mechanical, creating a new library in DebugInfo/DWARF/LowLevel. This new library has very minimal dependencies, allowing it to be used from more places than the normal DebugInfo/DWARF library--in particular from MC. I am happy to put it in another location, or to structure it differently if that makes sense. Some have suggested in BinaryFormat, but it is not a great fit there. But if that makes more sense to the reviewers, I can do that. Another possibility would be to use pass-through headers to allow clients who don't care to depend only on DebugInfo/DWARF. This would be a much less invasive change, and perhaps easier for clients. But also a system that hides details. Either way, I'm open. 1. https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
2025-06-09[NFC] Separate high-level-dependent portions of DWARFExpression (revised) ↵Sterling-Augustine
(#143170) (Revised version of a previous, unreviewed, PR.) Move all expression verification into its only client: DWARFVerifier. Move all printing code (which was a mix of static and member functions) into a separate class. This is one in a series of refactoring PRs to separate dwarf functionality into lower-level pieces usable without object files and sections at build time. The code is already written this way via various "if (section == nullptr)" and similar conditionals. So the functionality itself is needed and exists, but only as a runtime feature. The goal of these refactors is to remove the build-time dependencies, which will allow the existing functionality to be used from lower-level parts of the compiler. Particularly from lib/MC/.... More information at: https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665
2025-06-06Fix forward for new DWARF DW_OP enum to address warning in lldbDavid Blaikie
2025-03-24[LLDB][NFC] Added the interface DWARFExpression::Delegate to break ↵Dmitry Vasilyev
dependencies and reduce lldb-server size (#131645) This patch addresses the issue #129543. After this patch DWARFExpression does not call DWARFUnit directly and does not depend on lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a lot of clang code. After this patch the size of lldb-server binary (Linux Aarch64) is reduced from 47MB to 17MB.
2025-01-23[lldb] Add missing operations to GetOpcodeDataSize (#120163)Jonas Devlieghere
The improved error reporting in #120162 revealed that we were missing opcodes in GetOpcodeDataSize. I changed the function to remove the default case and switch over the enum type which will cause the compiler to emit a warning if there are unhandled operations in the future. rdar://139705570
2024-12-17[lldb] Improve error reporting in GetLocation_DW_OP_addr (#120162)Jonas Devlieghere
Instead of simply raising an error flag, use an llvm::Expected to propagate a meaningful error to the caller, who can report it. rdar://139705570
2024-11-21Reapply "[lldb] Convert file address to load address when reading memory for ↵Ilia Kuklin
DW_OP_piece" (#117168) This commit fixes the test so that the breakpoint is triggered correctly after `array` usage on AArch64. Reapplies #116411 with a fix.
2024-11-19Revert "[lldb] Convert file address to load address when reading memory for ↵Ilia Kuklin
DW_OP_piece" (#116824) Reverts llvm/llvm-project#116411
2024-11-19[lldb] Convert file address to load address when reading memory for ↵Ilia Kuklin
DW_OP_piece (#116411) When parsing an optimized value and reading a piece from a file address, LLDB tries to read the data from memory using that address. This patch converts file address to load address before reading the memory. Fixes #111313 Fixes #97484
2024-10-17[APInt] Fix APInt constructions where value does not fit bitwidth (NFCI) ↵Nikita Popov
(#80309) This fixes all the places that hit the new assertion added in https://github.com/llvm/llvm-project/pull/106524 in tests. That is, cases where the value passed to the APInt constructor is not an N-bit signed/unsigned integer, where N is the bit width and signedness is determined by the isSigned flag. The fixes either set the correct value for isSigned, set the implicitTrunc flag, or perform more calculations inside APInt. Note that the assertion is currently still disabled by default, so this patch is mostly NFC.
2024-10-10[lldb] Return an llvm::Error from GetFrameBaseValue (#111882)Jonas Devlieghere
This fixes the following assertion: "Cannot create Expected<T> from Error success value." The problem was that GetFrameBaseValue return false without updating the Status argument. This patch eliminates the opportunity for mistakes by returning an llvm:Error.
2024-08-20[lldb][AIX] 1. Avoid namespace collision on other platforms (#104679)Dhruv Srivastava
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. #101657 The complete changes for porting are present in this draft PR: https://github.com/llvm/llvm-project/pull/102601 The changes on this PR are intended to avoid namespace collision for certain typedefs between lldb and other platforms: 1. tid_t --> lldb::tid_t 2. offset_t --> lldb::offset_t
2024-06-07[lldb] Encode operands and arity in Dwarf.def and use them in LLDB. (#94679)Jonas Devlieghere
This PR extends Dwarf.def to include the number of operands and the arity (the number of entries on the DWARF stack). - The arity is used in LLDB's DWARF expression evaluator. - The number of operands is unused, but is present in the table to avoid confusing the arity with the operands. Keeping the latter up to date should be straightforward as it maps directly to a table present in the DWARF standard.
2024-06-06[lldb] Refactor ResolveLoadAddress to return an llvm::Expected (NFC) (#94558)Jonas Devlieghere
2024-06-06[lldb] Refactor ReadRegisterValueAsScalar to return an llvm::Error (NFC) ↵Jonas Devlieghere
(#94556)
2024-06-05[lldb] Fix inconsistencies in DWARFExpression errors (#94554)Jonas Devlieghere
This patch make all errors start with a lowercase letter and removes trailing periods and newlines. This fixes inconsistencies between error messages and facilitate concatenating them.
2024-06-05[lldb] Return an llvm::Expected from DWARFExpression::Evaluate (NFCI) (#94420)Jonas Devlieghere
Change the signature of `DWARFExpression::Evaluate` and `DWARFExpressionList::Evaluate` to return an `llvm::Expected` instead of a boolean. This eliminates the `Status` output parameter and generally improves error handling.
2024-06-04[lldb] Support reading DW_OP_piece from file address (#94026)Jonas Devlieghere
We received a bug report where someone was trying to print a global variable without a process. This would succeed in a debug build but fail in a on optimized build. We traced the issue back to the location being described by a DW_OP_addr + DW_OP_piece. The issue is that the DWARF expression evaluator only support reading pieces from a load address. There's no reason it cannot do the same for a file address, and indeed, that solves the problem. I unsuccessfully tried to craft a test case to illustrate the original example, using a global struct and trying to trick the compiler into breaking it apart with SROA. Instead I wrote a unit test that uses a mock target to read memory from. rdar://127435923
2024-02-13Don't count all the frames just to skip the current inlined ones. (#80918)jimingham
The algorithm to find the DW_OP_entry_value requires you to find the nearest non-inlined frame. It did that by counting the number of stack frames so that it could use that as a loop stopper. That is unnecessary and inefficient. Unnecessary because GetFrameAtIndex will return a null frame when you step past the oldest frame, so you already have the "got to the end" signal without counting all the stack frames. And counting all the stack frames can be expensive.
2023-10-13[LLDB][NFC] Create a namespace for the DWARF plugin (#68150)Walter Erquinigo
As a followup of https://github.com/llvm/llvm-project/pull/67851, I'm defining a new namespace `lldb_plugin::dwarf` for the classes in this Plugins/SymbolFile/DWARF folder. This change is very NFC and helped me with exporting the necessary symbols for my out-of-tree language plugin. The only class that I didn't change is ClangDWARFASTParser, because that shouldn't be in the same namespace as the generic language-agnostic dwarf parser. It would be a good idea if other plugins follow the same namespace scheme.
2023-07-21[lldb] Consider OP_addrx in DWARFExpression::Update_DW_OP_addrFelipe de Azevedo Piovezan
This rewrites DW_OP_addrx inside DWARFExpression as an DW_OP_addr so that we can update addresses that are originally located in the debug_addr section. The full discussion behind this can be found in https://discourse.llvm.org/t/dwarfexpression-and-dw-op-addrx/71627/12, but a summary follows. When SymbolFileDWARF::ParseVariableDIE creates DWARFExpressions for variables whose location is an OP_addr, it knows how to remap addresses appropriately in the DebugMap case. It then calls DWARFExpression::Update_DW_OP_addr, which updates the value associated with OP_addr. However, when we have an OP_addrx, the update function does nothing. This makes sense, as the DWARFExpression does not have a mutable view of the debug_addr section. In non-DebugMap flows this is not an issue, as the debug_addr contains the correct addresses of variables. In DebugMap flows, this is problematic because the work done by RelinkOSOAddress is lost. By updating the OP to OP_addr, we can also update the address as required, We also explored the alternative of relinking the debug_addr section when we are initializing OSOs (InitOSO). However, this creates an inconsistent story for users of DWARFExpression::GetLocation_DW_OP_addr. This function returns an address without telling callers whether that address came from an OP_addr or an OP_addrx. If we preemptively relink OP_addrx results without doing the same for OP_addr results, then callers can’t know whether the address they got was an executable address or an object file address. In other words, they can’t know whether they need to call LinkOSOFileAddress on those results or not. This patch addresses the majority of test failures when enabling DWARF 5 for MachO (over 200 test failures). Differential Revision: https://reviews.llvm.org/D155198
2023-07-10[LLDB] Fix buffer overflow problem in DWARFExpression::EvaluateCaroline Tice
In two calls to ReadMemory in DWARFExpression.cpp, the buffer size passed to ReadMemory is not checked and can be bigger than the actual size of the buffer. This caused a buffer overflow bug, which we found through Address Sanitizer. This patch fixes the problem by checking the address size when it is first read out of the DWARF, and setting an error and returning immediatley if the size is invalid. This is the second attempt to fix this issue; I reverted the first one, as it was not quite correct. Differential Revision: https://reviews.llvm.org/D154907
2023-07-10Revert "[LLDB] Fix buffer overflow problem in DWARFExpression::Evaluate."Caroline Tice
This reverts commit ee476996bec7f170928505a4c5b7715183cfbada. That commit was not the right way to fix the issue (it could result in reading too many bytes). A better fix is in the works. Original review: https://reviews.llvm.org/D153840
2023-07-03[lldb][NFC] Simplify GetLocation_DW_OP_addr functionFelipe de Azevedo Piovezan
A very old commit (9422dd64f870dd33) changed the signature of this function in a number of ways. This patch aims to improve it: 1. Reword the documentation, which still mentions old parameters that no longer exist, and to elaborate upon the behavior of this function. 2. Remove the unnecessary parameter `op_addr_idx`. This parameter is odd in a couple of ways: we never use it with a value that is non-zero, and the matching `Update_DW_OP_addr` function doesn't use a similar parameter. We also document that this new behavior. If we ever decide to handle multiple "DW_OP_addr", we can introduce the complexity again. Differential Revision: https://reviews.llvm.org/D154265
2023-06-28[LLDB] Fix buffer overflow problem in DWARFExpression::Evaluate.Caroline Tice
In two calls to ReadMemory in DWARFExpression.cpp, the buffer size passed to ReadMemory is not actually the size of the buffer (I suspect a copy/paste error where the variable name was not properly updated). This caused a buffer overflow bug, which we found throuth Address Sanitizer. This patch fixes the problem by passing the correct buffer size to the calls to ReadMemory (and to the DataExtractor). Differential Revision: https://reviews.llvm.org/D153840
2023-05-05Reland "[lldb][DWARFExpression] Fix DW_OP_div to use signed division"LU Hongyi
This patch resolves an issue where a value is incorrectly displayed if it is represented by DW_OP_div. This issue is caused by lldb evaluating operands of DW_OP_div as unsigned and performed unintended unsigned division. This issue is resolved by creating two temporary signed scalar and performing signed division. (Addresses GH#61727) Differential Revision: https://reviews.llvm.org/D147370
2023-05-02Revert "[lldb][DWARFExpression] Fix DW_OP_div to use signed division"Michael Buch
This reverts commit e15d6b520e1e85d2cdf9ffc66f0c4698390eaa3d. Newly added test fails on Darwin platforms and arm. Differential Revision: https://reviews.llvm.org/D147370
2023-05-02[lldb][DWARFExpression] Fix DW_OP_div to use signed divisionLU Hongyi
This patch resolves an issue where a value is incorrectly displayed if it is represented by DW_OP_div. This issue is caused by lldb evaluating operands of DW_OP_div as unsigned and performed unintended unsigned division. This issue is resolved by creating two temporary signed scalar and performing signed division. (Addresses GH#61727) Differential Revision: https://reviews.llvm.org/D147370
2023-02-13[lldb] Fix image lookup crashAlex Langford
lldb may crash when performing `image lookup --verbose --address $ADDR`. The ExecutionContext that gets passed into DWARFExpression::Evaluate may be valid but unpopulated. However, in one specific case, we were assuming that it has a valid Target and using it without checking first. We reach this codepath when we attempt to get information about an address that doesn't map to a CompileUnit in the module containing the requested address. lldb then checks to see if it maps to a global variable, so lldb has to evaluate the location of each global variable in the module. If a location expression contains DW_OP_deref_size that uses a FileAddress, we hit this code path. The simplest test case is to take a module that has a global variable with DW_OP_deref_size in its location expression, attempt to read an address that doesn't map to a CompileUnit (e.g. 0x0) and ensure we don't crash. Differential Revision: https://reviews.llvm.org/D143792
2023-01-07[lldb] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata
This patch removes the unused "using" declarations, updates comments, and removes #include "llvm/ADT/Optional.h". 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] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
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 Hirata
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-15Remove the dependency between lib/DebugInfoDWARF and MC.Shubham Sandeep Rastogi
Differential Revision: https://reviews.llvm.org/D134817
2022-12-14Revert "Remove the dependency between lib/DebugInfoDWARF and MC."Shubham Sandeep Rastogi
This reverts commit 7dde94251e1c9e4634f5d51d41f2d4a191258fb3. Because of test failures: lldb-shell :: SymbolFile/DWARF/x86/DW_AT_loclists_base.s lldb-shell :: SymbolFile/DWARF/x86/debug_loc.s lldb-shell :: SymbolFile/DWARF/x86/debug_loc_and_loclists.s lldb-shell :: SymbolFile/DWARF/x86/debug_loclists-dwo.s lldb-shell :: SymbolFile/DWARF/x86/debug_loclists-dwp.s lldb-shell :: SymbolFile/DWARF/x86/dwp.s lldb-shell :: SymbolFile/DWARF/x86/unused-inlined-params.test lldb-shell :: SymbolFile/NativePDB/inline_sites.test lldb-shell :: SymbolFile/NativePDB/local-variables-registers.s lldb-shell :: SymbolFile/NativePDB/nested-blocks-same-address.s
2022-12-14Remove the dependency between lib/DebugInfoDWARF and MC.Shubham Sandeep Rastogi
Differential Revision: https://reviews.llvm.org/D134817
2022-12-05[DebugInfo] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02Leave DW_OP_addr addresses as load addresses in DWARFExpressionJason Molenda
DWARFExpression::Evaluate will convert DW_OP_addr addresses in a DWARF expression into load addresses on the expression stack when there is a StackFrame in the ExecutionContext, this from a change in 2018 in https://reviews.llvm.org/D46362. At the time this was handling a case that came up in swift programs, and is no longer necessary. I generalized this conversion to a load address when a Target is available in https://reviews.llvm.org/D137682 to make a test case possible; this change broke a use case that Ted reported. This change removes my test case, and removes this conversion of a DW_OP_addr into a load address in some instances. Differential Revision: https://reviews.llvm.org/D139226
2022-11-22[lldb] Allow plugins to extend DWARF expression parsing for vendor extensionsPhilip Pfaffe
Parsing DWARF expressions currently does not support DW_OPs that are vendor extensions. With this change expression parsing calls into SymbolFileDWARF for unknown opcodes, which is the semantically "closest" plugin that we have right now. Plugins can then extend SymbolFileDWARF to add support for vendor extensions. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D137247
2022-11-14Change last-ditch magic address in IRMemoryMap::FindSpaceJason Molenda
When we cannot allocate memory in the inferior process, the IR interpreter's IRMemoryMap::FindSpace will create an lldb local buffer and assign it an address range in the inferior address space. When the interpreter sees an address in that range, it will read/write from the local buffer instead of the target. If this magic address overlaps with actual data in the target, the target cannot be accessed through expressions. Instead of using a high memory address that is validly addressable, this patch uses an address that cannot be accessed on 64-bit systems that don't actually use all 64 bits of the virtual address. Differential Revision: https://reviews.llvm.org/D137682 rdar://96248287
2022-11-02[wasm] Always treat DWARF expression addresses as load addressesPhilip Pfaffe
When resolving absolute addresses for DW_OP_addr or DW_OP_addrx, these are always load addresses rather than file addresses in wasm. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D135664
2022-10-06Revert "Remove the dependency between lib/DebugInfoDWARF and MC."Shubham Sandeep Rastogi
This reverts commit d96ade00c3c96bd451c60e34a17e613cdd5fdc38.
2022-10-06Remove the dependency between lib/DebugInfoDWARF and MC.Shubham Sandeep Rastogi
This patch had to be reverted because on gcc 7.5.0 we see an error converting from std::unique_ptr<MCRegisterInfo> to Expected<std::unique_ptr<MCRegisterInfo>> as the return type for the function createRegInfo. This has now been fixed.
2022-10-06Revert "Remove the dependency between lib/DebugInfoDWARF and MC."Shubham Sandeep Rastogi
This reverts commit 0008990479a2daf587c2a4f274384b2fb87247fb.
2022-10-06Remove the dependency between lib/DebugInfoDWARF and MC.Shubham Sandeep Rastogi
Differential Revision: https://reviews.llvm.org/D134817
2022-09-13[lldb] Fixed a number of typosGabriel Ravier
I went over the output of the following mess of a command: (ulimit -m 2000000; ulimit -v 2000000; git ls-files -z | parallel --xargs -0 cat | aspell list --mode=none --ignore-case | grep -E '^[A-Za-z][a-z]*$' | sort | uniq -c | sort -n | grep -vE '.{25}' | aspell pipe -W3 | grep : | cut -d' ' -f2 | less) and proceeded to spend a few days looking at it to find probable typos and fixed a few hundred of them in all of the llvm project (note, the ones I found are not anywhere near all of them, but it seems like a good start). Differential revision: https://reviews.llvm.org/D131122
2022-09-12Fix DW_OP_convert to resolve the CU relative offset correctly.Greg Clayton
Debugging some DWARF5 binaries was causing errors to appear when DWARFExpression::Evaluate was called: error: GetDIE for DIE 0x31 is outside of its CU 0x123450 The issue is in the DWARF expression evaluator. Fixed with this. Differential Revision: https://reviews.llvm.org/D133623
2022-08-08[lldb] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
2022-07-22[lldb] Handle jumping to the end in DW_OP_skip/DW_OP_braAndy Yankovsky
DW_OP_skip/DW_OP_bra can move offset to the end of the data, which means that this was the last instruction to execute and the interpreter should terminate. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D130285