summaryrefslogtreecommitdiff
path: root/lldb/test/Shell/ObjectFile/PECOFF
AgeCommit message (Collapse)Author
2025-06-09[LLDB] Unify DWARF section name matching (#141344)nerix
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.
2024-07-08[lldb] Improve error message for unrecognized executables (#97490)Jonas Devlieghere
Currently, LLDB prints out a rather unhelpful error message when passed a file that it doesn't recognize as an executable. > error: '/path/to/file' doesn't contain any 'host' platform > architectures: arm64, armv7, armv7f, armv7k, armv7s, armv7m, armv7em, > armv6m, armv6, armv5, armv4, arm, thumbv7, thumbv7k, thumbv7s, > thumbv7f, thumbv7m, thumbv7em, thumbv6m, thumbv6, thumbv5, thumbv4t, > thumb, x86_64, x86_64, arm64, arm64e I did a quick search internally and found at least 24 instances of users being confused by this. This patch improves the error message when it doesn't recognize the file as an executable, but keeps the existing error message otherwise, i.e. when it's an object file we understand, but the current platform doesn't support.
2023-11-03[lldb] Move LocateExecutableSymbolFile to SymbolLocator plugin (#71266)Jonas Devlieghere
This builds on top of the work started in c3a302d to convert LocateSymbolFile to a SymbolLocator plugin. This commit moves LocateExecutableSymbolFile.
2022-09-28[lldb][COFF] Map symbols without base+complex type as 'Data' typeAlvin Wong
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 Wong
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 Wong
Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134517
2022-09-28[lldb][COFF] Match symbols from COFF symbol table to export symbolsAlvin Wong
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 Wong
- 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 Wong
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-07-06[lldb] Stop passing both i386 and i686 in parallel as architectures on WindowsMartin Storsjö
When an object file returns multiple architectures, it is treated as a fat binary - which really isn't the case of i386 vs i686 where the object file actually has one architecture. This allows getting rid of hardcoded architecture triples in PlatformWindows. The parallel i386 and i686 architecture strings stem from 5e6f45201f0b62c1e7a24fc396f3ea6e10dc880d / D7120 and ad587ae4ca143d388c0ec4ef2faa1b5eddedbf67 / D4658. Differential Revision: https://reviews.llvm.org/D128617
2022-06-22[lldb] Add setting to override PE/COFF ABI by module nameAlvin Wong
The setting `plugin.object-file.pe-coff.module-abi` is a string-to-enum map that allows specifying an ABI to a module name. For example: ucrtbase.dll=msvc libstdc++-6.dll=gnu This allows for debugging a process which mixes both modules built using the MSVC ABI and modules built using the MinGW ABI. Depends on D127048 Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D127234
2022-06-22[lldb] Fix reading i686-windows executables with GNU environmentMartin Storsjö
25c8a061c5739677d2fc0af29a8cc9520207b923 / D127048 added an option for setting the ABI to GNU. When an object file is loaded, there's only minimal verification done for the architecture spec set for it, if the object file only provides one. However, for i386 object files, the PECOFF object file plugin provides two architectures, i386-pc-windows and i686-pc-windows. This picks a totally different codepath in TargetList::CreateTargetInternal, where it's treated as a fat binary. This goes through more verifications to see if the architectures provided by the object file matches what the platform plugin supports. The PlatformWindows() constructor explicitly adds the "i386-pc-windows" and "i686-pc-windows" architectures (even when running on other architectures), which allows this "fat binary verification" to succeed for the i386 object files that provide two architectures. However, after that commit, if the object file is advertised with the different environment (either when lldb is built in a mingw environment, or if that setting is set), the fat binary validation won't accept the file any longer. Update ArchSpec::IsEqualTo with more logic for the Windows use cases; mismatching vendors is not an issue (they don't have any practical effect on Windows), and GNU and MSVC environments are compatible to the point that PlatformWindows can handle object files for both environments/ABIs. As a separate path forward, one could also consider to stop returning two architecture specs from ObjectFilePECOFF::GetModuleSpecifications for i386 files. Differential Revision: https://reviews.llvm.org/D128268
2022-06-09[lldb] Set COFF module ABI from default triple and make it an optionAlvin Wong
PE/COFF can use either MSVC or GNU (MinGW) ABI for C++ code, however LLDB had defaulted to MSVC implicitly with no way to override it. This causes issues when debugging modules built with the GNU ABI, sometimes even crashes. This changes the PE/COFF plugin to set the module triple according to the default target triple used to build LLDB. If the default target triple is Windows and a valid environment is specified, then this environment will be used for the module spec. This not only works for MSVC and GNU, but also other environments. A new setting, `plugin.object-file.pe-coff.abi`, has been added to allow overriding this default ABI. * Fixes https://github.com/llvm/llvm-project/issues/50775 * Fixes https://github.com/mstorsjo/llvm-mingw/issues/226 * Fixes https://github.com/mstorsjo/llvm-mingw/issues/282 Reviewed By: omjavaid Differential Revision: https://reviews.llvm.org/D127048
2022-06-09[lldb] Add gnu-debuglink support for Windows PE/COFFAlvin Wong
The specification of gnu-debuglink can be found at: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html The file CRC or the CRC value from the .gnu_debuglink section is now used to calculate the module UUID as a fallback, to allow verifying that the debug object does match the executable. Note that if a CodeView build id exists, it still takes precedence. This works even for MinGW builds because LLD writes a synthetic CodeView build id which does not get stripped from the debug object. The `Minidump/Windows/find-module` test also needs a fix by adding a CodeView record to the exe to match the one in the minidump, otherwise it fails due to the new UUID calculated from the file CRC. Fixes https://github.com/llvm/llvm-project/issues/54344 Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D126367
2020-08-20[test] Replace `yaml2obj >` with `yaml2obj -o` and remove unneeded input ↵Fangrui Song
redirection
2020-07-20[LLDB] [COFF] Fix handling of symbols with more than one aux symbolMartin Storsjö
Differential Revision: https://reviews.llvm.org/D84070
2019-11-28[LLDB] [test] Add a missing "REQUIRES: arm" lineMartin Storsjö
2019-11-28[LLDB] Always interpret arm instructions as thumb on windowsMartin Storsjö
Windows on ARM always uses thumb mode, and doesn't have most of the mechanisms that are used in e.g. ELF for distinguishing between arm and thumb. Differential Revision: https://reviews.llvm.org/D70796
2019-11-28[LLDB] [PECOFF] Look for the truncated ".eh_fram" section nameMartin Storsjö
COFF section names can either be stored truncated to 8 chars, in the section header, or as a longer section name, stored separately in the string table. libunwind locates the .eh_frame section by runtime introspection, which only works for section names stored in the section header (as the string table isn't mapped at runtime). To support this behaviour, lld always truncates the section names for sections that will be mapped, like .eh_frame. Differential Revision: https://reviews.llvm.org/D70745
2019-10-31[LLDB] [PECOFF] Fix error handling for executables that object::createBinary ↵Martin Storsjö
errors out on llvm::object::createBinary returns an Expected<>, which requires not only checking the object for success, but also requires consuming the Error, if one was set. Use LLDB_LOG_ERROR for this case, and change an existing similar log statement to use it as well, to make sure the Error is consumed even if the log channel is disabled. Differential Revision: https://reviews.llvm.org/D69646
2019-10-30COFF: Set section permissionsPavel Labath
Summary: This enables us to reason about whether a given address can be executable, for instance during unwinding. Reviewers: amccarth, mstorsjo Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D69102
2019-10-29[LLDB] [PECOFF] Use FindSectionByID to associate symbols to sectionsMartin Storsjö
The virtual container/header section caused the section list to be offset by one, but by using FindSectionByID, the layout of the section list shouldn't matter. Differential Revision: https://reviews.llvm.org/D69366
2019-10-25lldb/COFF: Create a separate "section" for the file headerPavel Labath
In an attempt to ensure that every part of the module's memory image is accounted for, D56537 created a special "container section" spanning the entire image. While that seemed reasonable at the time (and it still mostly does), it did create a problem of what to put as the "file size" of the section, because the image is not continuous on disk, as we generally assume (which is why I put zero there). Additionally, this arrangement makes it unclear what kind of permissions should be assigned to that section (which is what my next patch does). To get around these, this patch partially reverts D56537, and goes back to top-level sections. Instead, what I do is create a new "section" for the object file header, which is also being loaded into memory, though its not considered to be a section in the strictest sense. This makes it possible to correctly assign file size section, and we can later assign permissions to it as well. Reviewers: amccarth, mstorsjo Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D69100
2019-10-15[LLDB] [PECOFF] Use a "pc" vendor name in aarch64 triplesMartin Storsjo
This matches all other architectures listed in the same file. This fixes debugging aarch64 executables with lldb-server, which otherwise fails, with log messages like these: Target::SetArchitecture changing architecture to aarch64 (aarch64-pc-windows-msvc) Target::SetArchitecture Trying to select executable file architecture aarch64 (aarch64-pc-windows-msvc) ArchSpec::SetArchitecture sets the vendor to llvm::Triple::PC for any coff/win32 combination, and if this doesn't match the triple set by the PECOFF module, things doesn't seem to work with when using lldb-server. Differential Revision: https://reviews.llvm.org/D68939 llvm-svn: 374867
2019-10-09Re-land "[test] Split LLDB tests into API, Shell & Unit"Jonas Devlieghere
The original patch got reverted because it broke `check-lldb` on a clean build. This fixes that. llvm-svn: 374201
2019-10-09Revert [test] Split LLDB tests into API, Shell & UnitAdrian Prantl
as it appears to have broken check-lldb. This reverts r374184 (git commit 22314179f0660c172514b397060fd8f34b586e82) llvm-svn: 374187
2019-10-09[test] Split LLDB tests into API, Shell & UnitJonas Devlieghere
LLDB has three major testing strategies: unit tests, tests that exercise the SB API though dotest.py and what we currently call lit tests. The later is rather confusing as we're now using lit as the driver for all three types of tests. As most of this grew organically, the directory structure in the LLDB repository doesn't really make this clear. The 'lit' tests are part of the root and among these tests there's a Unit and Suite folder for the unit and dotest-tests. This layout makes it impossible to run just the lit tests. This patch changes the directory layout to match the 3 testing strategies, each with their own directory and their own configuration file. This means there are now 3 directories under lit with 3 corresponding targets: - API (check-lldb-api): Test exercising the SB API. - Shell (check-lldb-shell): Test exercising command line utilities. - Unit (check-lldb-unit): Unit tests. Finally, there's still the `check-lldb` target that runs all three test suites. Finally, this also renames the lit folder to `test` to match the LLVM repository layout. Differential revision: https://reviews.llvm.org/D68606 llvm-svn: 374184