Commit Graph

25962 Commits

Author SHA1 Message Date
Nikita Popov ad1feef7b2 [lldb] Remove some uses of getPointerElementType()
While in the area, remove some uses of getPointerElementType()
that have obvious replacements.
2022-02-14 09:44:37 +01:00
Nikita Popov 2df9430fbf [lldb] Remove uses of PointerType::getElementType()
This method has been deprecated and removed. I missed these usages
in lldb previously.
2022-02-14 09:34:24 +01:00
Jonas Devlieghere af969141fa [lldb] Pin the shared cache when iterating over its images
Use the dyld_shared_cache_(un)pin_mapping SPI to map the whole shared
cache in memory (if possible) to avoid repeated calls to mmap.

rdar://81189015
2022-02-11 15:26:33 -08:00
Adrian Prantl 4ef02cba2e Revert "Add -fmodules-local-submodule-visibility to MANDATORY_MODULE_BUILD_CFLAGS"
This reverts commit 547a667cee.
2022-02-10 15:37:11 -08:00
Adrian Prantl 547a667cee Add -fmodules-local-submodule-visibility to MANDATORY_MODULE_BUILD_CFLAGS
to work around build failure introduced in https://reviews.llvm.org/D119036
2022-02-10 11:11:50 -08:00
Greg Clayton 3db7cc1ba4 Fix a double debug info size counting in top level stats for "statistics dump".
This mainly affects Darwin targets (macOS, iOS, tvOS and watchOS) when these targets don't use dSYM files and the debug info was in the .o files. All modules, including the .o files that are loaded by the debug maps, were in the global module list. This was great because it allows us to see each .o file and how much it contributes. There were virtual functions on the SymbolFile class to fetch the symtab/debug info parse and index times, and also the total debug info size. So the main executable would add all of the .o file's stats together and report them as its own data. Then the "totalDebugInfoSize" and many other "totalXXX" top level totals were all being added together. This stems from the fact that my original patch only emitted the modules for a target at the start of the patch, but as comments from the reviews came in, we switched to emitting all of the modules from the global module list.

So this patch fixes it so when we have a SymbolFileDWARFDebugMap that loads .o files, the main executable will have no debug info size or symtab/debug info parse/index times, but each .o file will have its own data as a separate module. Also, to be able to tell when/if we have a dSYM file I have added a "symbolFilePath" if the SymbolFile for the main modules path doesn't match that of the main executable. We also include a "symbolFileModuleIdentifiers" key in each module if the module does have multiple lldb_private::Module objects that contain debug info so that you can track down the information for a module and add up the contributions of all of the .o files.

Tests were added that are labeled with @skipUnlessDarwin and @no_debug_info_test that test all of this functionality so it doesn't regress.

For a module with a dSYM file, we can see the "symbolFilePath" is included:
```
  "modules": [
    {
      "debugInfoByteSize": 1070,
      "debugInfoIndexLoadedFromCache": false,
      "debugInfoIndexSavedToCache": false,
      "debugInfoIndexTime": 0,
      "debugInfoParseTime": 0,
      "identifier": 4873280600,
      "path": "/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_dsym_binary_has_symfile_in_stats/a.out",
      "symbolFilePath": "/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_dsym_binary_has_symfile_in_stats/a.out.dSYM/Contents/Resources/DWARF/a.out",
      "symbolTableIndexTime": 7.9999999999999996e-06,
      "symbolTableLoadedFromCache": false,
      "symbolTableParseTime": 7.8999999999999996e-05,
      "symbolTableSavedToCache": false,
      "triple": "arm64-apple-macosx12.0.0",
      "uuid": "E1F7D85B-3A42-321E-BF0D-29B103F5F2E3"
    },
```
And for the DWARF in .o file case we can see the "symbolFileModuleIdentifiers" in the executable's module stats:
```
  "modules": [
    {
      "debugInfoByteSize": 0,
      "debugInfoIndexLoadedFromCache": false,
      "debugInfoIndexSavedToCache": false,
      "debugInfoIndexTime": 0,
      "debugInfoParseTime": 0,
      "identifier": 4603526968,
      "path": "/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_no_dsym_binary_has_symfile_identifiers_in_stats/a.out",
      "symbolFileModuleIdentifiers": [
        4604429832
      ],
      "symbolTableIndexTime": 7.9999999999999996e-06,
      "symbolTableLoadedFromCache": false,
      "symbolTableParseTime": 0.000112,
      "symbolTableSavedToCache": false,
      "triple": "arm64-apple-macosx12.0.0",
      "uuid": "57008BF5-A726-3DE9-B1BF-3A9AD3EE8569"
    },
```
And the .o file for 4604429832 looks like:
```
    {
      "debugInfoByteSize": 1028,
      "debugInfoIndexLoadedFromCache": false,
      "debugInfoIndexSavedToCache": false,
      "debugInfoIndexTime": 0,
      "debugInfoParseTime": 6.0999999999999999e-05,
      "identifier": 4604429832,
      "path": "/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_no_dsym_binary_has_symfile_identifiers_in_stats/main.o",
      "symbolTableIndexTime": 0,
      "symbolTableLoadedFromCache": false,
      "symbolTableParseTime": 0,
      "symbolTableSavedToCache": false,
      "triple": "arm64-apple-macosx"
    }
```

