summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
AgeCommit message (Collapse)Author
2025-06-23[lldb][DWARF] Support retrieving DW_FORM_implicit_const value with ↵Michael Buch
DWARFDebugInfoEntry::GetAttributeValue (#145328) `DWARFFormValue::ExtractValue` has nothing to extract for `DW_FORM_implicit_const` since the value is stored in the abbreviation. `DWARFFormValue` expects the user to have set the value of the implicit_const. This patch does so in `GetAttributeValue`.
2025-06-13[lldb][DWARF] Don't try to compute address range information of forward ↵Michael Buch
declarations (#144059) This fixes the error reported in https://github.com/llvm/llvm-project/pull/144037. When computing the aranges table of a CU, LLDB would currently visit all `DW_TAG_subprogram` DIEs and check their `DW_AT_low_pc`/`DW_AT_high_pc`/`DW_AT_ranges` attributes. If those don't exist it would error out and spam the console. Some subprograms (particularly forward declarations) don't have low/high pc attributes, so it's not really an "error". See DWARFv5 spec section `3.3.3 Subroutine and Entry Point Locations`: ``` A subroutine entry may have either a DW_AT_low_pc and DW_AT_high_pc pair of attributes or a DW_AT_ranges attribute whose values encode the contiguous or non-contiguous address ranges, respectively, of the machine instructions generated for the subroutine (see Section 2.17 on page 51). ... A subroutine entry representing a subroutine declaration that is not also a definition does not have code address or range attributes. ``` We should just ignore those DIEs.
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-24[lldb] Use the first address range as the function address (#122440)Pavel Labath
This is the behavior expected by DWARF. It also requires some fixups to algorithms which were storing the addresses of some objects (Blocks and Variables) relative to the beginning of the function. There are plenty of things that still don't work in this setups, but this change is sufficient for the expression evaluator to correctly recognize the entry point of a function in this case.
2025-01-17[lldb][DWARF] Change GetAttributes parameter from SmallVector to SmallVectorImplMichael Buch
Fixes the lldb-arm-ubuntu buildbot failure: ``` ../llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp:374:26: error: non-const lvalue reference to type 'SmallVector<[...], (default) CalculateSmallVectorDefaultInlinedElements<T>::value aka 6>' cannot bind to a value of unrelated type 'SmallVector<[...], 3>' 374 | if (!::GetAttributes(worklist, seen, attributes)) { | ^~~~~~~~ ../llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp:288:56: note: passing argument to parameter 'worklist' here 288 | static bool GetAttributes(llvm::SmallVector<DWARFDIE> &worklist, | ^ 1 error generated. ```
2025-01-17[lldb][DWARF] Change GetAttributes to always visit current DIE before ↵Michael Buch
recursing (#123261) `GetAttributes` returns all attributes on a given DIE, including any attributes that the DIE references via `DW_AT_abstract_origin` and `DW_AT_specification`. However, if an attribute exists on both the referring DIE and the referenced DIE, the first one encountered will be the one that takes precendence when querying the returned `DWARFAttributes`. But there was no guarantee in which order those attributes get visited. That means there's no convenient way of ensuring that an attribute of a definition doesn't get shadowed by one found on the declaration. One use-case where we don't want this to happen is for `DW_AT_object_pointer` (which can exist on both definitions and declarations, see https://github.com/llvm/llvm-project/pull/123089). This patch makes sure we visit the current DIE's attributes before following DIE references. I tried keeping as much of the original `GetAttributes` unchanged and just add an outer `GetAttributes` that keeps track of the DIEs we need to visit next. There's precendent for this iteration order in `llvm::DWARFDie::findRecursively` and also `lldb_private::ElaboratingDIEIterator`. We could use the latter to implement `GetAttributes`, though it also follows `DW_AT_signature` so I decided to leave it for follow-up.
2024-12-13[lldb/DWARF] s/DWARFRangeList/llvm::DWARFAddressRangeVector (#116620)Pavel Labath
The main difference is that the llvm class (just a std::vector in disguise) is not sorted. It turns out this isn't an issue because the callers either: - ignore the range list; - convert it to a different format (which is then sorted); - or query the minimum value (which is faster than sorting) The last case is something I want to get rid of in a followup as a part of removing the assumption that function's entry point is also its lowest address.
2024-11-18[lldb] rm DWARFDebugRanges (#116379)Pavel Labath
The class is only used from one place, which is trivial to implement using the llvm class. The main difference is that in the new implementation, the ranges are parsed each time anew (instead of being parsed at startup and cached). I believe this is fine because: - this is already how things work with DWARF v5 debug_rnglists - parsing debug_ranges is fairly fast (definitely faster than rnglists) - generally, this result will be cached at a higher level anyway. Browsing the code I did find one instance where that is not the case -- SymbolFileDWARF::ResolveFunctionAndBlock -- which is called each time we resolve an address (to the block level). However, this function is already pretty suboptimal: it first traverses the DIE tree (which involves parsing all the DIE attributes) to find the correct block, then it parses them again to construct the `lldb_private::Block` representation, and *then* it uses the ID of the block DIE it found in the first step to look up the `Block` object. If this turns out to be a bottleneck, I think there are better ways to optimize it than caching the debug_ranges parse. The motiviation for this is that DWARFDebugRanges sorts the block ranges, even though the order of the ranges is load-bearing (in the absence of DW_AT_low_pc, the "base address" of a scope is determined by the first range entry). Delaying the parsing (and sorting) step makes it easier to access the first entry.
2024-11-07[lldb] Index static const members of classes, structs and unions as global ↵Ilia Kuklin
variables in DWARF 4 and earlier (#111859) In DWARF 4 and earlier `static const` members of structs, classes and unions have an entry tag `DW_TAG_member`, and are also tagged as `DW_AT_declaration`, but otherwise follow the same rules as `DW_TAG_variable`.
2024-09-30Fix an integer trunctation issues for the DW_AT_frame_base DWARF location ↵Greg Clayton
expression (#110388) This patch allows offsets to the DW_AT_frame_base to exceed 4GB. Prior to this, for any .debug_info.dwo offset that exceeded 4GB, we would truncate the offset to the DW_AT_frame_base expression bytes to be 32 bit only. Changing the offset to 64 bits restores correct functionality. No test for this as we don't want to create a .dwp file that has a .debug_info.dwo size that is over 4GB.
2024-09-10[lldb] Recurse through DW_AT_signature when looking for attributes (#107241)Pavel Labath
This allows e.g. DWARFDIE::GetName() to return the name of the type when looking at its declaration (which contains only DW_AT_declaration+DW_AT_signature). This is similar to how we recurse through DW_AT_specification when looking for a function name. Llvm dwarf parser has obtained the same functionality through #99495. This fixes a bug where we would confuse a type like NS::Outer::Struct with NS::Struct (because NS::Outer (and its name) was in a type unit).
2024-06-13[lldb] Move DWARFDeclContext functions from DWARFDebugInfoEntry to DW… ↵Pavel Labath
(#95227) …ARFDIE This puts them closer to the other two functions doing something very similar. I've tried to stick to the original logic of the functions as much as possible, though I did apply some easy simplifications. The changes in DWARFDeclContext.h are there to make the unit tests produce more useful error messages.
2024-05-23[lldb/DWARF] Make sure bad abbreviation codes do not crash lldb (#93006)Pavel Labath
We currently cannot represent abbreviation codes with more than 16 bits, and we were lldb-asserting if we ever ran into one. While I haven't seen any real DWARF with these kinds of abbreviations, it is possible to hit this with handcrafted evil dwarf, due some sort of corruptions, or just bugs (the addition of PeekDIEName makes these bugs more likely, as the function blindly dereferences offsets within the debug info section) . Missing abbreviations were already reporting an error. This patch turns sure that large abbreviations into an error as well, and adds a test for both cases.
2023-10-19[lldb][NFCI] Remove duplicated code in DWARFParser (#69531)Felipe de Azevedo Piovezan
The method DWARFDebugInfoEntry::Extract needs to skip over all the data in the debug_info / debug_types section for each DIE. It had the logic to do so hardcoded inside a loop, when it already exists in a neatly isolated function.
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-10-02[lldb] Replace lldb's DWARFDebugAbbrev implementation with llvm's (#67841)Alex Langford
The implementations are now close enough that replacing it is trivial.
2023-06-12[lldb] Remove lldb's DWARFAbbreviationDeclarationSet in favor of llvm'sAlex Langford
lldb's and llvm's implementations of DWARFAbbreviationDeclarationSet are now close enough (almost the same, actually) to replace lldb's with llvm's wholesale. llvm's is also tested against the same kinds of scenarios that lldb's is tested against so we can remove lldb's tests here. (see: llvm/unittests/DebugInfo/DWARF/DWARFDebugAbbrevTest.cpp). Differential Revision: https://reviews.llvm.org/D152476
2023-05-25[lldb][nfc] Refactor methods with out parameterFelipe de Azevedo Piovezan
Currently, the method `GetAttributeAddressRanges` takes a DWARFRangeList as a parameter, just to immediately clear it. The method also returns the size of this list. Such an API was obfuscating the intent of the call sites (it's not clear from the method name what it returns) and it was obfuscating redundant checks on the size of the list. This commit refactors the method to return the list and to also make the call sites use the more explicit `IsEmpty` method. Differential Revision: https://reviews.llvm.org/D151451
2023-05-18[lldb][NFCI] Switch to using llvm::DWARFAbbreviationDeclarationAlex Langford
Both LLVM and LLDB implement DWARFAbbreviationDeclaration. As of 631ff46cbf51, llvm's implementation of DWARFAbbreviationDeclaration::extract behaves the same as LLDB's implementation, making it easier to merge the implementations. The only major difference between LLDB's implementation and LLVM's implementation is that LLVM's DWARFAbbreviationDeclaration is slightly larger. Specifically, it has some metadata that keeps track of the size of a declaration (if it has a fixed size) so that it can potentially optimize extraction in some scenarios. I think this increase in size should be acceptable and possibly useful on the LLDB side. Differential Revision: https://reviews.llvm.org/D150716
2023-05-12[lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributesAlex Langford
The purpose of this method is to get the list of attributes of a DebugInfoEntry. Prior to this change we were passing in a mutable reference to a DWARFAttributes object and having the method fill it in for us while returning the size of the filled out list. But instead of doing that, we can just return a `DWARFAttributes` object ourselves since every caller creates a new list before calling GetAttributes. Differential Revision: https://reviews.llvm.org/D150402
2023-05-10[lldb][NFCI] Replace dw_form_t with llvm::dwarf::FormAlex Langford
LLDB currently defines `dw_form_t` as a `uint16_t` which makes sense. However, LLVM also defines a similar type `llvm::dwarf::Form` which is an enum backed by a `uint16_t`. Switching to the llvm implementation means that we can more easily interoperate with the LLVM DWARF code. Additionally, we get some type checking out of this: I found that DWARFAttribute had a method called `FormAtIndex` that returned a `dw_attr_t`. Although `dw_attr_t` is also a `uint16_t` under the hood, the type checking benefits here are undeniable: If this had returned a something of different signedness/width, we could have had some bad bugs. Differential Revision: https://reviews.llvm.org/D150228
2023-03-06[lldb] Make GetDIENamesAndRanges() allow 0-valued decl and call linesDavid Stenberg
In an upcoming patch, D142556, Clang is proposed to be changed to emit line locations that are inlined at line 0. This clashed with the behavior of GetDIENamesAndRanges() which used 0 as a default value to determine if file, line or column numbers had been set. Users of that function then checked for any non-0 values when setting up the call site: if (call_file != 0 || call_line != 0 || call_column != 0) [...] which did not work with the Clang change since all three values then could be 0. This changes the function to use std::optional to catch non-set values instead. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D142552
2023-02-22[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich
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 Yermolovich
This reverts commit 2062e90aa531e8445e5dc0e16222c0f246af1bf4.
2023-02-16[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich
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 Yermolovich
This reverts commit f36fe009c0fc1d655bfc6168730bedfa1b36e622.
2023-02-13[LLDB] Enable 64 bit debug/type offsetAlexander Yermolovich
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-09[LLDB] Change formatting to use llvm::formatvAlexander Yermolovich
In preparation for eanbling 64bit support in LLDB switching to use llvm::formatv instead of format MACROs. Reviewed By: labath, JDevlieghere Differential Revision: https://reviews.llvm.org/D139955
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-04[lldb] Use std::nullopt instead of None (NFC)Kazu Hirata
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-10-14[lldb][NFCish] Move DWARFDebugInfoEntry::GetQualifiedName() into ↵Arthur Eubanks
DWARFASTParserClang In D134378, we'll need the clang AST to be able to construct the qualified in some cases. This makes logging in one place slightly less informative. Reviewed By: dblaikie, Michael137 Differential Revision: https://reviews.llvm.org/D135979
2022-08-25Don't index the skeleton CU when we have a fission compile unit.Greg Clayton
When fission is enabled, we were indexing the skeleton CU _and_ the .dwo CU. Issues arise when users enable compiler options that add extra data to the skeleton CU (like -fsplit-dwarf-inlining) and there can end up being types in the skeleton CU due to template parameters. We never want to index this information since the .dwo file has the real definition, and we really don't want function prototypes from this info since all parameters are removed. The index doesn't work correctly if it does index the skeleton CU as the DIE offset will assume it is from the .dwo file, so even if we do index the skeleton CU, the index entries will try and grab information from the .dwo file using the wrong DIE offset which can cause errors to be displayed or even worse, if the DIE offsets is valid in the .dwo CU, the wrong DIE will be used. We also fix DWO ID detection to use llvm::Optional<uint64_t> to make sure we can load a .dwo file with a DWO ID of zero. Differential Revision: https://reviews.llvm.org/D131437
2022-08-08[lldb] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
2022-08-04Re-submit "[lldb] Filter DIEs based on qualified name where possible"Alex Langford
This reverts commit 967df65a3610f98a3bc0ec0f2303641d7bad176c. This fixes test/Shell/SymbolFile/NativePDB/find-functions.cpp. When looking up functions with the PDB plugins, if we are looking for a full function name, we should use `GetName` to populate the `name` field instead of `GetLookupName` since `GetName` has the more complete information.
2022-08-04Revert "[lldb] Filter DIEs based on qualified name where possible"Alex Langford
This reverts commit befa77e59a7760d8c4fdd177b234e4a59500f61c. Looks like this broke a SymbolFileNativePDB test. I'll investigate and resubmit with a fix soon.
2022-08-04[lldb] Filter DIEs based on qualified name where possibleAlex Langford
Context: When setting a breakpoint by name, we invoke Module::FindFunctions to find the function(s) in question. However, we use a Module::LookupInfo to first process the user-provided name and figure out exactly what we're looking for. When we actually perform the function lookup, we search for the basename. After performing the search, we then filter out the results using Module::LookupInfo::Prune. For example, given a::b::foo we would first search for all instances of foo and then filter out the results to just names that have a::b::foo in them. As one can imagine, this involves a lot of debug info processing that we do not necessarily need to be doing. Instead of doing one large post-processing step after finding each instance of `foo`, we can filter them as we go to save time. Some numbers: Debugging LLDB and placing a breakpoint on llvm::itanium_demangle::StringView::begin without this change takes approximately 70 seconds and resolves 31,920 DIEs. With this change, placing the breakpoint takes around 30 seconds and resolves 8 DIEs. Differential Revision: https://reviews.llvm.org/D129682
2022-07-12Reland "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Zequan Wu
This reland 227dffd0b6d78154516ace45f6ed28259c7baa48 and 562c3467a6738aa89203f72fc1d1343e5baadf3c with failed api tests fixed by keeping function base file addres in DWARFExpressionList.
2022-07-07Revert "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Jonas Devlieghere
This reverts commit 227dffd0b6d78154516ace45f6ed28259c7baa48 and its follow up 562c3467a6738aa89203f72fc1d1343e5baadf3c because it breaks a bunch of tests on GreenDragon: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45155/
2022-07-07[LLDB][NFC] Decouple dwarf location table from DWARFExpression.Zequan Wu
Differential Revision: https://reviews.llvm.org/D125509
2022-03-04[LLDB] Remove cases of using namespace stdShafik Yaghmour
We had using namespace std; sprinkled around several source files and tests. Differential Revision: https://reviews.llvm.org/D120966
2022-03-03[LLDB] Remove cases of using namespace llvm:: from header fileShafik Yaghmour
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-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2021-05-20[lldb] Improve invalid DWARF DW_AT_ranges error reportingJan Kratochvil
In D98289#inline-939112 @dblaikie said: Perhaps this could be more informative about what makes the range list index of 0 invalid? "index 0 out of range of range list table (with range list base 0xXXX) with offset entry count of XX (valid indexes 0-(XX-1))" Maybe that's too verbose/not worth worrying about since this'll only be relevant to DWARF producers trying to debug their DWARFv5, maybe no one will ever see this message in practice. Just a thought. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102851
2021-03-09[lldb] Fix DWARF-5 DW_FORM_implicit_const (used by GCC)Jan Kratochvil
Differential Revision: https://reviews.llvm.org/D98197
2021-03-02[nfc] [lldb] DWARFDebugInfoEntry::Extract(): reindentJan Kratochvil
2021-03-02[lldb] DWARFDebugInfoEntry::Extract(): Print an error for unsupported DW_FORM_*Jan Kratochvil
2021-03-02[lldb] Support DWARF-5 DW_FORM_line_strp (used by GCC)Jan Kratochvil
LLDB has been failing on binaries produced by new GCC 11.0 with -gdwarf-5. Differential Revision: https://reviews.llvm.org/D97721
2021-01-07lldb: Add support for DW_AT_ranges on DW_TAG_subprogramsDavid Blaikie
gcc already produces debug info with this form -freorder-block-and-partition clang produces this sort of thing with -fbasic-block-sections and with a coming-soon tweak to use ranges in DWARFv5 where they can allow greater reuse of debug_addr than the low/high_pc forms. This fixes the case of breaking on a function name, but leaves broken printing a variable - a follow-up commit will add that and improve the test case to match. Differential Revision: https://reviews.llvm.org/D94063
2020-11-09[lldb] Fix DW_AT_decl_file from DW_AT_specification from a different CUJan Kratochvil
This would be reproducible in future DWZ category of the testsuite as: Failed Tests (1): lldb-api :: python_api/symbol-context/two-files/TestSymbolContextTwoFiles.py Differential Revision: https://reviews.llvm.org/D91014