aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
AgeCommit message (Collapse)AuthorFilesLines
7 daysModify ObjectFileELF so it can load notes from PT_NOTE segments. (#160652)Greg Clayton1-0/+18
The ObjectFileELF parser was not able to load ELF notes from PT_NOTE program headers. This patch fixes ObjectFileELF::GetUUID() to check the program header and parse the notes in any PT_NOTE segments. This will allow memory ELF files to extract the UUID from an in memory image that has no section headers. Added a test that creates an ELF file, strips all section headers, and then makes sure that LLDB can see the UUID value.
2025-08-27[LLDB] Omit loading local symbols in LLDB symbol table (#154809)barsolo20001-1/+40
https://discourse.llvm.org/t/rfc-should-we-omit-local-symbols-in-eekciihgtfvflvnbieicunjlrtnufhuelf-files-from-the-lldb-symbol-table/87384 Improving symbolication by excluding local symbols that are typically not useful for debugging or symbol lookups. This aligns with the discussion that local symbols, especially those with STB_LOCAL binding and STT_NOTYPE type (including .L-prefixed symbols), often interfere with symbol resolution and can be safely omitted. --------- Co-authored-by: Bar Soloveychik <barsolo@fb.com>
2025-06-09[LLDB] Unify DWARF section name matching (#141344)nerix1-33/+3
Different object file formats support DWARF sections (COFF, ELF, MachO, PE/COFF, WASM). COFF and PE/COFF only matched a subset. This caused some GCC executables produced on MinGW to have issue later on when debugging. One example is that `.debug_rnglists` was not matched, which caused range-extraction to fail when printing a backtrace. This unifies the parsing of section names in `ObjectFile::GetDWARFSectionTypeFromName`, so all file formats can use the same naming convention. Since the prefixes are different, `GetDWARFSectionTypeFromName` only matches the suffixes (i.e. `.debug_` needs to be stripped before). I added two tests to ensure the sections are correctly identified on Windows executables.
2025-01-14[lldb][NFC] Make the target's SectionLoadList private. (#113278)Greg Clayton1-2/+1
Lots of code around LLDB was directly accessing the target's section load list. This NFC patch makes the section load list private so the Target class can access it, but everyone else now uses accessor functions. This allows us to control the resolving of addresses and will allow for functionality in LLDB which can lazily resolve addresses in JIT plug-ins with a future patch.
2025-01-10[lldb] Migrate away from PointerUnion::{is,get} (NFC) (#122420)Kazu Hirata1-29/+29
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-12-10Reland: [lldb] Implement a formatter bytecode interpreter in C++Adrian Prantl1-0/+1
Compared to the python version, this also does type checking and error handling, so it's slightly longer, however, it's still comfortably under 500 lines. Relanding with more explicit type conversions.
2024-12-11Revert "[lldb] Add cast to fix compile error on 32-bit platforms"Sylvestre Ledru1-1/+0
This reverts commit f6012a209dca6b1866d00e6b4f96279469884320. Revert "[lldb] Add cast to fix compile error on 32-but platforms" This reverts commit d300337e93da4ed96b044557e4b0a30001967cf0. Revert "[lldb] Improve log message to include missing strings" This reverts commit 0be33484853557bc0fd9dfb94e0b6c15dda136ce. Revert "[lldb] Add comment" This reverts commit e2bb47443d2e5c022c7851dd6029e3869fc8835c. Revert "[lldb] Implement a formatter bytecode interpreter in C++" This reverts commit 9a9c1d4a6155a96ce9be494cec7e25731d36b33e.
2024-12-10[lldb] Implement a formatter bytecode interpreter in C++Adrian Prantl1-0/+1
Compared to the python version, this also does type checking and error handling, so it's slightly longer, however, it's still comfortably under 500 lines.
2024-12-10[lldb] Load embedded type summary section (#7859) (#8040)Dave Lee1-0/+1
Add support for type summaries embedded into the binary. These embedded summaries will typically be generated by Swift macros, but can also be generated by any other means. rdar://115184658
2024-11-18Add support for reading the dynamic symbol table from PT_DYNAMIC (#116689)Greg Clayton1-20/+160
Resubmissions of https://github.com/llvm/llvm-project/pull/112596 with buildbot fixes. Allow LLDB to parse the dynamic symbol table from an ELF file or memory image in an ELF file that has no section headers. This patch uses the ability to parse the PT_DYNAMIC segment and find the DT_SYMTAB, DT_SYMENT, DT_HASH or DT_GNU_HASH to find and parse the dynamic symbol table if the section headers are not present. It also adds a helper function to read data from a .dynamic key/value pair entry correctly from the file or from memory.
2024-11-18Revert "Add support for reading the dynamic symbol table from PT_DYNAMIC ↵Shubham Sandeep Rastogi1-161/+21
(#112596)" This reverts commit a7b2e73bcaa91255a20f1f2e692bec9eb6c17022. This patch broke the greendragon bot Failed Tests (10): lldb-api :: python_api/sbplatform/TestLocateModuleCallback.py lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleCallbackSuccessWithModuleAndSymbol lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleCallbackSuccessWithOnlySymbol lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleCallbackSuccessWithSymbolAsModule lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleCallbackSuccessWithSymbolAsModuleAndSymbol lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleCallbackSuccessWithSymbolByPlatformUUID lldb-unit :: Target/./TargetTests/LocateModuleCallbackTest/GetOrCreateModuleWithCachedModuleAndSymbol lldb-unit :: Target/./TargetTests/ModuleCacheTest/GetAndPut lldb-unit :: Target/./TargetTests/ModuleCacheTest/GetAndPutStrangeHostname lldb-unit :: Target/./TargetTests/ModuleCacheTest/GetAndPutUuidExists
2024-11-18Add support for reading the dynamic symbol table from PT_DYNAMIC (#112596)Greg Clayton1-21/+161
Allow LLDB to parse the dynamic symbol table from an ELF file or memory image in an ELF file that has no section headers. This patch uses the ability to parse the PT_DYNAMIC segment and find the DT_SYMTAB, DT_SYMENT, DT_HASH or DT_GNU_HASH to find and parse the dynamic symbol table if the section headers are not present. It also adds a helper function to read data from a .dynamic key/value pair entry correctly from the file or from memory.
2024-11-08[lldb][LoongArch] Function calls support in lldb expressionswanglei1-0/+17
This patch adds desired feature flags in JIT compiler to enable hard-float instructions if target supports them and allows to use floats and doubles in lldb expressions. Fited tests: lldb-shell :: Expr/TestAnonNamespaceParamFunc.cpp lldb-shell :: Expr/TestIRMemoryMap.test lldb-shell :: Expr/TestStringLiteralExpr.test lldb-shell :: SymbolFile/DWARF/debug-types-expressions.test Similar as #99336 Depens on: https://github.com/llvm/llvm-project/pull/114741 Reviewed By: SixWeining Pull Request: https://github.com/llvm/llvm-project/pull/114742
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl1-8/+13
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-08-12 [LLDB] Impove ObjectFileELF's .dynamic parsing and usage. (#102570)Greg Clayton1-120/+306
This patch improves the ability of a ObjectFileELF instance to read the .dynamic section. It adds the ability to read the .dynamic section from the PT_DYNAMIC program header which is useful for ELF files that have no section headers and for ELF files that are read from memory. It cleans up the usage of the .dynamic entries so that ObjectFileELF::ParseDynamicSymbols() is the only code that parses .dynamic entries, teaches that function the read and store the string values for each .dynamic entry. We now dump the .dynamic entries in the output of "image dump objfile". It also cleans up the code that gets the dynamic string table so that it can grab it from the DT_STRTAB and DT_STRSZ .dynamic entries for when we have a ELF file with no section headers or we are reading it from memory.
2024-08-08Revert "[LLDB] Impove ObjectFileELF's .dynamic parsing and usage. (#101237)"Leonard Chan1-302/+120
This reverts commit 28ba8a56b6fb9ec61897fa84369f46e43be94c03. Reverting since this broke the buildbot at https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/9352/.
2024-08-08[LLDB] Impove ObjectFileELF's .dynamic parsing and usage. (#101237)Greg Clayton1-120/+302
This patch improves the ability of a ObjectFileELF instance to read the .dynamic section. It adds the ability to read the .dynamic section from the PT_DYNAMIC program header which is useful for ELF files that have no section headers and for ELF files that are read from memory. It cleans up the usage of the .dynamic entries so that ObjectFileELF::ParseDynamicSymbols() is the only code that parses .dynamic entries, teaches that function the read and store the string values for each .dynamic entry. We now dump the .dynamic entries in the output of "image dump objfile". It also cleans up the code that gets the dynamic string table so that it can grab it from the DT_STRTAB and DT_STRSZ .dynamic entries for when we have a ELF file with no section headers or we are reading it from memory.
2024-07-19[lldb] SHT_NOBITS sections type (#99044)dlav-sc1-1/+4
.sbss section was recognized as eSectionTypeOther, but has to be eSectionTypeZeroFill. Fixed tests for RISCV target: TestClassLoadingViaMemberTypedef.TestCase TestClassTemplateNonTypeParameterPack.TestCaseClassTemplateNonTypeParameterPack TestThreadSelectionBug.TestThreadSelectionBug lldbsuite.test.lldbtest.TestOffsetof lldbsuite.test.lldbtest.TestOffsetofCpp TestTargetDumpTypeSystem.TestCase TestCPP11EnumTypes.CPP11EnumTypesTestCase TestCppIsTypeComplete.TestCase TestExprCrash.ExprCrashTestCase TestDebugIndexCache.DebugIndexCacheTestcase
2024-07-11[lldb] Fix a bug for PT_TLS segments getting loaded when they shouldn't. ↵Greg Clayton1-0/+14
(#98432) PT_LOAD and PT_TLS segments are top level sections in the ObjectFileELF section list. The two segments can often have the same program header p_vaddr and p_paddr values and this can cause section load list issues in LLDB if we load the PT_TLS segments. What happens is the SectionLoadList::m_addr_to_sect, when a library is loaded, will first map one of the sections named "PT_LOAD[0]" with the load address that matches the p_vaddr entry from the program header. Then the "PT_TLS[0]" would come along and try to load this section at the same address. This would cause the "PT_LOAD[0]" section to be unloaded as the SectionLoadList::m_addr_to_sect would replace the value for the matching p_vaddr with the last section to be seen. The sizes of the PT_TLS and PT_LOAD that have the same p_vaddr value don't need to have the same byte size, so this could cause lookups to fail for an addresses in the "PT_LOAD[0]" section or any of its children if the offset is greater than the offset size of the PT_TLS segment. It could also cause us to incorrectly attribute addresses from the "PT_LOAD[0]" to the "PT_TLS[0]" segment when doing lookups for offset that are less than the size of the PT_TLS segment. This fix stops us from loading PT_TLS segments in the section load lists and will prevent the bugs that resulted from this. No addresses the the DWARF refer to TLS data with a "file address" in any way. They all have TLS DWARF location expressions to locate these variables. We also don't have any support for having actual thread specific sections and having those sections resolve to something different for each thread, so there currently is no point in loading thread specific sections. Both the ObjectFileMachO and ObjectFileCOFF both ignore thread specific sections at the moment, so this brings the ObjectFileELF to parity with those plug-ins. I added a test into an existing test to verify that things work as expected. Prior to this fix with a real binary, the output of "target dump section-load-list" would look like this for the old LLDB: ``` // (lldb) target dump section-load-list // addr = 0x0000000000000000, section = 0x55d46ab8c510: 0xfffffffffffffffd container [0x0000000000000000-0x0000000000000628) r-- 0x00000000 0x00000628 0x00000000 a.out.PT_LOAD[0] // addr = 0x0000000000001000, section = 0x55d46ab8b0c0: 0xfffffffffffffffc container [0x0000000000001000-0x0000000000001185) r-x 0x00001000 0x00000185 0x00000000 a.out.PT_LOAD[1] // addr = 0x0000000000002000, section = 0x55d46ac040f0: 0xfffffffffffffffb container [0x0000000000002000-0x00000000000020cc) r-- 0x00002000 0x000000cc 0x00000000 a.out.PT_LOAD[2] // addr = 0x0000000000003db0, section = 0x55d46ab7cef0: 0xfffffffffffffff6 container [0x0000000000003db0-0x0000000000003db4) r-- 0x00002db0 0x00000000 0x00000000 a.out.PT_TLS[0] ``` And this for the fixed LLDB: ``` // (lldb) target dump section-load-list // addr = 0x0000000000000000, section = 0x105f0a9a8: 0xfffffffffffffffd container [0x0000000000000000-0x0000000000000628) r-- 0x00000000 0x00000628 0x00000000 a.out.PT_LOAD[0] // addr = 0x0000000000001000, section = 0x105f0adb8: 0xfffffffffffffffc container [0x0000000000001000-0x0000000000001185) r-x 0x00001000 0x00000185 0x00000000 a.out.PT_LOAD[1] // addr = 0x0000000000002000, section = 0x105f0af48: 0xfffffffffffffffb container [0x0000000000002000-0x00000000000020cc) r-- 0x00002000 0x000000cc 0x00000000 a.out.PT_LOAD[2] // addr = 0x0000000000003db0, section = 0x105f0b078: 0xfffffffffffffffa container [0x0000000000003db0-0x0000000000004028) rw- 0x00002db0 0x00000274 0x00000000 a.out.PT_LOAD[3] ``` We can see that previously the "PT_LOAD[3]" segment would be removed from the section load list, and after the fix it remains and there is on PT_TLS in the loaded sections.
2024-05-16[lldb] Use operator==(StringRef, StringRef) instead of StringRef::equals ↵Kazu Hirata1-1/+1
(NFC) (#92476) Note that StringRef::equals has been deprecated in favor of operator==(StringRef, StringRef).
2024-05-10[lldb][ELF] Return address class map changes from symbol table parsing ↵David Spickett1-28/+49
methods (#91585) Instead of updating the member of the ObjectFileELF instance. This means that if one object file asks another to parse the symbol table, that first object's can update its address class map with the same changes that the other object did. (I'm not returning a reference to the other object's m_address_class_map member because there may be other things in there not related to the symbol table being parsed) This will fix the code added in https://github.com/llvm/llvm-project/pull/90622 which broke the test `Expr/TestStringLiteralExpr.test` on 32 bit Arm Linux. This happened because we had the program file, then asked for a better object file, which returned the same program file again. This creates a second ObjectFileELF for the same file, so when we tell the second instance to parse the symbol table it actually calls into the first instance, leaving the address class map of the second instance empty. Which caused us to put an Arm breakpoint instuction at a Thumb return address and broke the ability to call mmap.
2024-05-07[lldb] fix step in AArch64 trampoline (#90783)Vincent Belliard1-1/+18
Detects AArch64 trampolines in order to be able to step in a function through a trampoline on AArch64. --------- Co-authored-by: Vincent Belliard <v-bulle@github.com>
2024-05-01[LLDB][ELF] Fix section unification to not just use names. (#90099)Alastair Houghton1-12/+47
Section unification cannot just use names, because it's valid for ELF binaries to have multiple sections with the same name. We should check other section properties too. Fixes #88001. rdar://124467787
2024-01-16[lldb][Progress] Separate title and details (#77547)Chelsea Cassanova1-3/+2
Per this RFC: https://discourse.llvm.org/t/rfc-improve-lldb-progress-reporting/75717 on improving progress reports, this commit separates the title field and details field so that the title specifies the category that the progress report falls under. The details field is added as a part of the constructor for progress reports and by default is an empty string. In addition, changes the total amount of progress completed into a std::optional. Also updates the test to check for details being correctly reported from the event structured data dictionary.
2023-10-03[lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (#67106)aokblast1-5/+38
The implemtation support parsing kernel module for FreeBSD Kernel and has been test on x86-64 and arm64. In summary, this class parse the linked list resides in the kernel memory that record all kernel module and load the debug symbol file to facilitate debug process
2023-08-31[lldb] Add support for recognizing swift ast sections in object filesAlex Langford1-0/+1
In Apple's downstream fork, there is support for understanding the swift AST sections in various binaries. Even though the lldb on llvm.org does not have support for debugging swift, I think it makes sense to move support for recognizing swift ast sections upstream. Differential Revision: https://reviews.llvm.org/D159142
2023-07-13[lldb] Support Compact C Type Format (CTF) sectionJonas Devlieghere1-0/+1
Teach LLDB about the ctf (Compact C Type Format) section. Differential revision: https://reviews.llvm.org/D154668
2023-06-20[lldb][ObjectFileELF] Set ModuleSpec file offset and sizeKazuki Sakamoto1-1/+13
In Android API level 23 and above, dynamic loader is able to load .so file directly from APK. https://android.googlesource.com/platform/bionic/+/master/ android-changes-for-ndk-developers.md# opening-shared-libraries-directly-from-an-apk ObjectFileELF::GetModuleSpecifications will load a .so file, which is page aligned and uncompressed, directly from a zip file. However it does not set the .so file offset and size to the ModuleSpec. Also crc32 calculation uses more data than the .so file size. Set the .so file offset and size to the ModuleSpec, and set the size to MapFileData length argument. For normal file, file_offset should be zero, and length should be the size of the file. Differential Revision: https://reviews.llvm.org/D152757
2023-05-04[lldb] Move Core/FileSpecList -> Utility/FileSpecList (NFC)Jonas Devlieghere1-1/+1
There's no reason for FileSpecList to live in lldb/Core while FileSpec lives in lldb/Utility. Move FileSpecList next to FileSpec.
2023-05-02[lldb] Remove FileSpec::GetLastPathComponentAlex Langford1-1/+1
As far as I can tell, this just computes the filename of the FileSpec, which is already conveniently stored in m_filename. We can use FileSpec::GetFilename() instead. Differential Revision: https://reviews.llvm.org/D149663
2023-04-29[lldb][ObjectFileELF] Support AArch32 in ApplyRelocationsStefan Gränitz1-0/+53
Allow the ObjectFileELF plugin to resolve R_ARM_ABS32 relocations from AArch32 object files. This fixes https://github.com/llvm/llvm-project/issues/61948 The existing architectures work with RELA-type relocation records that read addend from the relocation entry. REL-type relocations in AArch32 store addend in-place. The new function doesn't re-use ELFRelocation::RelocAddend32(), because the interface doesn't match: in addition to the relocation entry we need the actual target section memory. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D147642
2023-04-26[lldb] Change return type of FileSpec::GetFileNameExtensionAlex Langford1-1/+1
These don't really need to be in ConstStrings. It's nice that comparing ConstStrings is fast (just a pointer comparison) but the cost of creating the ConstString usually already includes the cost of doing a StringRef comparison anyway, so this is just extra work and extra memory consumption for basically no benefit. Differential Revision: https://reviews.llvm.org/D149300
2023-04-13[lldb][ObjectFileELF] Improve error output for unsupported arch/relocationsStefan Gränitz1-27/+39
ObjectFileELF::ApplyRelocations() considered all 32-bit input objects to be i386 and didn't provide good error messages for AArch32 objects. Please find an example in https://github.com/llvm/llvm-project/issues/61948 While we are here, let' improve the situation for unsupported architectures as well. I think we should report the error here too and not silently fail (or crash with assertions enabled). Reviewed By: SixWeining Differential Revision: https://reviews.llvm.org/D147627
2023-03-13[LLDB][ObjectFileELF] Correct the return type of Reloc{Offset,Addend}32Weining Lu1-4/+4
This is a follow up of D145550. I think Reloc{Type,Symbol}{32,64} can keep unchanged as they are not directly returning a field of the ELFRel[a] struct. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D145571
2023-03-13[LLDB][ObjectFileELF] Correct the return type of RelocOffset64 and RelocAddend64Weining Lu1-4/+4
According to `/usr/include/elf.h` and `lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h`. For ELF64 relocation, types of `offset` and `addend` should be `elf_addr` and `elf_sxword`. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D145550
2023-03-13[LLDB][ObjectFileELF] Support LoongArch64 in ApplyReloctionsWeining Lu1-44/+83
Currently ApplyReloctions() deals with different archs' relocation types together (in a single `switch() {..}`). I think it is incorrect because different relocation types of different archs may have same enum values. For example: `R_LARCH_32` and `R_X86_64_64` are both `1`; `R_LARCH_64` and `R_X86_64_PC32` are both `2`. This patch handles each arch in seperate `switch()` to solve the enum values conflict issue. And a new test is added for LoongArch64. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D145462
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille1-2/+2
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2023-01-09[LLDB] Change formatting to use llvm::formatvAlexander Yermolovich1-9/+8
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 Hirata1-3/+3
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04[lldb] Use std::nullopt instead of None (NFC)Kazu Hirata1-4/+4
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-01[LLDB][LoongArch] Add LoongArch ArchSpec and subtype detectionTiezhu Yang1-0/+14
Define LoongArch architecture subtypes, add the LoongArch ArchSpec bits, and inspect the ELF header to detect the right subtype based on ELF class. Here is a simple test: ``` [loongson@linux ~]$ cat hello.c int main() { printf("Hello, World!\n"); return 0; } [loongson@linux ~]$ clang hello.c -g -o hello ``` Without this patch: ``` [loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello (lldb) target create "hello" error: '/home/loongson/hello' doesn't contain any 'host' platform architectures: unknown ``` With this patch: ``` [loongson@linux ~]$ llvm-project/llvm/build/bin/lldb hello (lldb) target create "hello" Current executable set to '/home/loongson/hello' (loongarch64). (lldb) run Process 735167 launched: '/home/loongson/hello' (loongarch64) Hello, World! Process 735167 exited with status = 0 (0x00000000) (lldb) quit [loongson@linux ~]$ llvm-project/llvm/build/bin/llvm-lit llvm-project/lldb/test/Shell/ObjectFile/ELF/loongarch-arch.yaml llvm-lit: /home/loongson/llvm-project/llvm/utils/lit/lit/llvm/config.py:456: note: using clang: /home/loongson/llvm-project/llvm/build/bin/clang -- Testing: 1 tests, 1 workers -- PASS: lldb-shell :: ObjectFile/ELF/loongarch-arch.yaml (1 of 1) Testing Time: 0.09s Passed: 1 ``` Reviewed By: SixWeining, xen0n, DavidSpickett Differential Revision: https://reviews.llvm.org/D137057
2022-09-13lldb: Add support for R_386_32 relocations to ObjectFileELFDavid M. Lary1-11/+34
I encountered an issue where `p &variable` was finding an incorrect address for 32-bit PIC ELF files loaded into a running process. The problem was that the R_386_32 ELF relocations were not being applied to the DWARF section, so all variables in that file were reporting as being at the start of their respective section. There is an assert that catches this on debug builds, but silently ignores the issue on non-debug builds. In this changeset, I added handling for the R_386_32 relocation type to ObjectFileELF, and a supporting function to ELFRelocation to differentiate between DT_REL & DT_RELA in ObjectFileELF::ApplyRelocations(). Demonstration of issue: ``` [dmlary@host work]$ cat rel.c volatile char padding[32] = "make sure var isnt at .data+0"; volatile char var[] = "test"; [dmlary@host work]$ gcc -c rel.c -FPIC -fpic -g -m32 [dmlary@host work]$ lldb ./exec (lldb) target create "./exec" Current executable set to '/home/dmlary/src/work/exec' (i386). (lldb) process launch --stop-at-entry Process 21278 stopped * thread #1, name = 'exec', stop reason = signal SIGSTOP frame #0: 0xf7fdb150 ld-2.17.so`_start ld-2.17.so`_start: -> 0xf7fdb150 <+0>: movl %esp, %eax 0xf7fdb152 <+2>: calll 0xf7fdb990 ; _dl_start ld-2.17.so`_dl_start_user: 0xf7fdb157 <+0>: movl %eax, %edi 0xf7fdb159 <+2>: calll 0xf7fdb140 Process 21278 launched: '/home/dmlary/src/work/exec' (i386) (lldb) image add ./rel.o (lldb) image load --file rel.o .text 0x40000000 .data 0x50000000 section '.text' loaded at 0x40000000 section '.data' loaded at 0x50000000 (lldb) image dump symtab rel.o Symtab, file = rel.o, num_symbols = 13: Debug symbol |Synthetic symbol ||Externally Visible ||| Index UserID DSX Type File Address/Value Load Address Size Flags Name ------- ------ --- --------------- ------------------ ------------------ ------------------ ---------- ---------------------------------- [ 0] 1 SourceFile 0x0000000000000000 0x0000000000000000 0x00000004 rel.c [ 1] 2 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 2] 3 Invalid 0x0000000000000000 0x50000000 0x0000000000000020 0x00000003 [ 3] 4 Invalid 0x0000000000000025 0x0000000000000000 0x00000003 [ 4] 5 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 5] 6 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 6] 7 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 7] 8 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 8] 9 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 9] 10 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 10] 11 Invalid 0x0000000000000000 0x0000000000000020 0x00000003 [ 11] 12 X Data 0x0000000000000000 0x50000000 0x0000000000000020 0x00000011 padding [ 12] 13 X Data 0x0000000000000020 0x50000020 0x0000000000000005 0x00000011 var (lldb) p &var (volatile char (*)[5]) $1 = 0x50000000 ``` Reviewed By: labath Differential Revision: https://reviews.llvm.org/D132954
2022-08-30Change the meaning of a UUID with all zeros for data.Jim Ingham1-5/+5
Previously, depending on how you constructed a UUID from data or a StringRef, an input value of all zeros was valid (e.g. setFromData) or not (e.g. setFromOptionalData). Since there was no way to tell which interpretation to use, it was done somewhat inconsistently. This standardizes the meaning of a UUID of all zeros to Not Valid, and removes all the Optional methods and their uses, as well as the static factories that supported them. Differential Revision: https://reviews.llvm.org/D132191
2022-08-22Don't create sections for SHN_ABS symbols in ELF files.Greg Clayton1-17/+0
Symbols that have the section index of SHN_ABS were previously creating extra top level sections that contained the value of the symbol as if the symbol's value was an address. As far as I can tell, these symbol's values are not addresses, even if they do have a size. To make matters worse, adding these extra sections can stop address lookups from succeeding if the symbol's value + size overlaps with an existing section as these sections get mapped into memory when the image is loaded by the dynamic loader. This can cause stack frames to appear empty as the address lookup fails completely. This patch: - doesn't create a section for any SHN_ABS symbols - makes symbols that are absolute have values that are not addresses - add accessors to SBSymbol to get the value and size of a symbol as raw integers. Prevoiusly there was no way to access a symbol's value from a SBSymbol because the only accessors were: SBAddress SBSymbol::GetStartAddress(); SBAddress SBSymbol::GetEndAddress(); and these accessors would return an invalid SBAddress if the symbol's value wasn't an address - Adds a test to ensure no ".absolute.<symbol-name>" sections are created - Adds a test to test the new SBSymbol APIs Differential Revision: https://reviews.llvm.org/D131705
2022-07-14[lldb] Remove ELF .zdebug supportFangrui Song1-3/+2
clang 14 removed -gz=zlib-gnu support and ld.lld/llvm-objcopy removed zlib-gnu support recently. Remove lldb support by migrating away from llvm::object::Decompressor::isCompressedELFSection. The API has another user llvm-dwp, so it is not removed in this patch. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D129724
2022-07-13[Support] Change compression::zlib::{compress,uncompress} to use uint8_t *Fangrui Song1-2/+1
It's more natural to use uint8_t * (std::byte needs C++17 and llvm has too much uint8_t *) and most callers use uint8_t * instead of char *. The functions are recently moved into `llvm::compression::zlib::`, so downstream projects need to make adaption anyway.
2022-05-05[lldb] Fix ppc64 detection in lldbserge-sans-paille1-0/+10
Currently, ppc64le and ppc64 (defaulting to big endian) have the same descriptor, thus the linear scan always return ppc64le. Handle that through subtype. This is a recommit of f114f009486816ed4b3bf984f0fbbb8fc80914f6 with a new test setup that doesn't involves (unsupported) corefiles. Differential Revision: https://reviews.llvm.org/D124760
2022-05-03Revert "[lldb] Fix ppc64 detection in lldb"David Spickett1-10/+0
This reverts commit f114f009486816ed4b3bf984f0fbbb8fc80914f6. Due to hitting an assert on our lldb bots: https://lab.llvm.org/buildbot/#/builders/96/builds/22715 ../llvm-project/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp:170: virtual lldb::RegisterContextSP ThreadElfCore::CreateRegisterContextForFrame( lldb_private::StackFrame *): Assertion `false && "Architecture or OS not supported"' failed.
2022-05-03[lldb] Fix ppc64 detection in lldbserge-sans-paille1-0/+10
Currently, ppc64le and ppc64 (defaulting to big endian) have the same descriptor, thus the linear scan always return ppc64le. Handle that through subtype. Differential Revision: https://reviews.llvm.org/D124760