Differential Revision: https://reviews.llvm.org/D119400
2022-02-10 10:55:18 -08:00
David Spickett 2937b28218 Reland "[lldb] Remove non address bits when looking up memory regions"
This reverts commit 0df522969a.

Additional checks are added to fix the detection of the last memory region
in GetMemoryRegions or repeating the "memory region" command when the
target has non-address bits.

Normally you keep reading from address 0, looking up each region's end
address until you get LLDB_INVALID_ADDR as the region end address.
(0xffffffffffffffff)

This is what the remote will return once you go beyond the last mapped region:
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]
[0x0001000000000000-0xffffffffffffffff) ---

Problem is that when we "fix" the lookup address, we remove some bits
from it. On an AArch64 system we have 48 bit virtual addresses, so when
we fix the end address of the [stack] region the result is 0.
So we loop back to the start.

[0x0000fffffffdf000-0x0001000000000000) rw- [stack]
[0x0000000000000000-0x0000000000400000) ---

To fix this I added an additional check for the last range.
If the end address of the region is different once you apply
FixDataAddress, we are at the last region.

Since the end of the last region will be the last valid mappable
address, plus 1. That 1 will be removed by the ABI plugin.

The only side effect is that on systems with non-address bits, you
won't get that last catch all unmapped region from the max virtual
address up to 0xf...f.

[0x0000fffff8000000-0x0000fffffffdf000) ---
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]
<ends here>

Though in some way this is more correct because that region is not
just unmapped, it's not mappable at all.

No extra testing is needed because this is already covered by
TestMemoryRegion.py, I simply forgot to run it on system that had
both top byte ignore and pointer authentication.

This change has been tested on a qemu VM with top byte ignore,
memory tagging and pointer authentication enabled.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D115508
2022-02-10 10:42:49 +00:00
Med Ismail Bennani 9a9bf12c4a [lldb/crashlog] Fix arm64 register parsing on crashlog.py
This patch fixes the register parser for arm64 crashlogs.

Compared to x86_64 crashlogs, the arm64 crashlogs nests the general
purpose registers into a separate dictionary within `thread_state`
dictionary. It uses the dictionary key as the the register number.

Differential Revision: https://reviews.llvm.org/D119168

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-09 13:28:20 -08:00
Med Ismail Bennani d327108d17 [lldb/test] Split Scripted Process test in multiple tests (NFC)
This splits the scripted process tests to be able to run in parallel
since some of test functions can take a very long time to run.

This also disables debug info testing.

Differential Revision: https://reviews.llvm.org/D118513

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-09 13:28:20 -08:00
Med Ismail Bennani f5e5074c40 [lldb/test] Fix TestScriptedProcess.py timeout on x86_64
This patch fixes a timeout issue on the ScriptedProcess test that was
happening on intel platforms. The timeout was due to a misreporting of
the StopInfo in the ScriptedThread that caused the ScriptedProcess to
never stop.

To solve this, this patch changes the way a ScriptedThread reports its
stop reason by making it more architecture specific. In order to do so,
this patch also refactors the ScriptedProcess & ScriptedThread
initializer methods to provide an easy access to the target architecture.

Differential Revision: https://reviews.llvm.org/D118484

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-09 13:28:20 -08:00
Zequan Wu 48d889079a [LLDB][NativePDB] fix that FindSymbolScope never finds scope of a symbol if it doesn't open a scope 2022-02-09 13:20:45 -08:00
Andy Yankovsky e0f2375b52 [lldb] Disable failing test on Windows
Test was introduced in https://reviews.llvm.org/D113498.
2022-02-09 20:40:50 +01:00
Pavel Labath 1046b726ad [lldb] Account for extra threads in TestGdbRemoteThreadsInStopReply on windows
After 9611282c, TestGdbRemoteThreadsInStopReply is not non-deterministic
-- instead it deterministically fails due to extra threads created by
std::thread thread pool.

