summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
AgeCommit message (Collapse)Author
2025-09-15[lldb][TypeSystem] Enable colored AST dump (#86159)Michael Buch
This patch causes the various AST dump commands (`target modules dump ast`/`target dump typesystem`) to be color-highlighted. I added a `bool show_color` parameter to `SymbolFile::DumpClangAST` and `TypeSystem::Dump`. In `TypeSystemClang` I temporarily sets the `getShowColors` flag on the owned Clang AST (using an RAII helper) for the duration of the AST dump. We use `Debugger::GetUseColors` to decide whether to color the AST dump.
2025-09-09[lldb][Expression] Add structor variant to LLDB's function call labels (#149827)Michael Buch
Depends on * https://github.com/llvm/llvm-project/pull/148877 * https://github.com/llvm/llvm-project/pull/155483 * https://github.com/llvm/llvm-project/pull/155485 * https://github.com/llvm/llvm-project/pull/154137 * https://github.com/llvm/llvm-project/pull/154142 This patch is an implementation of [this discussion](https://discourse.llvm.org/t/rfc-lldb-handling-abi-tagged-constructors-destructors-in-expression-evaluator/82816/7) about handling ABI-tagged structors during expression evaluation. **Motivation** LLDB encodes the mangled name of a `DW_TAG_subprogram` into `AsmLabel`s on function and method Clang AST nodes. This means that when calls to these functions get lowered into IR (when running JITted expressions), the address resolver can locate the appropriate symbol by mangled name (and it is guaranteed to find the symbol because we got the mangled name from debug-info, instead of letting Clang mangle it based on AST structure). However, we don't do this for `CXXConstructorDecl`s/`CXXDestructorDecl`s because these structor declarations in DWARF don't have a linkage name. This is because there can be multiple variants of a structor, each with a distinct mangling in the Itanium ABI. Each structor variant has its own definition `DW_TAG_subprogram`. So LLDB doesn't know which mangled name to put into the `AsmLabel`. Currently this means using ABI-tagged structors in LLDB expressions won't work (see [this RFC](https://discourse.llvm.org/t/rfc-lldb-handling-abi-tagged-constructors-destructors-in-expression-evaluator/82816) for concrete examples). **Proposed Solution** The `FunctionCallLabel` encoding that we put into `AsmLabel`s already supports stuffing more info about a DIE into it. So this patch extends the `FunctionCallLabel` to contain an optional discriminator (a sequence of bytes) which the `SymbolFileDWARF` plugin interprets as the constructor/destructor variant of that DIE. So when searching for the definition DIE, LLDB will include the structor variant in its heuristic for determining a match. There's a few subtleties here: 1. At the point at which LLDB first constructs the label, it has no way of knowing (just by looking at the debug-info declaration), which structor variant the expression evaluator is supposed to call. That's something that gets decided when compiling the expression. So we let the Clang mangler inject the correct structor variant into the `AsmLabel` during JITing. I adjusted the `AsmLabelAttr` mangling for this in https://github.com/llvm/llvm-project/pull/155485. An option would've been to create a new Clang attribute which behaved like an `AsmLabel` but with these special semantics for LLDB. My main concern there is that we'd have to adjust all the `AsmLabelAttr` checks around Clang to also now account for this new attribute. 2. The compiler is free to omit the `C1` variant of a constructor if the `C2` variant is sufficient. In that case it may alias `C1` to `C2`, leaving us with only the `C2` `DW_TAG_subprogram` in the object file. Linux is one of the platforms where this occurs. For those cases I added a heuristic in `SymbolFileDWARF` where we pick `C2` if we asked for `C1` but it doesn't exist. This may not always be correct (e.g., if the compiler decided to drop `C1` for other reasons). 3. In https://github.com/llvm/llvm-project/pull/154142 Clang will emit `C4`/`D4` variants of ctors/dtors on declarations. When resolving the `FunctionCallLabel` we will now substitute the actual variant that Clang told us we need to call into the mangled name. We do this using LLDB's `ManglingSubstitutor`. That way we find the definition DIE exactly the same way we do for regular function calls. 4. In cases where declarations and definitions live in separate modules, the DIE ID encoded in the function call label may not be enough to find the definition DIE in the encoded module ID. For those cases we fall back to how LLDB used to work: look up in all images of the target. To make sure we don't use the unified mangled name for the fallback lookup, we change the lookup name to whatever mangled name the FunctionCallLabel resolved to. rdar://104968288
2025-08-01[lldb][Expression] Encode Module and DIE UIDs into function AsmLabels (#148877)Michael Buch
LLDB currently attaches `AsmLabel`s to `FunctionDecl`s such that that the `IRExecutionUnit` can determine which mangled name to call (we can't rely on Clang deriving the correct mangled name to call because the debug-info AST doesn't contain all the info that would be encoded in the DWARF linkage names). However, we don't attach `AsmLabel`s for structors because they have multiple variants and thus it's not clear which mangled name to use. In the [RFC on fixing expression evaluation of abi-tagged structors](https://discourse.llvm.org/t/rfc-lldb-handling-abi-tagged-constructors-destructors-in-expression-evaluator/82816) we discussed encoding the structor variant into the `AsmLabel`s. Specifically in [this thread](https://discourse.llvm.org/t/rfc-lldb-handling-abi-tagged-constructors-destructors-in-expression-evaluator/82816/7) we discussed that the contents of the `AsmLabel` are completely under LLDB's control and we could make use of it to uniquely identify a function by encoding the exact module and DIE that the function is associated with (mangled names need not be enough since two identical mangled symbols may live in different modules). So if we already have a custom `AsmLabel` format, we can encode the structor variant in a follow-up (the current idea is to append the structor variant as a suffix to our custom `AsmLabel` when Clang emits the mangled name into the JITted IR). Then we would just have to teach the `IRExecutionUnit` to pick the correct structor variant DIE during symbol resolution. The draft of this is available [here](https://github.com/llvm/llvm-project/pull/149827) This patch sets up the infrastructure for the custom `AsmLabel` format by encoding the module id, DIE id and mangled name in it. **Implementation** The flow is as follows: 1. Create the label in `DWARFASTParserClang`. The format is: `$__lldb_func:module_id:die_id:mangled_name` 2. When resolving external symbols in `IRExecutionUnit`, we parse this label and then do a lookup by DIE ID (or mangled name into the module if the encoded DIE is a declaration). Depends on https://github.com/llvm/llvm-project/pull/151355
2025-07-07Defer loading all DWOs by default when dumping separate_debug-info (#146166)qxy11
### Summary Currently `target modules dump separate separate-debug-info` automatically loads up all DWO files, even if deferred loading is enabled through debug_names. Then, as expected all DWO files (assuming there is no error loading it), get marked as "loaded". This change adds the option `--force-load-all-debug-info` or `-f` for short to force loading all debug_info up, if it hasn't been loaded yet. Otherwise, it will change default behavior to not load all debug info so that the correct DWO files will show up for each modules as "loaded" or not "loaded", which could be helpful in cases where we want to know which particular DWO files were loaded. ### Testing #### Unit Tests Added additional unit tests `test_dwos_load_json_with_debug_names_default` and `test_dwos_load_json_with_debug_names_force_load_all` to test both default behavior and loading with the new flag `--force-load-all-debug-info`, and changed expected behavior in `test_dwos_loaded_symbols_on_demand`. ``` bin/lldb-dotest -p TestDumpDwo ~/llvm-project/lldb/test/API/commands/target/dump-separate-debug-info/dwo ``` #### Manual Testing Compiled a simple binary w/ `--gsplit-dwarf --gpubnames` and loaded it up: ``` (lldb) target create "./a.out" Current executable set to '/home/qxy11/hello-world/a.out' (x86_64). (lldb) help target modules dump separate-debug-info List the separate debug info symbol files for one or more target modules. Syntax: target modules dump separate-debug-info <cmd-options> [<filename> [<filename> [...]]] Command Options Usage: target modules dump separate-debug-info [-efj] [<filename> [<filename> [...]]] -e ( --errors-only ) Filter to show only debug info files with errors. -f ( --force-load-all-debug-info ) Load all debug info files. -j ( --json ) Output the details in JSON format. This command takes options and free-form arguments. If your arguments resemble option specifiers (i.e., they start with a - or --), you must use ' -- ' between the end of the command options and the beginning of the arguments. (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": false }, { ... "dwo_name": "foo.dwo", "loaded": false }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b main Breakpoint 1: where = a.out`main + 15 at main.cc:3:12, address = 0x00000000000011ff (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": false }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b foo Breakpoint 2: where = a.out`foo(int) + 11 at foo.cc:12:11, address = 0x000000000000121b (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/foo.dwo" }, { ... "dwo_name": "bar.dwo", "loaded": false } ], } ] (lldb) b bar Breakpoint 3: where = a.out`bar(int) + 11 at bar.cc:10:9, address = 0x000000000000126b (lldb) target modules dump separate-debug-info --j [ { "separate-debug-info-files": [ { ... "dwo_name": "main.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/main.dwo" }, { ... "dwo_name": "foo.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/foo.dwo" }, { ... "dwo_name": "bar.dwo", "loaded": true, "resolved_dwo_path": "/home/qxy11/hello-world/bar.dwo" } ], } ] ```
2025-06-05Revert "[lldb] Don't create instance of `SymbolFileDWARFDebugMap` for ↵Jason Molenda
non-Mach-O files (#139170)" This reverts commit 3096f8768676bd64123270cc59b7cc904a72d875. Reverting this commit because it depends on another PR that was reverted, https://github.com/llvm/llvm-project/pull/142704 Both can be reapplied once we find a correct fix for that.
2025-06-05[lldb] Don't create instance of `SymbolFileDWARFDebugMap` for non-Mach-O ↵royitaqi
files (#139170) # Change `SymbolFileDWARFDebugMap::CreateInstance()` will return `nullptr` if the file is not a Mach-O. # Benefit This may improve **Linux** debugger launch time by skipping the creation of `SymbolFileDWARFDebugMap` during the [`SymbolFile::FindPlugin()` call](https://fburl.com/hi1w8dil), which loops through a list of `SymbolFile` plugins and tries to find the one that provides the best abilities. If the `SymbolFileDWARFDebugMap` is created during this loop, it will load the symbol table of the file in question and loop through all the compile units in the debug map (the OSO entries) to calculate the abilities. # Tests See PR.
2025-06-02[lldb] Add filter option to AST dump command (#142164)Michael Buch
Depends on https://github.com/llvm/llvm-project/pull/142163 This patch makes the `-ast-dump-filter` Clang option available to the `target modules dump ast` command. This allows us to selectively dump parts of the AST by name. The AST can quickly grow way too large to skim on the console. This will aid in debugging AST related issues. Example: ``` (lldb) target modules dump ast --filter func Dumping clang ast for 48 modules. Dumping func: FunctionDecl 0xc4b785008 <<invalid sloc>> <invalid sloc> func 'void (int)' extern |-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' `-AsmLabelAttr 0xc4b785358 <<invalid sloc>> Implicit "_Z4funcIiEvT_" Dumping func<int>: FunctionDecl 0xc4b7850b8 <<invalid sloc>> <invalid sloc> func<int> 'void (int)' implicit_instantiation extern |-TemplateArgument type 'int' | `-BuiltinType 0xc4b85b110 'int' `-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' ``` The majority of this patch is adjust the `Dump` API. The main change in behaviour is in `TypeSystemClang::Dump`, where we now use the `ASTPrinter` for dumping the `TranslationUnitDecl`. This is where the `-ast-dump-filter` functionality lives in Clang.
2025-04-04[lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method (#133370)Jonas Devlieghere
Add ObjectFile::GetObjectName and SymbolFile::GetObjectName to retrieve the name of the object file, including the `.a` for static libraries. We currently do something similar in CommandObjectTarget, but the code for dumping this is a lot more involved than what's being offered by the new method. We have options to print he full path, the base name, and the directoy of the path and trim it to a specific width. This is motivated by #133211, where Greg pointed out that the old code would print the static archive (the .a file) rather than the actual object file inside of it.
2025-03-31[lldb] Create a default rate limit constant in Progress (NFC) (#133506)Jonas Devlieghere
In #133211, Greg suggested making the rate limit configurable through a setting. Although adding the setting is easy, the two places where we currently use rate limiting aren't tied to a particular debugger. Although it'd be possible to hook up, given how few progress events currently implement rate limiting, I don't think it's worth threading this through, if that's even possible. I still think it's a good idea to be consistent and make it easy to pick the same rate limiting value, so I've moved it into a constant in the Progress class.
2025-03-27[lldb] Emit progress events in SymbolFileDWARFDebugMap (#133211)Jonas Devlieghere
Emit progress events from SymbolFileDWARFDebugMap. Because we know the number of OSOs, we can show determinate progress. This is based on a patch from Adrian, and part of what prompted me to look into improving how LLDB shows progress events. Before the statusline, all these progress events would get shadowed and never displayed on the command line.
2025-01-10[lldb] Add Function::GetAddress and redirect some uses (#115836)Pavel Labath
Many calls to Function::GetAddressRange() were not interested in the range itself. Instead they wanted to find the address of the function (its entry point) or the base address for relocation of function-scoped entities (technically, the two don't need to be the same, but there's isn't good reason for them not to be). This PR creates a separate function for retrieving this, and changes the existing (non-controversial) uses to call that instead.
2024-12-17[lldb][DWARF] Remove obsolete calls to ↵Michael Buch
Supports_DW_AT_APPLE_objc_complete_type and DW_AT_decl_file_attributes_are_invalid (#120226) Depends on https://github.com/llvm/llvm-project/pull/120225 With `llvm-gcc` support being removed from LLDB, these APIs are now trivial and can be removed too.
2024-09-05[lldb] Make deep copies of Status explicit (NFC) (#107170)Adrian Prantl
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2024-06-25[lldb/DWARF] Remove parsing recursion when searching for definition DIEs ↵Pavel Labath
(#96484) If ParseStructureLikeDIE (or ParseEnum) encountered a declaration DIE, it would call FindDefinitionTypeForDIE. This returned a fully formed type, which it achieved by recursing back into ParseStructureLikeDIE with the definition DIE. This obscured the control flow and caused us to repeat some work (e.g. the UniqueDWARFASTTypeMap lookup), but it mostly worked until we tried to delay the definition search in #90663. After this patch, the two ParseStructureLikeDIE calls were no longer recursive, but rather the second call happened as a part of the CompleteType() call. This opened the door to inconsistencies, as the second ParseStructureLikeDIE call was not aware it was called to process a definition die for an existing type. To make that possible, this patch removes the recusive type resolution from this function, and leaves just the "find definition die" functionality. After finding the definition DIE, we just go back to the original ParseStructureLikeDIE call, and have it finish the parsing process with the new DIE. While this patch is motivated by the work on delaying the definition searching, I believe it is also useful on its own.
2024-04-18Check for null oso SymbolFile in ↵jimingham
SymbolFileDwarfDebugMap::ResolveSymbolContext (#89324) The couple other places that use the oso module's SymbolFile, they check that it's non-null, so this is just an oversight in ResolveSymbolContext. I didn't add a test for this (but did add a log message for the error case) because I can't see how this would actually happen. The .o file had to have valid enough DWARF that the linker's parser could handle it or it would not be in the debug map. If you delete the .o file, we just leave that entry out of the debug map. If you strip it or otherwise mess with it, we'll notice the changed mod time and refuse to read it... This was based on a report from the field, and we don't have access to the project. But if the logging tells me how this happened I can come back and add a test with that example.
2024-04-03[lldb][SymbolFileDWARFDebugMap] Introduce enum to indicate whether to ↵Michael Buch
continue iteration of object files (#87344) This patch introduces a new `IterationMarker` enum (happy to take alternative name suggestions), which callbacks, like the one in `SymbolFileDWARFDebugMap::ForEachSymbolFile`, can return in order to indicate whether the caller should continue iterating or bail. For now this patch just changes the `ForEachSymbolFile` callback to use this new enum. In the future we could change the various `DWARFIndex::GetXXX` callbacks to do the same. This makes the callbacks easier to read and hopefully reduces the chance of bugs like https://github.com/llvm/llvm-project/pull/87177.
2024-03-31[lldb] Fix type lookup in DWARF .o files via debug map (#87177)Pablo Busse
An inverted condition causes `SymbolFileDWARFDebugMap::FindTypes` to bail out after inspecting the first .o file in each module. The same kind of bug is found in `SymbolFileDWARFDebugMap::ParseDeclsForContext`. Correct both early exit conditions and add a regression test for lookup of up a type defined in a secondary compilation unit. Fixes #87176
2024-01-16[lldb] Store SupportFile in CompileUnit (NFC)Jonas Devlieghere
Store a SupportFile, rather than a FileSpec, in CompileUnit. This commit works towards having the SourceManager operate on SupportFiles so that it can (1) validate the Checksum and (2) materialize the content of inline source information.
2024-01-04Add support for inline DWARF source files. (#75880)Adrian Prantl
LLVM supports DWARF 5 linetable extension to store source files inline in DWARF. This is particularly useful for compiler-generated source code. This implementation tries to materialize them as temporary files lazily, so SBAPI clients don't need to be aware of them. rdar://110926168
2023-12-12[lldb] Make only one function that needs to be implemented when searching ↵Greg Clayton
for types (#74786) This patch revives the effort to get this Phabricator patch into upstream: https://reviews.llvm.org/D137900 This patch was accepted before in Phabricator but I found some -gsimple-template-names issues that are fixed in this patch. A fixed up version of the description from the original patch starts now. This patch started off trying to fix Module::FindFirstType() as it sometimes didn't work. The issue was the SymbolFile plug-ins didn't do any filtering of the matching types they produced, and they only looked up types using the type basename. This means if you have two types with the same basename, your type lookup can fail when only looking up a single type. We would ask the Module::FindFirstType to lookup "Foo::Bar" and it would ask the symbol file to find only 1 type matching the basename "Bar", and then we would filter out any matches that didn't match "Foo::Bar". So if the SymbolFile found "Foo::Bar" first, then it would work, but if it found "Baz::Bar" first, it would return only that type and it would be filtered out. Discovering this issue lead me to think of the patch Alex Langford did a few months ago that was done for finding functions, where he allowed SymbolFile objects to make sure something fully matched before parsing the debug information into an AST type and other LLDB types. So this patch aimed to allow type lookups to also be much more efficient. As LLDB has been developed over the years, we added more ways to to type lookups. These functions have lots of arguments. This patch aims to make one API that needs to be implemented that serves all previous lookups: - Find a single type - Find all types - Find types in a namespace This patch introduces a `TypeQuery` class that contains all of the state needed to perform the lookup which is powerful enough to perform all of the type searches that used to be in our API. It contain a vector of CompilerContext objects that can fully or partially specify the lookup that needs to take place. If you just want to lookup all types with a matching basename, regardless of the containing context, you can specify just a single CompilerContext entry that has a name and a CompilerContextKind mask of CompilerContextKind::AnyType. Or you can fully specify the exact context to use when doing lookups like: CompilerContextKind::Namespace "std" CompilerContextKind::Class "foo" CompilerContextKind::Typedef "size_type" This change expands on the clang modules code that already used a vector<CompilerContext> items, but it modifies it to work with expression type lookups which have contexts, or user lookups where users query for types. The clang modules type lookup is still an option that can be enabled on the `TypeQuery` objects. This mirrors the most recent addition of type lookups that took a vector<CompilerContext> that allowed lookups to happen for the expression parser in certain places. Prior to this we had the following APIs in Module: ``` void Module::FindTypes(ConstString type_name, bool exact_match, size_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeList &types); void Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, TypeMap &types); void Module::FindTypesInNamespace(ConstString type_name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, TypeList &type_list); ``` The new Module API is much simpler. It gets rid of all three above functions and replaces them with: ``` void FindTypes(const TypeQuery &query, TypeResults &results); ``` The `TypeQuery` class contains all of the needed settings: - The vector<CompilerContext> that allow efficient lookups in the symbol file classes since they can look at basename matches only realize fully matching types. Before this any basename that matched was fully realized only to be removed later by code outside of the SymbolFile layer which could cause many types to be realized when they didn't need to. - If the lookup is exact or not. If not exact, then the compiler context must match the bottom most items that match the compiler context, otherwise it must match exactly - If the compiler context match is for clang modules or not. Clang modules matches include a Module compiler context kind that allows types to be matched only from certain modules and these matches are not needed when d oing user type lookups. - An optional list of languages to use to limit the search to only certain languages The `TypeResults` object contains all state required to do the lookup and store the results: - The max number of matches - The set of SymbolFile objects that have already been searched - The matching type list for any matches that are found The benefits of this approach are: - Simpler API, and only one API to implement in SymbolFile classes - Replaces the FindTypesInNamespace that used a CompilerDeclContext as a way to limit the search, but this only worked if the TypeSystem matched the current symbol file's type system, so you couldn't use it to lookup a type in another module - Fixes a serious bug in our FindFirstType functions where if we were searching for "foo::bar", and we found a "baz::bar" first, the basename would match and we would only fetch 1 type using the basename, only to drop it from the matching list and returning no results
2023-11-02[lldb][split-dwarf] Add --errors-only argument separate-debug-info list (#71000)Tom Yang
Often, we only care about the split-dwarf files that have failed to load. This can be useful when diagnosing binaries with many separate debug info files where only some have errors. ``` (lldb) help image dump separate-debug-info List the separate debug info symbol files for one or more target modules. Syntax: target modules dump separate-debug-info <cmd-options> [<filename> [<filename> [...]]] Command Options Usage: target modules dump separate-debug-info [-ej] [<filename> [<filename> [...]]] -e ( --errors-only ) Filter to show only debug info files with errors. -j ( --json ) Output the details in JSON format. This command takes options and free-form arguments. If your arguments resemble option specifiers (i.e., they start with a - or --), you must use ' -- ' between the end of the command options and the beginning of the arguments. 'image' is an abbreviation for 'target modules' ``` I updated the following tests ``` # on Linux bin/lldb-dotest -p TestDumpDwo # on Mac bin/lldb-dotest -p TestDumpOso ``` This change applies to both the table and JSON outputs. --------- Co-authored-by: Tom Yang <toyang@fb.com>
2023-10-25[LLDB][NFC] Remove DWARFASTParserClang as friend from SymbolFileDWARF (#70157)Walter Erquinigo
This effectively moves a few functions from protected to public. In any case, for the sake of having a cleaner SymbolFileDWARF API, it's better if it's not a friend of a one of its consumers, DWARFASTParserClang. Another effect of this change is that I can use SymbolFileDWARF for the out-of-tree mojo dwarf parser, which relies on pretty much the same functions that DWARFASTParserClang needs from SymbolFileDWARF.
2023-10-24Expose DWARFDIE::GetDeclContext() in lldb_private::Function. (#69981)Adrian Prantl
I need this API in the Swift plugin, but it seems generally useful enough to expose it in the main branch.
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-12Add `target modules dump separate-debug-info` (#66035)Tom Yang
Add a new command ``` target modules dump separate-debug-info [-j] [<filename> [<filename> [...]]] ``` or ``` image dump separate-debug-info [-j] [<filename> [<filename> [...]]] ``` (since `image` is an alias for `target modules`). This lists the separate debug info files and their current status (loaded or not loaded) for the specified modules. This diff implements this command for mach-O files with OSO and ELF files with dwo. Example dwo: ``` (lldb) image dump separate-debug-info Symbol file: /home/toyang/workspace/dwo-scratch/a.out Type: "dwo" Dwo ID Err Dwo Path ------------------ --- ----------------------------------------- 0x9a429da5abb6faae /home/toyang/workspace/scratch-dwo/a-main.dwo 0xbcc129959e76ff33 /home/toyang/workspace/scratch-dwo/a-foo.dwo (lldb) image dump separate-debug-info -j [ { "separate-debug-info-files": [ { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 11115620165179865774, "dwo_name": "a-main.dwo", "loaded": true, "resolved_dwo_path": "/home/toyang/workspace/dwo-scratch/a-main.dwo" }, { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 13601198072221073203, "dwo_name": "a-foo.dwo", "loaded": true, "resolved_dwo_path": "/home/toyang/workspace/dwo-scratch/a-foo.dwo" } ], "symfile": "/home/toyang/workspace/dwo-scratch/a.out", "type": "dwo" } ] ``` Example dwo with missing dwo: ``` (lldb) image dump separate-debug-info Symbol file: /home/toyang/workspace/dwo-scratch/a.out Type: "dwo" Dwo ID Err Dwo Path ------------------ --- ----------------------------------------- 0x9a429da5abb6faae E unable to locate .dwo debug file "/home/toyang/workspace/scratch-dwo/b.out-main.dwo" for skeleton DIE 0x0000000000000014 0xbcc129959e76ff33 E unable to locate .dwo debug file "/home/toyang/workspace/scratch-dwo/b.out-foo.dwo" for skeleton DIE 0x000000000000003c (lldb) image dump separate-debug-info -j [ { "separate-debug-info-files": [ { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 11115620165179865774, "dwo_name": "a-main.dwo", "error": "unable to locate .dwo debug file \"/home/toyang/workspace/dwo-scratch/a-main.dwo\" for skeleton DIE 0x0000000000000014", "loaded": false }, { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 13601198072221073203, "dwo_name": "a-foo.dwo", "error": "unable to locate .dwo debug file \"/home/toyang/workspace/dwo-scratch/a-foo.dwo\" for skeleton DIE 0x000000000000003c", "loaded": false } ], "symfile": "/home/toyang/workspace/dwo-scratch/a.out", "type": "dwo" } ] ``` Example output with dwp: ``` (lldb) image dump separate-debug-info Symbol file: /home/toyang/workspace/dwo-scratch/a.out Type: "dwo" Dwo ID Err Dwo Path ------------------ --- ----------------------------------------- 0x9a429da5abb6faae /home/toyang/workspace/dwo-scratch/a.out.dwp(a-main.dwo) 0xbcc129959e76ff33 /home/toyang/workspace/dwo-scratch/a.out.dwp(a-foo.dwo) (lldb) image dump separate-debug-info -j [ { "separate-debug-info-files": [ { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 11115620165179865774, "dwo_name": "a-main.dwo", "loaded": true, "resolved_dwo_path": "/home/toyang/workspace/dwo-scratch/a.out.dwp" }, { "comp_dir": "/home/toyang/workspace/dwo-scratch", "dwo_id": 13601198072221073203, "dwo_name": "a-foo.dwo", "loaded": true, "resolved_dwo_path": "/home/toyang/workspace/dwo-scratch/a.out.dwp" } ], "symfile": "/home/toyang/workspace/dwo-scratch/a.out", "type": "dwo" } ] ``` Example oso on my Mac: ``` (lldb) image dump separate-debug-info Symbol file: /Users/toyang/workspace/scratch/a.out Type: "oso" Mod Time Err Oso Path ------------------ --- --------------------- 0x0000000064e64868 /Users/toyang/workspace/scratch/foo.a(foo.o) 0x0000000064e64868 /Users/toyang/workspace/scratch/foo.a(main.o) (lldb) image dump separate-debug-info -j [ { "separate-debug-info-files": [ { "loaded": true, "oso_mod_time": 1692813416, "oso_path": "/Users/toyang/workspace/scratch/foo.a(foo.o)", "so_file": "/Users/toyang/workspace/scratch/foo.cpp" }, { "loaded": true, "oso_mod_time": 1692813416, "oso_path": "/Users/toyang/workspace/scratch/foo.a(main.o)", "so_file": "/Users/toyang/workspace/scratch/main.cpp" } ], "symfile": "/Users/toyang/workspace/scratch/a.out", "type": "oso" } ] ``` Test Plan: Tested on Mac OS and Linux. ``` lldb-dotest -p TestDumpDwo lldb-dotest -p TestDumpOso ``` --------- Co-authored-by: Tom Yang <toyang@fb.com>
2023-08-17[lldb][NFCI] Module constructor should take ConstString by valueAlex Langford
ConstStrings are super cheap to copy around. It is often more expensive to pass a pointer and potentially dereference it than just to always copy it. Differential Revision: https://reviews.llvm.org/D158043
2023-08-09[lldb] Sink StreamFile into lldbHostAlex Langford
StreamFile subclasses Stream (from lldbUtility) and is backed by a File (from lldbHost). It does not depend on anything from lldbCore or any of its sibling libraries, so I think it makes sense for this to live in lldbHost instead. Differential Revision: https://reviews.llvm.org/D157460
2023-07-06[lldb][NFC] Remove code duplication in InitOSOFelipe de Azevedo Piovezan
Two identical loops were iterating over different ranges, leading to code duplication. We replace this by a loop over the concatenation of the ranges. We also use early returns to avoid deeply nested code and explicitly check for a condition mentioned in comments. Differential Revision: https://reviews.llvm.org/D154505
2023-07-03[lldb][nfc] Remove redundant nullptr checkFelipe de Azevedo Piovezan
The make_shared function never returns a nullptr, as such the test for nullptr is not needed. We also move the empty string check earlier in the if ("oso_object"), as this is cheaper than loading the object file. Differential Revision: https://reviews.llvm.org/D154365
2023-04-14[lldb][ClangExpression] Filter out non-root namespaces in FindNamespaceMichael Buch
**Summary** In a program such as: ``` namespace A { namespace B { struct Bar {}; } } namespace B { struct Foo {}; } ``` ...LLDB would run into issues such as: ``` (lldb) expr ::B::Foo f error: expression failed to parse: error: <user expression 0>:1:6: no type named 'Foo' in namespace 'A::B' ::B::Foo f ~~~~~^ ``` This is because the `SymbolFileDWARF::FindNamespace` implementation will return *any* namespace it finds if the `parent_decl_ctx` provided is empty. In `FindExternalVisibleDecls` we use this API to find the namespace that symbol `B` refers to. If `A::B` happened to be the one that `SymbolFileDWARF::FindNamespace` looked at first, we would try to find `struct Foo` in `A::B`. Hence the error. This patch proposes a new `SymbolFileDWARF::FindNamespace` API that will only find a match for top-level namespaces, which is what `FindExternalVisibleDecls` is attempting anyway; it just never accounted for multiple namespaces of the same name. **Testing** * Added API test-case Differential Revision: https://reviews.llvm.org/D147436
2023-04-10[lldb] Implement SymbolFile::GetCompileOptionsAugusto Noronha
Implement SymbolFile::GetCompileOptions, which returns a map from compilation units to compilation arguments associated with that unit. Differential Revision: https://reviews.llvm.org/D147748
2023-03-18[lldb] Introduce SymbolFile::ParseAllLanguagesAugusto Noronha
SymbolFile::ParseAllLanguages allows collecting the languages of the extra compile units a SymbolFileDWARFDebugMap may have, which can't be accessed otherwise. For every other symbol file type, it should behave exactly the same as ParseLanguage. rdar://97610458 Differential Revision: https://reviews.llvm.org/D146265
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-19Revert "[lldb] Remove redundant .c_str() and .get() calls"Muhammad Omair Javaid
This reverts commit fbaf48be0ff6fb24b9aa8fe9c2284fe88a8798dd. This has broken all LLDB buildbots: https://lab.llvm.org/buildbot/#/builders/68/builds/44990 https://lab.llvm.org/buildbot/#/builders/96/builds/33160
2022-12-18[lldb] Remove redundant .c_str() and .get() callsFangrui Song
Removing .c_str() has a semantics difference, but the use scenarios likely do not matter as we don't have NUL in the strings.
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-11-30[lldb] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIEArthur Eubanks
This simplifies an upcoming patch. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138612
2022-11-25Revert "[lldb][NFC] Change FindDefinitionTypeForDWARFDeclContext() to take ↵Jason Molenda
DWARFDIE" The changes in https://reviews.llvm.org/D138612 cause a testsuite failure on Darwin systems in TestCPPAccelerator.py, first flagged by the "LLDB Incremental" CI bot. https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/ with the specific failure text appended to the phabracator. This reverts commit c3c423b6cb2e1c00483e951ce8cc4d935e31cd14.
2022-11-24[lldb][NFC] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIEArthur Eubanks
This simplifies an upcoming patch. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138612
2022-10-19[lldb] Allow SymbolFileDWARFDebugMap to register multiple compile unitsAugusto Noronha
Currently, SymbolFileDWARFDebugMap works on the assumption that there is only one compile unit per object file. This patch documents this limitation (when using the general SymbolFile API), and allows users of the concrete SymbolFileDWARFDebugMap class to find out about these extra compile units. Differential Revision: https://reviews.llvm.org/D136114
2022-09-28Track which modules have debug info variable errors.Greg Clayton
Now that we display an error when users try to get variables, but something in the debug info is preventing variables from showing up, track this with a new bool in each module's statistic information named "debugInfoHadVariableErrors". This patch modifies the code to track when we have variable errors in a module and adds accessors to get/set this value. This value is used in the module statistics and we added a test to verify this value gets set correctly. Differential Revision: https://reviews.llvm.org/D134508
2022-09-12Add the ability to show when variables fails to be available when debug info ↵Greg Clayton
is valid. Summary: Many times when debugging variables might not be available even though a user can successfully set breakpoints and stops somewhere. Letting the user know will help users fix these kinds of issues and have a better debugging experience. Examples of this include: - enabling -gline-tables-only and being able to set file and line breakpoints and yet see no variables - unable to open object file for DWARF in .o file debugging for darwin targets due to modification time mismatch or not being able to locate the N_OSO file. This patch adds an new API to SBValueList: lldb::SBError lldb::SBValueList::GetError(); object so that if you request a stack frame's variables using SBValueList SBFrame::GetVariables(...), you can get an error the describes why the variables were not available. This patch adds the ability to get an error back when requesting variables from a lldb_private::StackFrame when calling GetVariableList. It also now shows an error in response to "frame variable" if we have debug info and are unable to get varialbes due to an error as mentioned above: (lldb) frame variable error: "a.o" object from the "/tmp/libfoo.a" archive: either the .o file doesn't exist in the archive or the modification time (0x63111541) of the .o file doesn't match Reviewers: labath JDevlieghere aadsm yinghuitan jdoerfert sscalpone Subscribers: Differential Revision: https://reviews.llvm.org/D133164