aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-09[LLDB] Unify DWARF section name matching (#141344)nerix1-14/+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-05-24[lldb] Use llvm::stable_sort (NFC) (#141352)Kazu Hirata1-2/+1
2025-02-13[lldb] Use LLDB_LOG_ERROR in ObjectFilePECOFF.cpp (NFC) (#126972)Dave Lee1-22/+11
2025-01-14[lldb][NFC] Make the target's SectionLoadList private. (#113278)Greg Clayton1-1/+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.
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-09-11[LLDB] Reapply SBSaveCore Add Memory List (#107937)Jacob Lalonde1-0/+1
Recently in #107731 this change was revereted due to excess memory size in `TestSkinnyCore`. This was due to a bug where a range's end was being passed as size. Creating massive memory ranges. Additionally, and requiring additional review, I added more unit tests and more verbose logic to the merging of save core memory regions. @jasonmolenda as an FYI.
2024-09-07Revert "[LLDB] Reappply SBSaveCore AddMemoryList" (#107731)Jonas Devlieghere1-1/+0
Reverts llvm/llvm-project#107159 as this is still causing `TestSkinnyCorefile.py` to time out. https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/11099/ https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/lldb-cmake/5544/
2024-09-06[LLDB] Reappply SBSaveCore AddMemoryList (#107159)Jacob Lalonde1-0/+1
Reapplies #106293, testing identified issue in the merging code. I used this opportunity to strip CoreFileMemoryRanges to it's own file and then add unit tests on it's behavior.
2024-08-27Revert "[LLDB][SBSaveCore] Add selectable memory regions to SBSaveCor… ↵Jacob Lalonde1-1/+0
(#106293) Reverts #105442. Due to `TestSkinnyCoreFailing` and root causing of the failure will likely take longer than EOD.
2024-08-27[LLDB][SBSaveCore] Add selectable memory regions to SBSaveCore (#105442)Jacob Lalonde1-0/+1
This patch adds the option to specify specific memory ranges to be included in a given core file. The current implementation lets user specified ranges either be in addition to a certain save style, or independent of them via the newly added custom enum. To achieve being inclusive of save style, I've moved from a std::vector of ranges to a RangeDataVector, and to join overlapping ranges to prevent duplication of memory ranges in the core file. As a non function bonus, when SBSavecore was initially created, the header was included in the lldb-private interfaces, and I've fixed that and moved it the forward declare as an oversight. CC @bulbazord in case we need to include that into swift.
2024-08-15[LLDB] Reapply #100443 SBSaveCore Thread list (#104497)Jacob Lalonde1-1/+1
Reapply #100443 and #101770. These were originally reverted due to a test failure and an MSAN failure. I changed the test attribute to restrict to x86 (following the other existing tests). I could not reproduce the test or the MSAN failure and no repo steps were provided.
2024-08-05Revert "[LLDB][SBSaveCore] Fix bug where default values are not propagated. ↵Haojian Wu1-1/+1
(#101770)" This reverts commit 34766d0d488ba2fbefa80dcd0cc8720a0e753448 which caused a msan failure, see comment https://github.com/llvm/llvm-project/pull/101770#issuecomment-2268373325 for details.
2024-08-02[LLDB][SBSaveCore] Fix bug where default values are not propagated. (#101770)Jacob Lalonde1-1/+1
In #100443, Mach-o and Minidump now only call process API's that take a `SaveCoreOption` as the container for the style and information if a thread should be included in the core or not. This introduced a bug where in subsequent method calls we were not honoring the defaults of both implementations. ~~To solve this I have made a copy of each SaveCoreOptions that is mutable by the respective plugin. Originally I wanted to leave the SaveCoreOptions as non const so these default value mutations could be shown back to the user. Changing that behavior is outside of the scope of this bugfix, but is context for why we are making a copy.~~ Removed const on the savecoreoptions so defaults can be inspected by the user CC: @Michael137
2024-07-18[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() ↵Jacob Lalonde1-4/+5
overload (#98403) This PR adds `SBSaveCoreOptions`, which is a container class for options when LLDB is taking coredumps. For this first iteration this container just keeps parity with the extant API of `file, style, plugin`. In the future this options object can be extended to allow users to take a subset of their core dumps.
2023-11-01[lldb] Fix missing comsumeError() with LLDB_LOG in ObjectFileCOFF/PECOFF ↵Stefan Gränitz1-5/+4
(#70793) All `llvm::Error`s must be checked/consumed before destruction. Previously, the errors in this patch were only consumed when logging was enabled. Using `LLDB_LOG_ERROR` instead of `LLDB_LOG` fixes that, because it calls `llvm::consumeError()` explicitly when logging is disabled.
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-08-31[lldb][NFCI] Remove unneeded ConstString conversionsAlex Langford1-2/+2
ConstString can be implicitly converted into a llvm::StringRef. This is very useful in many places, but it also hides places where we are creating a ConstString only to use it as a StringRef for the entire lifespan of the ConstString object. I locally removed the implicit conversion and found some of the places we were doing this. Differential Revision: https://reviews.llvm.org/D159237
2023-08-09[lldb] Sink StreamFile into lldbHostAlex Langford1-1/+0
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-08-04[lldb][PECOFF] Exclude alignment padding when reading section dataHiroshi Yamauchi1-0/+10
There can be zero padding bytes at a section end for file alignment in PECOFF. Exclude those padding bytes when reading the section data. Differential Revision: https://reviews.llvm.org/D157059
2023-07-26[lldb] Treat ARM64X images as ARM64.Jacek Caban1-0/+1
With D149091, ARM64X binaries are no longer reported as ARM64. This broke lldb tests as Windows 11 system DLLs are mostly ARM64X binaries and lldb doesn't know how to handle them. Ideally lldb would understand a bit more about ARM64X and handle them as AMD64 in x64 processes, but this is enough to preserve previous behavior and fix tests. Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D156268
2023-05-14[lldb] Complete OptionValue cleanup (NFC)Jonas Devlieghere1-2/+2
Make the `Get.*Value` and `Set.*Value` function private and migrate the last remaining call sites to the new overloaded/templated functions.
2023-05-05ObjectFile: remove extraneous shadowed variable (NFCI)Saleem Abdulrasool1-1/+0
We already construct the shared pointer for the module. Avoid creating a shadow copy and use the original definition.
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-04[lldb] Use templates to simplify {Get,Set}PropertyAtIndex (NFC)Jonas Devlieghere1-3/+2
Use templates to simplify {Get,Set}PropertyAtIndex. It has always bothered me how cumbersome those calls are when adding new properties. After this patch, SetPropertyAtIndex infers the type from its arguments and GetPropertyAtIndex required a single template argument for the return value. As an added benefit, this enables us to remove a bunch of wrappers from UserSettingsController and OptionValueProperties. Differential revision: https://reviews.llvm.org/D149774
2023-05-02[lldb] Remove FileSpec::GetLastPathComponentAlex Langford1-2/+2
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-05-02[lldb] Make exe_ctx an optional argument in OptionValueProperties (NFC)Jonas Devlieghere1-2/+2
The majority of call sites are nullptr as the execution context. Refactor OptionValueProperties to make the argument optional and simplify all the callers.
2023-05-01[lldb] Refactor OptionValueProperties to return a std::optional (NFC)Jonas Devlieghere1-3/+3
Similar to fdbe7c7faa54, refactor OptionValueProperties to return a std::optional instead of taking a fail value. This allows the caller to handle situations where there's no value, instead of being unable to distinguish between the absence of a value and the value happening the match the fail value. When a fail value is required, std::optional::value_or() provides the same functionality.
2023-05-01[lldb] Refactor OptionValue to return a std::optional (NFC)Jonas Devlieghere1-1/+2
Refactor OptionValue to return a std::optional instead of taking a fail value. This allows the caller to handle situations where there's no value, instead of being unable to distinguish between the absence of a value and the value happening the match the fail value. When a fail value is required, std::optional::value_or() provides the same functionality.
2023-05-01[lldb] Change ObjectValueDictionary to use a StringMapAlex Langford1-5/+3
llvm has a structure for maps where the key's type is a string. Using that also means that the keys for OptionValueDictionary don't stick around forever in ConstString's StringPool (even after they are gone). The only thing we lose here is ordering: iterating over the map where the keys are ConstStrings guarantees that we iterate in alphabetical order. StringMap makes no guarantees about the ordering when you iterate over the entire map. Differential Revision: https://reviews.llvm.org/D149482
2023-04-19[lldb] Change setting descriptions to use StringRef instead of ConstStringAlex Langford1-2/+1
These probably do not need to be in the ConstString StringPool as they don't really need any of the advantages that ConstStrings offer. Lifetime for these things is always static and we never need to perform comparisons for setting descriptions. Differential Revision: https://reviews.llvm.org/D148679
2023-04-17PECOFF: consume errors properlySaleem Abdulrasool1-12/+22
We would not ensure that the error is consumed in the case that logging is disabled. Ensure that we properly drop the error on the floor or we would re-trigger the checked failure. Differential Revision: https://reviews.llvm.org/D147669 Reviewed By: sgraenitz
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+1
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-1/+1
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-13[lldb] Place PlatformQemu Properties into anonymous namespacePavel Labath1-2/+2
It's fine right now, but will break as soon as someone else declares a PluginProperties class in the same way. Also tighten up the scope of the anonymous namespaces surrounding the other PluginProperties classes.
2022-09-28[lldb][COFF] Map symbols without base+complex type as 'Data' typeAlvin Wong1-0/+7
Both LLD and GNU ld write global/static variables to the COFF symbol table with `IMAGE_SYM_TYPE_NULL` and `IMAGE_SYM_DTYPE_NULL` type. Map these symbols as 'Data' type in the symtab to allow these symbols to be used in expressions and printable. Reviewed By: labath, DavidSpickett Differential Revision: https://reviews.llvm.org/D134585
2022-09-28[lldb][COFF] Add note to forwarder export symbols in symtabAlvin Wong1-3/+24
Forwarder exports do not point to a real function or variable. Instead they point to a string describing which DLL and symbol to forward to. Any imports which uses them will be redirected by the loader transparently. These symbols do not have much use in LLDB, but keep them just in case someone find it useful. Also set a synthesized name with the forwarder string for informational purpose. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134518
2022-09-28[lldb][COFF] Load absolute symbols from COFF symbol tableAlvin Wong1-0/+3
Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134517
2022-09-28[lldb][COFF] Match symbols from COFF symbol table to export symbolsAlvin Wong1-10/+50
If a symbol is the same as an export symbol, mark it as 'Additional' to prevent the duplicated symbol from being repeated in some commands (e.g. `disas -n func`). If the RVA is the same but exported with a different name, only synchronize the symbol types. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134426
2022-09-28[lldb][COFF] Improve info of symbols from export tableAlvin Wong1-2/+15
- Skip dummy/invalid export symbols. - Make the export ordinal of export symbols visible when dumping the symtab. - Stop setting the 'Debug' flag and set the 'External' flag instead to better match the meaning of export symbols. - Try to guess the type (code vs data) of the symbol from section flags. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134265
2022-09-28[lldb][COFF] Rewrite ParseSymtab to list both export and symbol tablesAlvin Wong1-113/+76
This reimplements `ObjectFilePECOFF::ParseSymtab` to replace the manual data extraction with what `COFFObjectFile` already provides. Also use `SymTab::AddSymbol` instead of resizing the SymTab then assigning each elements afterwards. Previously, ParseSymTab loads symbols from both the COFF symbol table and the export table, but if there are any entries in the export table, it overwrites all the symbols already loaded from the COFF symbol table. Due to the change to use AddSymbols, this no longer happens, and so the SymTab now contains all symbols from both tables as expected. The export symbols are now ordered by ordinal, instead of by the name table order. In its current state, it is possible for symbols in the COFF symbol table to be duplicated by those in the export table. This behaviour will be modified in a separate change. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134196
2022-09-08[lldb] Use std::size instead of llvm::array_lengthofJoe Loser1-1/+1
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133501
2022-08-30Change the meaning of a UUID with all zeros for data.Jim Ingham1-2/+2
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-07-28[NFC] Improve FileSpec internal APIs and usage in preparation for adding ↵Greg Clayton1-1/+1
caching of resolved/absolute. Resubmission of https://reviews.llvm.org/D130309 with the 2 patches that fixed the linux buildbot, and new windows fixes. The FileSpec APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossible to control all of the times the FileSpec object is modified so we can clear cached member variables like m_resolved and with an upcoming patch caching if the file is relative or absolute. This patch modifies the APIs of FileSpec so no one can modify the directory or filename instance variables directly by adding set accessors and by removing the get accessors that are non const. Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString: ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const; This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result. The patch: - Removes the non const GetDirectory() and GetFilename() get accessors - Adds set accessors to replace the above functions: SetDirectory() and SetFilename(). - Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites - Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently. Differential Revision: https://reviews.llvm.org/D130549
2022-07-23Revert "[NFC] Improve FileSpec internal APIs and usage in preparation for ↵Nico Weber1-1/+1
adding caching of resolved/absolute." and follow-ups This reverts commit 9429b67b8e300e638d7828bbcb95585f85c4df4d. It broke the build on Windows, see comments on https://reviews.llvm.org/D130309 It also reverts these follow-ups: Revert "Fix buildbot breakage after https://reviews.llvm.org/D130309." This reverts commit f959d815f4637890ebbacca379f1c38ab47e4e14. Revert "Fix buildbot breakage after https://reviews.llvm.org/D130309." This reverts commit 0bbce7a4c2d2bff622bdadd4323f93f5d90e6d24. Revert "Cache the value for absolute path in FileSpec." This reverts commit dabe877248b85b34878e75d5510339325ee087d0.
2022-07-22[NFC] Improve FileSpec internal APIs and usage in preparation for adding ↵Greg Clayton1-1/+1
caching of resolved/absolute. The FileSpect APIs allow users to modify instance variables directly by getting a non const reference to the directory and filename instance variables. This makes it impossibly to control all of the times the FileSpec object is modified so we can clear the cache. This patch modifies the APIs of FileSpec so no one can modify the directory or filename directly by adding set accessors and by removing the get accessors that are non const. Many clients were using FileSpec::GetCString(...) which returned a unique C string from a ConstString'ified version of the result of GetPath() which returned a std::string. This caused many locations to use this convenient function incorrectly and could cause many strings to be added to the constant string pool that didn't need to. Most clients were converted to using FileSpec::GetPath().c_str() when possible. Other clients were modified to use the newly renamed version of this function which returns an actualy ConstString: ConstString FileSpec::GetPathAsConstString(bool denormalize = true) const; This avoids the issue where people were getting an already uniqued "const char *" that came from a ConstString only to put the "const char *" back into a "ConstString" object. By returning the ConstString instead of a "const char *" clients can be more efficient with the result. The patch: - Removes the non const GetDirectory() and GetFilename() get accessors - Adds set accessors to replace the above functions: SetDirectory() and SetFilename(). - Adds ClearDirectory() and ClearFilename() to replace usage of the FileSpec::GetDirectory().Clear()/FileSpec::GetFilename().Clear() call sites - Fixed all incorrect usage of FileSpec::GetCString() to use FileSpec::GetPath().c_str() where appropriate, and updated other call sites that wanted a ConstString to use the newly returned ConstString appropriately and efficiently. Differential Revision: https://reviews.llvm.org/D130309