Adjust the tests to account for that.
2022-02-09 17:42:54 +01:00
Andy Yankovsky afb446e8a6 [lldb] Constant-resolve operands to `getelementptr`
Operands to `getelementptr` can be constants or constant expressions. Check
that all operands can be constant-resolved and resolve them during the
evaluation. If some operands can't be resolved as constants -- the expression
evaluation will fallback to JIT.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=52449

Reviewed By: #lldb, shafik

Differential Revision: https://reviews.llvm.org/D113498
2022-02-09 17:38:38 +01:00
Pavel Labath 9611282c64 [lldb] Stabilize threaded windows lldb-server tests
The tests enabled in 9e699595 are not passing reliably -- sometimes they
report seeing fewer threads than expected.

Based on my (limited) research, this is not a lldb bug, but simply a
consequence of the operating system reporting their presence
asynchronously -- they're reported when they are scheduled to run (or
something similar), and not at the time of the CreateThread call.

To fix this, I add some additional synchronization to the test inferior,
which makes sure that the created thread is alive before continuing to
do other things.
2022-02-09 16:18:27 +01:00
Pavel Labath 96000f5c2b [lldb] Simplify SBCommandInterpreter::SourceInitFileInHomeDirectory
just have it delegate to the new overload.
2022-02-09 16:18:27 +01:00
Muhammad Omair Javaid 73a961b9cc [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows
This patch updates toolchain-msvc.test to cater for Arm64 windows platform.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D117676
2022-02-09 17:40:39 +05:00
Pavel Labath 29caa8583f [lldb] Restore original meaning to test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt
D119167 changed the meaning of that test by removing the use of the
interrupt packet. I did not notice this because the interrupting
happened in a shared utility function.

This patch restores the original meaning of the test, but (almost)
avoids sleeps by using process stdout to synchronize. Sadly, this means
the test stays disabled on windows, as it does not implement output
forwarding.
2022-02-09 12:34:55 +01:00
Pavel Labath 9e6995957a [lldb] Adjust windows xfails for D119167
A couple of additional tests pass with that patch. One new test fails
(because it's not testing a slightly different thing). I'll update it
later to restore the original meaning (I don't want to revert as the net
effect is still very positive), but for now this gets the bot green.
2022-02-09 12:04:13 +01:00
Pavel Labath 5a4fe166d1 [lldb/test] Remove sleeps from some lldb-server tests
Instead of using sleeps, have the inferior notify us (via a trap opcode) that
the requested number of threads have been created.

This allows us to get rid of some fairly dodgy test utility code --
wait_for_thread_count seemed like it was waiting for the threads to
appear, but it never actually let the inferior run, so it only succeeded
if the threads were already started when the function was called. Since
the function was called after a fairly small delay (1s, usually), this
is probably the reason why the tests were failing on some bots.

Differential Revision: https://reviews.llvm.org/D119167
2022-02-09 11:05:02 +01:00
serge-sans-paille 81cde474e2 Cleanup LLVMDebugInfoCodeView headers
Major user-facing changes:

Many headers in llvm/DebugInfo/CodeView no longer include
llvm/Support/BinaryStreamReader.h or llvm/Support/BinaryStreamWriter.h,
those headers may need to be included manually.

Several headers in llvm/DebugInfo/CodeView no longer include
llvm/DebugInfo/CodeView/EnumTables.h or llvm/DebugInfo/CodeView/CodeView.h,
those headers may need to be included manually.

Some statistics:
$ clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/DebugInfo/CodeView/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
after:  2794466
before: 2832765

Discourse thread on the topic: https://discourse.llvm.org/t/include-what-you-use-include-cleanup/

Differential Revision: https://reviews.llvm.org/D119092
2022-02-08 16:00:36 +01:00
Jason Molenda 9b1cb0e171 Platform gdb RSP packet doc fixes based on implementation behavior
Reviewing some recent fixes to the platform packet implementations
in lldb, I saw the docs were out of sync in a few spots.  Updated them.

Differential Revision: https://reviews.llvm.org/D118842
2022-02-07 23:51:46 -08:00
Mariusz Ceier 385f5c4d33 [lldb][CMake] Fix linking of gdb-remote when LLVM_ENABLE_ZLIB is ON
When LLVM_ENABLE_ZLIB is ON gdb-remote should link against ZLIB::ZLIB.

This fixes
```
/mnt/b/yoe/master/build/tmp/hosttools/ld: lib/liblldbPluginProcessGDBRemote.a(GDBRemoteCommunication.cpp.o): in function `lldb_private::process_gdb_remote::GDBRemoteCommunication::DecompressPacket() [clone .localalias]':
GDBRemoteCommunication.cpp:(.text._ZN12lldb_private18process_gdb_remote22GDBRemoteCommunication16DecompressPacketEv+0x59a): undefined reference to `inflateInit2_'
/mnt/b/yoe/master/build/tmp/hosttools/ld: GDBRemoteCommunication.cpp:(.text._ZN12lldb_private18process_gdb_remote22GDBRemoteCommunication16DecompressPacketEv+0x5af): undefined reference to `inflate'
```

Reviewed By: JDevlieghere, MaskRay

Differential Revision: https://reviews.llvm.org/D119186
2022-02-07 23:26:22 -08:00
Dave Lee bf02586c57 [lldb] Call __lldb_init_module from __init__
Update `__init__.py` generation to implement `__lldb_init_module`, which calls
`__lldb_init_module` on submodules that define it.

This allows the use case where a user runs `command script import lldb.macosx`.
With this change, the `__lldb_init_module` function in `crashlog.py` and
`heap.py` will be run, which is where command registration is occurring.

Differential Revision: https://reviews.llvm.org/D119179
2022-02-07 14:43:44 -08:00
Dave Lee f8d889a789 [lldb] Print message after loading 'crashlog' command
Previously, importing `crashlog` resulted in a message being printed. The
message was about other commands (those in heap.py), not `crashlog`. The
changes in D117237 made it so that the heap.py messages were printed only when
importing `lldb.macosx.heap`, not when importing `lldb.macosx.crashlog`. Some
users may see no output and think `crashlog` wasn't successfully loaded. This
ensures users see that `crashlog` is loaded.

rdar://88283132

Differential Revision: https://reviews.llvm.org/D119155
2022-02-07 12:34:12 -08:00
Jonas Devlieghere a5a71b139c [lldb] Fix Lua/watchpoint_callback.test on Apple Silicon
As Pavel pointed out, on Apple Silicon "b main" stops at a point after
the variable has already been initialized. This patch updates the test
case to avoids that. I've also split the test into separate files so its
easier to reproduce the individual scenarios without having to build any
shared state.
2022-02-07 12:08:24 -08:00
Adrian Prantl 677182fe98 Revert "Add llgs category to all tests in TestLldbGdbServer that attach to the process."
This reverts commit d42765b3be.
2022-02-07 09:42:07 -08:00
Jonas Devlieghere 0d16652021 [lldb] Skip part of TestGdbRemoteMemoryAllocation.py on Apple Silicon
Skip the part of TestGdbRemoteMemoryAllocation.py that attempts to
allocate both writable and executable memory.
2022-02-07 09:41:38 -08:00
Jonas Devlieghere 20e17323cd [lldb] Fix a few lldb-server tests on Apple Silicon
This fixes TestGdbRemoteSingleStep.py and TestGdbRemote_vCont.py. This
patch updates the test to account for the possibility that the constants
are already materialized. This appears to behave differently between
embedded arm64 devices and Apple Silicon.
2022-02-07 09:35:12 -08:00
Adrian Prantl d42765b3be Add llgs category to all tests in TestLldbGdbServer that attach to the process. 2022-02-07 08:26:48 -08:00
Jonas Devlieghere d63dfa14d6 [lldb] Update outdated comment in TestDyldTrieSymbols.py
After aed965d55d we no longer demangle and store the full name. The
test was updated accordingly but the comment still specified that we
should be able to find the symbol by its full demangled name.
2022-02-07 08:13:54 -08:00
Pavel Labath a53c5c66b3 [lldb/Platform] s/m_name/m_hostname
m_name is confusing, as there is a getter called GetName, but it returns
a completely different thing.
2022-02-07 14:58:55 +01:00
Kazu Hirata ee4b6cf538 [Breakpoint] Remove redundant member initialization (NFC)
Identified with readability-redundant-member-init.
2022-02-06 10:54:46 -08:00
Adrian Prantl 11d64edbf9 Revert "Disable TestLldbGdbServer on Dwarf2 and clang versions below 14"
This reverts commit 867fdec194.
2022-02-05 14:54:41 -08:00
Adrian Prantl a701dc8eda Revert "Fixed typos in TestLldbGdbServer.py"
This reverts commit cf93a08575.
2022-02-05 14:54:37 -08:00
Jonas Devlieghere ef3fade14b [lldb] Use mangled symbol name to look for __asan::AsanDie()
After aed965d we no longer demangle full symbol names while indexing the
symbol table which means we have to use the mangled name instead of the
demangled name to find the symbol for __asan::AsanDie().

This fixes the following two tests:

  lldb-api :: functionalities/asan/TestMemoryHistory.py
  lldb-api :: functionalities/asan/TestReportData.py
2022-02-05 09:50:31 -08:00
Jason Molenda a37c38176a Increase memory buffer for scanning objc classes on darwin systems
iOS systems are getting near this limit; double itfrom a 150kb
buffer to a 300kb buffer, which is freed after processing the
list of classes.

rdar://88454594
Differential Revision: https://reviews.llvm.org/D118972
2022-02-04 23:53:27 -08:00
Jonas Devlieghere edbb0f6df7 [lldb] Rename DemangleWithRichManglingInfo to GetRichManglingInfo (NFC)
This addresses Pavel's comment from D118814.
2022-02-04 10:40:33 -08:00
Jonas Devlieghere aed965d55d [lldb] Don't construct the demangled strings while indexing the symbol table
The symbol table needs to demangle all symbol names when building its
index. However, this doesn't require the full mangled name: we only need
the base name and the function declaration context. Currently, we always
construct the demangled string during indexing and cache it in the
string pool as a way to speed up future lookups.

Constructing the demangled string is by far the most expensive step of
the demangling process, because the output string can be exponentially
larger than the input and unless you're dumping the symbol table, many
of those demangled names will not be needed again.

This patch avoids constructing the full demangled string when we can
partially demangle. This speeds up indexing and reduces memory usage.

I gathered some numbers by attaching to Slack:

Before
------

  Memory usage: 280MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
    Time (mean ± σ):      4.829 s ±  0.518 s    [User: 4.012 s, System: 0.208 s]
    Range (min … max):    4.624 s …  6.294 s    10 runs

After
-----

  Memory usage: 189MB
  Benchmark 1: ./bin/lldb -n Slack -o quit
    Time (mean ± σ):      4.182 s ±  0.025 s    [User: 3.536 s, System: 0.192 s]
    Range (min … max):    4.152 s …  4.233 s    10 runs

Differential revision: https://reviews.llvm.org/D118814
2022-02-04 10:17:39 -08:00
Jonas Devlieghere fa52788b7a [lldb] Improve RichManglingContext ergonomics (NFC)
Have the different ::Parse.* methods return the demangled string
directly instead of having to go through ::GetBufferRef.

Differential revision: https://reviews.llvm.org/D118953
2022-02-04 10:17:39 -08:00
Pavel Labath 13b58f9710 [lldb] Remove Log:Channel::GetLogIfAll
after the recent refactor, the function is unused.
2022-02-04 13:31:14 +01:00
Zequan Wu 8682947d24 [LLDB][NativePDB] terminal entry has lower precedence than new entry 2022-02-03 15:41:26 -08:00
Zequan Wu ac73e12ee0 [LLDB] remove an extra register enum on windows x64 2022-02-03 14:12:24 -08:00
Zequan Wu 607ffa5515 [LLDB] Fix window bot failure
This attempts to fix this bot failure: https://lab.llvm.org/buildbot/#/builders/83/builds/14736 caused by D118750 by un-xfail those expected failed tests.

Differential Revision: https://reviews.llvm.org/D118866
2022-02-03 11:27:48 -08:00
Pavel Labath 359a2deb6f [lldb] Fix windows&mac builds for c34698a811 2022-02-03 18:06:55 +01:00
Pavel Labath c34698a811 [lldb] Rename Logging.h to LLDBLog.h and clean up includes
Most of our code was including Log.h even though that is not where the
"lldb" log channel is defined (Log.h defines the generic logging
infrastructure). This worked because Log.h included Logging.h, even
though it should.

After the recent refactor, it became impossible the two files include
each other in this direction (the opposite inclusion is needed), so this
patch removes the workaround that was put in place and cleans up all
files to include the right thing. It also renames the file to LLDBLog to
better reflect its purpose.
2022-02-03 14:47:01 +01:00
Zequan Wu f3e1ba1d03 [LLDB] add sub regigter enums on x64 Windows
Differential Revision: https://reviews.llvm.org/D118750
2022-02-02 14:21:08 -08:00
Michał Górny 287ce6b516 [lldb] [Commands] Implement "thread siginfo"
Differential Revision: https://reviews.llvm.org/D118473
2022-02-02 19:31:44 +01:00
Pavel Labath a007a6d844 [lldb] Convert "LLDB" log channel to the new API 2022-02-02 14:13:08 +01:00
Pavel Labath b1127753b9 [lldb] Convert ProcessGDBRemoteLog to the new API 2022-02-01 14:36:29 +01:00