aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/Expression/DWARFExpressionTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
3 days[lldb] Support DW_OP_WASM_location in DWARFExpression (#151010)Jonas Devlieghere1-152/+427
Add support for DW_OP_WASM_location in DWARFExpression. This PR rebases #78977 and cleans up the unit test. The DWARF extensions are documented at https://yurydelendik.github.io/webassembly-dwarf/ and supported by LLVM-based toolchains such as Clang, Swift, Emscripten, and Rust.
11 days[lldb] Eliminate namespace lldb_private::dwarf (NFC) (#150073)Jonas Devlieghere1-1/+1
Eliminate the `lldb_private::dwarf` namespace, in favor of using `llvm::dwarf` directly. The latter is shorter, and this avoids ambiguity in the ABI plugins that define a `dwarf` namespace inside an anonymous namespace.
12 days[lldb] Add an extra optional did_read_live_memory to Target::ReadMemory ↵Augusto Noronha1-1/+2
(#149620) Target::ReadMemory may or may not read live memory, but whether it did read from live memory or from the filecache is opaque to callers. Add an extra out parameter to indicate whether live memory was read or not.
2024-10-29[DWARF] Fix arity of DW_OP_bra (#114136)Jonas Devlieghere1-0/+3
Found by my proof-of-concept DWARF expression evaluator fuzzer.
2024-06-05[lldb] Return an llvm::Expected from DWARFExpression::Evaluate (NFCI) (#94420)Jonas Devlieghere1-40/+38
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 Devlieghere1-0/+69
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
2023-10-13[LLDB] Fix buildbotswalter erquinigo1-0/+1
https://lab.llvm.org/buildbot/#/builders/96/builds/46935 https://lab.llvm.org/buildbot/#/builders/68/builds/61651 are failing because of some namespace changes introduced by https://reviews.llvm.org/rG1673a1ba5dec
2023-07-21[lldb] Consider OP_addrx in DWARFExpression::Update_DW_OP_addrFelipe de Azevedo Piovezan1-0/+5
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-19[lldb][NFC] Refactor test to enable subsequent reuseFelipe de Azevedo Piovezan1-10/+17
On a subsequent commit, I intend to update the expression and call the evaluate function more times. This refactors enables reusing some of the existing code for that. Differential Revision: https://reviews.llvm.org/D155197
2023-02-22[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich1-2/+2
This came out of from https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902 With big binaries we can have .dwp files where .debug_info.dwo section can grow beyond 4GB. We would like to support this in LLVM and in LLDB. The plan is to enable manual parsing of cu/tu index in DWARF library (https://reviews.llvm.org/D137882), and then switch internal index data structure to 64 bit. For the second part is to enable 64bit offset support in LLDB with this patch. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138618
2023-02-16Revert "[LLDB] Enable 64 bit debug/type offset"Alexander Yermolovich1-2/+2
This reverts commit 2062e90aa531e8445e5dc0e16222c0f246af1bf4.
2023-02-16[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich1-2/+2
This came out of from https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902 With big binaries we can have .dwp files where .debug_info.dwo section can grow beyond 4GB. We would like to support this in LLVM and in LLDB. The plan is to enable manual parsing of cu/tu index in DWARF library (https://reviews.llvm.org/D137882), and then switch internal index data structure to 64 bit. For the second part is to enable 64bit offset support in LLDB with this patch. Depends on D139955 Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138618
2023-02-13Revert "[LLDB] Enable 64 bit debug/type offset"Alexander Yermolovich1-2/+2
This reverts commit f36fe009c0fc1d655bfc6168730bedfa1b36e622.
2023-02-13[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich1-2/+2
This came out of from https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902 With big binaries we can have .dwp files where .debug_info.dwo section can grow beyond 4GB. We would like to support this in LLVM and in LLDB. The plan is to enable manual parsing of cu/tu index in DWARF library (https://reviews.llvm.org/D137882), and then switch internal index data structure to 64 bit. For the second part is to enable 64bit offset support in LLDB with this patch. Depends on D139955 Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138618
2023-01-13Revert "[lldb] Add Debugger & ScriptedMetadata reference to ↵Med Ismail Bennani1-9/+4
Platform::CreateInstance" This reverts commit 2d53527e9c64c70c24e1abba74fa0a8c8b3392b1.
2023-01-12[lldb] Add Debugger & ScriptedMetadata reference to Platform::CreateInstanceMed Ismail Bennani1-4/+9
This patch is preparatory work for Scripted Platform support and does multiple things: First, it introduces new options for the `platform select` command and `SBPlatform::Create` API, to hold a reference to the debugger object, the name of the python script managing the Scripted Platform and a structured data dictionary that the user can use to pass arbitrary data. Then, it updates the various `Create` and `GetOrCreate` methods for the `Platform` and `PlatformList` classes to pass down the new parameter to the `Platform::CreateInstance` callbacks. Finally, it updates every callback to reflect these changes. Differential Revision: https://reviews.llvm.org/D139249 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-11-22[lldb] Allow plugins to extend DWARF expression parsing for vendor extensionsPhilip Pfaffe1-0/+241
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-02[wasm] Always treat DWARF expression addresses as load addressesPhilip Pfaffe1-0/+113
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-09-19[lldb] Remove LLDB reproducersJonas Devlieghere1-4/+1
This patch removes the remaining reproducer code. The SBReproducer class remains for ABI stability but is just an empty shell. This completes the removal process outlined on the mailing list [1]. [1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html
2022-09-12Fix DW_OP_convert to resolve the CU relative offset correctly.Greg Clayton1-1/+17
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 Song1-1/+1
2022-08-08[lldb] Make Process and subclass constructors protectedMichał Górny1-1/+3
Make constructors of the Process and its subclasses class protected, to prevent accidentally constructing Process on stack when it could be afterwards accessed via a shared_ptr (since it uses std::enable_shared_from_this<>). The only place where a stack allocation was used were unittests, and fixing them via declaring an explicit public constructor in the respective mock classes is trivial. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D131275
2022-07-22[lldb] Handle jumping to the end in DW_OP_skip/DW_OP_braAndy Yankovsky1-0/+19
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
2022-03-03[LLDB] Remove cases of using namespace llvm:: from header fileShafik Yaghmour1-0/+1
We have using namespace llvm::dwarf in dwarf.h header globally. Replacing that with a using namespace within lldb_private::dwarf and moving to a using namespace lldb_private::dwarf in .cpp files and fully qualified names in the few header files. Differential Revision: https://reviews.llvm.org/D120836
2021-10-18[lldb] Return StringRef from PluginInterface::GetPluginNamePavel Labath1-1/+1
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-09-13[lldb] Remove PluginInterface::GetPluginVersionPavel Labath1-1/+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-03-23Teach DWARFExpression about DWARF 4+ Location DescriptionsAdrian Prantl1-18/+30
DWARFExpression implements the DWARF2 expression model that left ambiguity on whether the result of an expression was a value or an address. This patch implements the DWARF location description model introduces in DWARF 4 and sets the result Value's kind accordingly, if the expression comes from a DWARF v4+ compile unit. The nomenclature is taken from DWARF 5, chapter 2.6 "Location Descriptions". Differential Revision: https://reviews.llvm.org/D98996
2021-03-02Promote scalars to load addresses when dereferencing them.Adrian Prantl1-1/+9
This is a follow-up to 188b0747c1664d962e94f00b5e3caac529fa1e26. This is a very narrow fix to a more general problem. LLDB should be better at distinguishing between implict and memory location descriptions. rdar://74902042
2021-02-12Support dereferencing a DWARF scalar stack valueAdrian Prantl1-7/+74
Swift async functions receive function arguments inside a heap-allocated data structure, similar to how ObjC block captures or C++ coroutine arguments are implement. In DWARF they are described relative to an entry value that produces a pointer into that heap object. At typical location looks like DW_OP_entry_value [ DW_OP_reg14 ] DW_OP_deref DW_OP_plus_uconst 32 DW_OP_deref This allows the unwinder (which has special ABI knowledge to restore the contents of r14) to push the base address onto the stack thus allowing the deref/offset operations to continue. The result of the entry value is a scalar, because DW_OP_reg14 is a register location — as it should be since we want to restore the pointer value contained in r14 at the beginning of the function and not the historical memory contents it was pointing to. The entry value should restore the address, which is still valid, not the contents at function entry. To make this work, we need to allow LLDB to dereference Scalar stack results like load addresses, which is what this patch does. Unfortunately it is difficult to test this in isolation, since the DWARFExpression unit test doesn't have a process. Differential Revision: https://reviews.llvm.org/D96549
2021-02-12Make the error condition in Value::ValueType explicit (NFC)Adrian Prantl1-2/+2
The comment for ValueType claims that all values <1 are errors, but not all switch statements take this into account. This patch introduces an explicit Error case and deletes all default: cases, so we get warned about incomplete switch coverage. https://reviews.llvm.org/D96537
2021-02-10Diagnose unhandled cases in DW_OP_derefAdrian Prantl1-0/+4
2020-11-10[lldb/DWARF] Fix sizes of DW_OP_const[1248][us] and DW_OP_litN resultsPavel Labath1-14/+50
Dwarf says (Section 2.5.1.1. of DWARF v5) that these operations should push "generic" (pointer-sized) values. This was not the case for DW_OP_const operations (which were pushing values based on the size of arguments), nor DW_OP_litN (which were always pushing 64-bit values). The practical effect of this that were were unable to display the values of variables if the size of the DW_OP_const opcode was smaller than the value of the variable it was describing. This would happen because we would store this (small) result into a buffer and then would not be able to read sufficient data out of it (in Value::GetValueAsData). Gcc emits debug info like this. Other (more subtle) effects are also possible. The same fix should be applied to DW_OP_const[us] (leb128 versions), but I'm not doing that right now, because that would cause us to display wrong (truncated) values of variables on 32-bit targets (pr48087). Differential Revision: https://reviews.llvm.org/D90840
2020-10-30[lldb/test] Simplify/generalize YAMLModuleTesterPavel Labath1-58/+66
The class only supports a single DWARF unit (needed for my new test), and it reimplements chunks of object and symbol file classes. We can just make it use the real thing, save some LOC and get the full feature set. Differential Revision: https://reviews.llvm.org/D90393
2020-10-22[lldb/DWARF] Add support for DW_OP_implicit_valueMed Ismail Bennani1-0/+8
This patch completes https://reviews.llvm.org/D83560. Now that the compiler can emit `DW_OP_implicit_value` into DWARF expressions, lldb needed to learn reading these opcodes for variable inspection and expression evaluation. This implicit location descriptor specifies an immediate value with two operands: the length (ULEB128) followed by a block representing the value in the target memory representation. rdar://67406091 Differential revision: https://reviews.llvm.org/D89842 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-08-31[Test] Simplify DWARF test cases. NFC.Xing GUO1-4/+1
The Length, AbbrOffset and Values fields of the debug_info section are optional. This patch helps remove them and simplify test cases. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D86857
2020-08-21[DWARFYAML] Add support for emitting multiple abbrev tables.Xing GUO1-14/+15
This patch adds support for emitting multiple abbrev tables. Currently, compilation units will always reference the first abbrev table. Reviewed By: jhenderson, labath Differential Revision: https://reviews.llvm.org/D86194
2020-07-22[DWARFYAML] Make the length field of compilation units optional. NFC.Xing GUO1-2/+1
This patch makes the length field of compilation units optional (0 by default).
2020-06-30[DWARFYAML][debug_info] Replace 'InitialLength' with 'Format' and 'Length'.Xing GUO1-2/+1
'InitialLength' is replaced with 'Format' (DWARF32 by default) and 'Length' in this patch. Besides, test cases for DWARFv4 and DWARFv5, DWARF32 and DWARF64 is added. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D82622
2020-06-24[lldb] Refactor Scalar::TruncOrExtendToPavel Labath1-29/+2
The "type" argument to the function is mostly useless -- the only interesting aspect of it is signedness. Pass signedness directly and compute the value of bits and signedness fields -- that's exactly what the single caller of this function does.
2020-06-08[lldb] Fail evaluation of DWARF expressions with unknown opcodesPavel Labath1-6/+13
Previously, we were simply ignoring them and continuing the evaluation. This behavior does not seem useful, because the resulting value will most likely be completely bogus.
2020-03-31[lldb/DWARF] Fix evaluator crash when accessing empty stack.Med Ismail Bennani1-0/+4
This patch fixes a crash that happens on the DWARF expression evaluator when trying to access the top of the stack while it's empty. rdar://60512489 Differential Revision: https://reviews.llvm.org/D77108 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-03-31Revert "[lldb/DWARF] Fix evaluator crash when accessing empty stack."Med Ismail Bennani1-4/+0
This reverts commit e26eece1e2e7d7e6fbadb1207afef9b6353b5330.
2020-03-31[lldb/DWARF] Fix evaluator crash when accessing empty stack.Med Ismail Bennani1-0/+4
This patch fixes a crash that happens on the DWARF expression evaluator when trying to access the top of the stack while it's empty. Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-02-04[lldb/Unittest] Fix the modules build by including TypeSystemClang.hJonas Devlieghere1-0/+1
This should fix the modules build on the GreenDragon bot.
2020-02-04Re-land "[lldb] [testsuite] generalize `DWARFASTParserClangTests` based on ↵Jonas Devlieghere1-122/+4
`DWARFExpressionTest`'s YAML"
2020-02-04Revert: [lldb] [testsuite] generalize `DWARFASTParserClangTests` based on ↵Jan Kratochvil1-4/+122
`DWARFExpressionTest`'s YAML It is causing a failure on OSX, to be investigated more. Differential Revision: https://reviews.llvm.org/D73279
2020-02-04[lldb] [testsuite] generalize `DWARFASTParserClangTests` based on ↵Jan Kratochvil1-122/+4
`DWARFExpressionTest`'s YAML YAMLModuleTester from DWARFExpressionTest can be reused for more testcases. Differential Revision: https://reviews.llvm.org/D73279
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann1-1/+1
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2020-01-16Fix a buffer-size bug when the first DW_OP_piece is undefinedAdrian Prantl1-0/+5
and document the shortcomings of LLDB's partially defined DW_OP_piece handling. This would manifest as "DW_OP_piece for offset foo but top of stack is of size bar". rdar://problem/46262998 Differential Revision: https://reviews.llvm.org/D72880
2020-01-16Add testing for DW_OP_piece and fix a bug with small Scalar values.Adrian Prantl1-1/+22
By switching to Scalars that are backed by explicitly-sized APInts we can avoid a bug that increases the buffer reserved for a small piece to the next-largest host integer type. This manifests as "DW_OP_piece for offset foo but top of stack is of size bar". Differential Revision: https://reviews.llvm.org/D72879