Commit Graph

26647 Commits

Author SHA1 Message Date
Luís Ferreira 3da4f9c57b [lldb][NFC] Move non-clang specific method to the generic DWARF Parser
This patch renames DW_ACCESS_to_AccessType function and move it to the abstract
DWARFASTParser, since there is no clang-specific code there. This is useful for
plugins other than Clang.

Reviewed By: shafik, bulbazord

Differential Revision: https://reviews.llvm.org/D114719
2022-06-02 16:39:39 +00:00
Luís Ferreira f9b8f422e7 [lldb][NFC] Move generic DWARFASTParser code out of Clang-specific code
This patch moves ParseChildArrayInfo out of DWARFASTParserClang in order
to decouple Clang-specific logic from DWARFASTParser.

Reviewed By: clayborg

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

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
2022-06-02 14:44:07 +00:00
Venkata Ramanaiah Nalamothu c6ad690173 [lldb, test] Fix typos in the lldb tests
Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D126596
2022-06-02 12:45:57 +05:30
Adrian Prantl 62b4482175 Revert "Adapt LLDB for D120540."
This reverts commit ca73de4374.

That patch was just hiding the problem, instead of fixing it.
2022-06-01 10:33:53 -07:00
Jim Ingham d92f7f790c Fix a copy-paste error in "br com add -s py -o 'some_python' BKPT_NAME"
The function that was supposed to iterate over all the breakpoints sharing
BKPT_NAME stopped after the first one because of a reversed "if success"
condition.

Differential Revision: https://reviews.llvm.org/D126730
2022-05-31 17:24:14 -07:00
Adrian Prantl ca73de4374 Adapt LLDB for D120540.
In https://reviews.llvm.org/D120540 the -fcxx-modules flag changed
semantics and specifying it explicitly seems to no longer be what we
want here.
2022-05-31 16:56:37 -07:00
Jason Molenda 2f23abd6c6 Increase the default maximum stack walk
lldb will only backtrace a fixed number of stack frames, as a
last-ditch attempt to avoid a runaway looping backtrace.  It's
unusual that anyone ends up depending on this final safety net in
years. I picked the original number of 300000 was picked by seeing
how many stack frames I could make in a small recursive function
on Darwin systems before using the default stack space.  Checking
again today on a modern system, I can exceed this limit & lldb will
not show the original invocation of the recursing call.  Double the
old value to cover this larger maximum possible stack frame count,
as a default value.
(`target.process.thread.max-backtrace-depth`)
2022-05-28 13:12:57 -07:00
Martin Storsjö 9191078707 [lldb] Fix cross compiling on macOS
When cross compiling, a separate nested cmake is spawned, for building
host code generation tools such as lldb-tblgen.

When cross compiling on macOS, the nested native build would trigger
the lldb check for libc++, if testing is enabled (which it is by default).
(Even if `LLDB_INCLUDE_TESTS=OFF` is set on the main build, it has to
be passed separately in `CROSS_TOOLCHAIN_FLAGS_NATIVE` to reach the
nested build.)

Skip this check when building the host tools when cross compiling, as
the user won't try to run tests in that nested build.

(Alternatively, we could consider disabling all the `*_INCLUDE_TESTS`
by default in the nested host tools build.)

Differential Revision: https://reviews.llvm.org/D126557
2022-05-28 00:53:25 +03:00
Chelsea Cassanova 5451c4b4fb
[lldb/fuzzer] Moving target fuzzer into separate subdirectory
Moving lldb-target-fuzzer into its own subdirectory for better
organization and modularity.

Differential revision: https://reviews.llvm.org/D126507
2022-05-26 17:05:14 -07:00
Jim Ingham 134d7f9a4b Store a by name list of signals with their actions in the Target
so that they can be used to prime new Process runs.  "process handle"
was also changed to populate the dummy target if there's no selected
target, so that the settings will get copied into new targets.

Differential Revision: https://reviews.llvm.org/D126259
2022-05-26 14:50:33 -07:00
Stella Stamenova 75acec818e [lldb] Fix enums-layout test on Windows
The test was broken by: https://reviews.llvm.org/D125604
2022-05-26 12:16:52 -07:00
Will Hawkins 84b9985f5f
[lldb] Fix broken bad-address-breakpoint test
After changing the "fallback" behavior when a user sets a breakpoint
without specifying a module the bad-address-breakpoint test case failed
incorrectly. This patch updates that test case in order to more
thoroughly discover an illegal address and use that as the means for
testing whether a breakpoint set at an illegal address fails to resolve.

Differential revision: https://reviews.llvm.org/D126109
2022-05-26 12:16:11 -07:00
Jason Molenda ea6d0c4b2a One further tweak for realpathing filepath to match dyld
I missed one place I need to realpath the build artifact path,
to make it match the path we get back from dyld.
2022-05-26 11:24:56 -07:00
Jason Molenda bd67468645 Check that a FileSpec has a Directory component before using
A follow on to my patch for https://reviews.llvm.org/D126435
hit by an x86_64 linux bot; I assumed that a FileSpec had a
directory component and checked if the first character was a
'~'.  This was not a valid assumption.
2022-05-26 11:12:37 -07:00
Jason Molenda 8a467284d5 Defer source path remap tilde expansion until source file use
When reading source path remappings out of a dSYM, lldb currently
does tilde expansion -- expanding the tilde-username and checking
that the destination pathname exists, for each dSYM with the path
remappings.  This cost happens during lldb's initial process launch
/ load, an especially perf-sensitive time.  Inside Apple, we have
dSYMs with source path remappings pointing to NFS directories where
these extra stats for every dSYM can be very expensive if the network
is slow.

This patch instead keeps the source path mapping in the original
tilde-username terms and does the tilde expansion when we need
to read a specific source file from one of the modules.  We'll
be stat'ing all of those inodes to load the source file anyway,
so the fact that we do the tilde expansion on every source file
we load, it doesn't cost us significantly.

Differential Revision: https://reviews.llvm.org/D126435
rdar://77091379

(cherry picked from commit c274b6e583)
2022-05-26 11:12:37 -07:00
Jason Molenda 56ac85a20f Revert "Defer source path remap tilde expansion until source file use"
This reverts commit c274b6e583.

The x86_64 debian bot got a failure with this patch,
https://lab.llvm.org/buildbot#builders/68/builds/33078
where
SymbolFile/DWARF/x86/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu1.s
is crashing here -

 #2 0x0000000000425a9f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f57160e9140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
 #4 0x00007f570d911e43 lldb_private::SourceManager::GetFile(lldb_private::FileSpec const&) crtstuff.c:0:0
 #5 0x00007f570d914270 lldb_private::SourceManager::DisplaySourceLinesWithLineNumbers(lldb_private::FileSpec const&, unsigned int, unsigned int, unsigned int, unsigned int, char const*, lldb_private::Stream*, lldb_private::SymbolContextList const*) crtstuff.c:0:0
 #6 0x00007f570da662c8 lldb_private::StackFrame::GetStatus(lldb_private::Stream&, bool, bool, bool, char const*) crtstuff.c:0:0

I don't get a failure here my mac, I'll review this method more
closely tomorrow.
2022-05-26 00:46:54 -07:00
Jason Molenda c274b6e583 Defer source path remap tilde expansion until source file use
When reading source path remappings out of a dSYM, lldb currently
does tilde expansion -- expanding the tilde-username and checking
that the destination pathname exists, for each dSYM with the path
remappings.  This cost happens during lldb's initial process launch
/ load, an especially perf-sensitive time.  Inside Apple, we have
dSYMs with source path remappings pointing to NFS directories where
these extra stats for every dSYM can be very expensive if the network
is slow.

This patch instead keeps the source path mapping in the original
tilde-username terms and does the tilde expansion when we need
to read a specific source file from one of the modules.  We'll
be stat'ing all of those inodes to load the source file anyway,
so the fact that we do the tilde expansion on every source file
we load, it doesn't cost us significantly.

Differential Revision: https://reviews.llvm.org/D126435
rdar://77091379
2022-05-26 00:30:12 -07:00
Jason Molenda 8ee35c5558 Update three tests to realpath paths that we compare to dyld paths
I get to my work directory through a symlink, so the pathnames the
tests get for their build artifacts etc are via that symlink.  There
are three tests which compare those symlink paths to a directory
received from dyld on macOS, which is the actual real pathname.

These tests have always failed for me on my dekstop but I finally
sat down to figure out why. Easy quick fix.
2022-05-26 00:21:44 -07:00
Jason Molenda bef4da4a6a Skip testing of watchpoint hit-count/ignore-count on multithreaded
Skip all watchpoint hit-count/ignore-count tests for multithreaded
API tests for now on arm64 Darwin.

On AArch64, insns that trigger a WP are rolled back and we are
notified.  lldb needs to disable the WP, insn step, re-enable it,
then report it to the user.  lldb only does this full step action
for the "selected thread", and so when a program stops with
multiple threads hitting a stop reason, some of them watchpoints,
any non-selected-thread will not be completed in this way.  But
all threads with the initial watchpoint exception will have their
hit-count/ignore-counts updated.  When we resume execution, the
other threads sitting at the instruction will again execute &
trigger the WP exceptoin again, repeating until we've gone through
all of the threads.

This bug is being tracked in llvm.org/pr49433 and inside apple
in rdar://93863107
2022-05-25 16:05:51 -07:00
Zequan Wu 5c9f3ec4ad [LLDB][NativePDB] Check for missing type info to avoid crash.
NativePDB often assumes that all debug info are available.
This is one step to make it more pervasive.

Differential Revision: https://reviews.llvm.org/D125844
2022-05-25 13:19:27 -07:00
Thomas Preud'homme 8e757c6b50 Fix conversion error to Expected
On Ubuntu 18.04 with GCC 7.5 Intel trace code fails to build due to
failure to convert from
lldb_private::process_linux::IntelPTPerThreadProcessTraceUP to
Expected<lldb_private::process_linux::IntelPTPerThreadProcessTraceUP>.
This commit explicitely marks those unique_ptr values as being moved
which fixes the conversion error.

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D126402
2022-05-25 20:51:14 +01:00
Kazu Hirata 4391625255 [lldb] Fix an unused function warning
This patch fixes:

  .../llvm-project/lldb/source/Host/common/PseudoTerminal.cpp:106:20:
  error: unused function 'use_ptsname' [-Werror,-Wunused-function]
2022-05-25 09:49:05 -07:00
Jonas Devlieghere 436eaf8d32
[lldb] Improve TestAppleSimulatorOSType.py error message
This was inspired by D109336 which got reverted because we didn't want
the test to fail silently. This patch prints a more informative error
message when we fail to parse the simctl output while still failing the
test.

Differential revision: https://reviews.llvm.org/D126217
2022-05-24 17:17:26 -07:00
Jonas Devlieghere f179f403c8
[lldb] Disable modules in Apple-lldb-base
The LLDB website recommends using the CMake caches to build on macOS.
Although modules result in a faster build, this configuration tends to
break occasionally because it's specific to our platform. I don't expect
newcomers to be able to deal with those kind of breakages so don't
enable them by default.
2022-05-24 17:17:14 -07:00
Jeffrey Tan a1d490319a Fix lldb-vscode frame test failure
Previous patch (https://reviews.llvm.org/D126013) added a new "optimized"
attribute to DAP stack frame this caused some tests, like
lldb-vscode/coreFile/TestVSCode_coreFile.py
to fail because the tests explicitly check for all attributes.

To fix the test failure I decided to remove this attribute.

Differential Revision: https://reviews.llvm.org/D126225
2022-05-23 14:04:37 -07:00
Jorge Gorbe Moya f0a61c2ce2 Remove `friend` classes from TypeCategoryMap
As far as I can tell, the only thing those friend classes access is the
`ValueSP` typedef.

Given that this is a map-ish class, with "Map" in its name, it doesn't
seem like a stretch to make `KeyType`, `ValueType` and `ValueSP` public.
More so when the public methods of the class have `KeyType` and
`ValueSP` arguments and clearly `ValueSP` needs to be accessed from the
outside.

`friend` complicates local reasoning about who can access private
members, which is valuable in a class like this that has every method
locking a mutex to prevent concurrent access.

Differential Revision: https://reviews.llvm.org/D126103
2022-05-23 11:31:53 -07:00
Dave Lee 760298adc2 [lldb] Specify aguments of `image list`
Register positional argument details in `CommandObjectTargetModulesList`.

I recently learned that `image list` takes a module name, but the help info
does not indicate this. With this change, `help image list` will show that it
accepts zero or more module names.

This makes it easier to get info about specific modules, without having to
find/grep through the full image list.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D125154
2022-05-23 11:00:48 -07:00
Dave Lee 0da230ff44 [lldb] Improve formatting of dlopen error messages (NFC)
Ensure there's a space between "utility" and "function", and also makes
it easier to grep/search for "utility function".

While making this change, I also re-formatted the other dlopen error messages
(with clang-format). This fix other instances of spaces missing between words,
and makes each of these strings fit a single line, making them greppable.

Differential Revision: https://reviews.llvm.org/D126078
2022-05-23 10:57:40 -07:00
Jeffrey Tan 0fe220a331 Show error message for optimized variables
This fixes an issue that optimized variable error message is not shown to end
users in lldb-vscode.

Differential Revision: https://reviews.llvm.org/D126014
2022-05-23 10:04:58 -07:00
Jeffrey Tan 46c1f77e16 Add [opt] suffix to optimized stack frame in lldb-vscode
To help user identify optimized code This diff adds a "[opt]" suffix to
optimized stack frames in lldb-vscode. This provides consistent experience
as command line lldb.

It also adds a new "optimized" attribute to DAP stack frame object so that
it is easy to identify from telemetry than parsing trailing "[opt]".

Differential Revision: https://reviews.llvm.org/D126013
2022-05-23 10:03:13 -07:00
Jonas Devlieghere c30a8c8083
[lldb] Fix should_skip_simulator_test decorator
Currently simulator tests get skipped when the reported platform is
macosx rather than darwin. Update the decorator to match both.
2022-05-23 09:33:51 -07:00
Muhammad Omair Javaid b876c23604 Revert "[lldb] Consider binary as module of last resort"
This reverts commit a3c3482ceb.
It broke LLDB API test TestBadAddressBreakpoints.py

Differential revision: https://reviews.llvm.org/D124731
2022-05-23 11:19:48 +05:00
Luboš Luňák 8ba1421432 [lldb] fix 'command container' help text 2022-05-21 12:26:42 +02:00
Jim Ingham b369762beb Convert the test file for TestIgnoredExceptions.py to the mach_vm API.
The previous version of this test uses mprotect, and that seemed to be
flakey on older systems.  I converted the test to use the underlying
mach_vm API's.  The test only runs on Darwin anyway, so this is not a
real limitation, and I'm hoping the lower level API's work more
consistently.
2022-05-20 15:16:24 -07:00
Jonas Devlieghere d252d9231c
[lldb] Fix spurious assertion in PrintCommandOutput
When the string passed to PrintCommandOutput doesn't end with a newline,
`written` will exceed `size` and result in an lldbassert.

After 8e776bb660 we don't really need
written anymore and we can check whether `str` is empty instead. This
patch simplifies the code and removes the assert that's no longer
relevant.

Differential revision: https://reviews.llvm.org/D126081
2022-05-20 14:15:01 -07:00
Will Hawkins a3c3482ceb
[lldb] Consider binary as module of last resort
When setting an address breakpoint using a non-section address in lldb
before having ever run the program, the binary itself is not considered
a module. As a result, the breakpoint is unresolved (and never gets
resolved subsequently).

This patch changes that behavior: as a last resort, the binary is
considered as a module when resolving a non-section address breakpoint.

Differential revision: https://reviews.llvm.org/D124731
2022-05-20 14:01:05 -07:00
Jim Ingham 9385a6d6ea Add some diagnostics to diagnose bot-only failures for TestIgnoredExceptions.py
The test for commit bff4673b41 is failing on the
GreenDragon bot but none of us can repro the failure locally.  Adding some logging
to the test failure to help diagnose the issue.
2022-05-20 11:38:37 -07:00
Adrian Prantl f4570ce442 Adapt C++ std::string dataformatter for D125496
https://reviews.llvm.org/D125496 changed the layout of std::string
without updating the LLDB dataformatter. This patch adds code to
recognize the new format.

Differential Revision: https://reviews.llvm.org/D126080
2022-05-20 11:25:42 -07:00
Jonas Devlieghere a1cf154dd4
[lldb] Set correct register number for cpsr (GENERIC_REGNUM_FLAGS)
Report the correct register number (GENERIC_REGNUM_FLAGS) for cpsr. This
fixes TestLldbGdbServer.py on Apple Silicon.

Differential revision: https://reviews.llvm.org/D126076
2022-05-20 09:36:58 -07:00
Jonas Devlieghere 80c836ec55
[lldb] Disable scripted_crashlog_json.test on Apple Silicon
Disable scripted_crashlog_json.test on Apple Silicon until Ismail has
bandwidth to investigate.

rdar://93655633
2022-05-20 08:24:46 -07:00
Jonas Devlieghere b9a30b69d8
[lldb] Update test_software_breakpoint_set_and_remove_work for AS
On Apple Silicon the platform arch is arm64 rather than AArch64.
2022-05-19 21:40:20 -07:00
Jonas Devlieghere ea4864007c
[lldb] Fix 'ptsname_r' is only available on macOS 10.13.4 or newer
A deployment target less than 10.13.4 causes an error saying that
'ptsname_r' is only available on macOS 10.13.4 or newer. The current
logic only checks if the symbol is available and doesn't account for the
deployment target. This patch fixes that by adding an availability
check.

Differential revision: https://reviews.llvm.org/D125995
2022-05-19 21:39:52 -07:00
Med Ismail Bennani 027499a824
[lldb/test] Fix PExpect.launch issue when disabling color support
This patch should fix a bug in PExpect.launch that happened when color
support is not enabled.

In that case, we need to add the `--no-use-colors` flag to lldb's launch
argument list. However, previously, each character to the string was
appended separately to the `args` list. This patch solves that by adding
the whole string to the list.

This should fix the TestIOHandlerResize failure on GreenDragon.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-19 14:47:04 -07:00
David Spickett 068f14f1e4 [lldb] Add --show-tags option to "memory find"
This is off by default. If you get a result and that
memory has memory tags, when --show-tags is given you'll
see the tags inline with the memory content.

```
(lldb) memory read mte_buf mte_buf+64 --show-tags
<...>
0xfffff7ff8020: 00 00 00 00 00 00 00 00 0d f0 fe ca 00 00 00 00 ................ (tag: 0x2)
<...>
(lldb) memory find -e 0xcafef00d mte_buf mte_buf+64 --show-tags
data found at location: 0xfffff7ff8028
0xfffff7ff8028: 0d f0 fe ca 00 00 00 00 00 00 00 00 00 00 00 00 ................ (tags: 0x2 0x3)
0xfffff7ff8038: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ (tags: 0x3 0x4)
```

The logic for handling alignments is the same as for memory read
so in the above example because the line starts misaligned to the
granule it covers 2 granules.

Depends on D125089

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D125090
2022-05-19 14:40:01 +01:00
David Spickett 13e1cf8065 Reland "[lldb] Add --all option to "memory region""
This reverts commit 3e928c4b9d.

This fixes an issue seen on Windows where we did not properly
get the section names of regions if they overlapped. Windows
has regions like:
[0x00007fff928db000-0x00007fff949a0000) ---
[0x00007fff949a0000-0x00007fff949a1000) r-- PECOFF header
[0x00007fff949a0000-0x00007fff94a3d000) r-x .hexpthk
[0x00007fff949a0000-0x00007fff94a85000) r-- .rdata
[0x00007fff949a0000-0x00007fff94a88000) rw- .data
[0x00007fff949a0000-0x00007fff94a94000) r-- .pdata
[0x00007fff94a94000-0x00007fff95250000) ---

I assumed that you could just resolve the address and get the section
name using the start of the region but here you'd always get
"PECOFF header" because they all have the same start point.

The usual command repeating loop used the end address of the previous
region when requesting the next, or getting the section name.
So I've matched this in the --all scenario.

In the example above, somehow asking for the region at
0x00007fff949a1000 would get you a region that starts at
0x00007fff949a0000 but has a different end point. Using the load
address you get (what I assume is) the correct section name.
2022-05-19 13:16:36 +01:00
Med Ismail Bennani 1351a9b19e [lldb/test] Fix failures caused by a previous PExpect.launch change
This should fix the issues introduced by d71d1a9, which skipped all the
test setup commands.

This also fixes the test failures happening in TestAutosuggestion.py.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 21:12:44 -07:00
Med Ismail Bennani fbf0c42294 Revert "[lldb/test] Make some tests as XFAIL while I investigate the issue"
This reverts commit 80589f272c.
2022-05-18 21:12:43 -07:00
Med Ismail Bennani fd25ad5122 Revert 821ee172cd
This reverts commit 821ee172cd, that
landed by mistake.
2022-05-18 19:07:47 -07:00
Med Ismail Bennani 80589f272c
[lldb/test] Make some tests as XFAIL while I investigate the issue
This is very likely to be caused by d71d1a947b.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 18:51:10 -07:00
Med Ismail Bennani 821ee172cd dyld patch
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 18:46:00 -07:00
Med Ismail Bennani 3e54ea0cfa [lldb/crashlog] Fix line entries resolution in interactive mode
This patch subtracts 1 to the pc of any frame above frame 0 to get the
previous line entry and display the right line in the debugger.

This also rephrase some old comment from `48d157dd4`.

rdar://92686666

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 18:22:47 -07:00
Med Ismail Bennani 051a5ae998 [lldb/Core] Fix "sticky" long progress messages
When the terminal window is too small, lldb would wrap progress messages
accross multiple lines which would break the progress event handling
code that is supposed to clear the message once the progress is completed.

This causes the progress message to remain on the screen, sometimes partially,
which can be confusing for the user.

To fix this issue, this patch trims the progress message to the terminal
width taking into account the progress counter leading the message for
finite progress events and also the trailing `...`.

rdar://91993836

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 18:22:46 -07:00
Med Ismail Bennani d71d1a947b [lldb/Test] Add `use_colors` argument to the PExpect.launch wrapper
This patch adds a new `use_colors` argument to the PExpect.launch
method.

As the name suggests, it allows the user to conditionally enable color
support in the debugger, which can be helpful to test functionalities that
rely on that, like progress reporting. It defaults to False.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-18 18:22:46 -07:00
Jim Ingham bff4673b41 Add a darwin platform setting to specify which exceptions debugserver
should not receive as exceptions (some will get converted to BSD
signals instead).  This is really the only stable way to ensure that
a Mach exception gets converted to it's equivalent BSD signal.  For
programs that rely on BSD signal handlers, this has to happen or you
can't even get the program to invoke the signal handler when under
the debugger.

This builds on a previous solution to this problem which required you
start debugserver with the -U flag.  This was not very discoverable
and required lldb be the one to launch debugserver, which is not always
the case.

Differential Revision: https://reviews.llvm.org/D125434
2022-05-18 10:16:11 -07:00
David Spickett 29e556fc2b [lldb] Change implementation of memory read --show-tags option
This does 2 things:
* Moves it after the short options. Which makes sense given it's
  a niche, default off option.
  (if 2 files for one option seems a bit much, I am going to reuse
  them for "memory find" later)
* Fixes the use of repeated commands. For example:
    memory read buf --show-tags
    <shows tags>
    memory read
    <shows tags>

Added tests for the repetition and updated existing help tests.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D125089
2022-05-18 16:49:09 +01:00
David Spickett 00a1258593 [lldb][AArch64] Fix corefile memory reads when there are non-address bits
Previously if you read a code/data mask before there was a valid thread
you would get the top byte mask. This meant the value was "valid" as in,
don't read it again.

When using a corefile we ask for the data mask very early on and this
meant that later once you did have a thread it wouldn't read the
register to get the rest of the mask.

This fixes that and adds a corefile test generated from the same program
as in my previous change on this theme.

Depends on D118794

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D122411
2022-05-18 14:13:42 +01:00
David Spickett d9398a91e2 [lldb] Remove non-address bits from read/write addresses in lldb
Non-address bits are not part of the virtual address in a pointer.
So they must be removed before passing to interfaces like ptrace.

Some of them we get way with not removing, like AArch64's top byte.
However this is only because of a hardware feature that ignores them.

This change updates all the Process/Target Read/Write memory methods
to remove non-address bits before using addresses.

Doing it in this way keeps lldb-server simple and also fixes the
memory caching when differently tagged pointers for the same location
are read.

Removing the bits is done at the ReadMemory level not DoReadMemory
because particualrly for process, many subclasses override DoReadMemory.

Tests have been added for read/write at the command and API level,
for process and target. This includes variants like
Read<sometype>FromMemory. Commands are tested to make sure we remove
at the command and API level.

"memory find" is not included because:
* There is no API for it.
* It already has its own address handling tests.

Software breakpoints do use these methods but they are not tested
here because there are bigger issues to fix with those. This will
happen in another change.

Reviewed By: omjavaid

Differential Revision: https://reviews.llvm.org/D118794
2022-05-18 12:59:34 +01:00
David Spickett 3e928c4b9d Revert "[lldb] Add --all option to "memory region""
This reverts commit 8e648f195c
due to test failures on Windows:
https://lab.llvm.org/buildbot/#/builders/83/builds/19094
2022-05-18 11:57:20 +00:00
David Spickett 8e648f195c [lldb] Add --all option to "memory region"
This adds an option to the memory region command
to print all regions at once. Like you can do by
starting at address 0 and repeating the command
manually.

memory region [-a] [<address-expression>]

(lldb) memory region --all
[0x0000000000000000-0x0000000000400000) ---
[0x0000000000400000-0x0000000000401000) r-x <...>/a.out PT_LOAD[0]
<...>
[0x0000fffffffdf000-0x0001000000000000) rw- [stack]
[0x0001000000000000-0xffffffffffffffff) ---

The output matches exactly what you'd get from
repeating the command. Including that it shows
unmapped areas between the mapped regions.

(this is why Process GetMemoryRegions is not
used, that skips unmapped areas)

Help text has been updated to show that you can have
an address or --all but not both.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D111791
2022-05-18 10:33:39 +00:00
David Spickett 7d8ec4dc44 [lldb] const a couple of getters on MemoryRegionInfo
GetDirtyPageList was being assigned to const & in most places anyway.
If you wanted to change the list you'd make a new one and call
SetDirtyPageList.

GetPageSize is just an int so no issues being const.

Differential Revision: https://reviews.llvm.org/D125786
2022-05-18 09:00:00 +00:00
Walter Erquinigo 1188faa7ab [trace][intelpt] Support system-wide tracing [6] - Break IntelPTCollector into smaller files and minor refactor
IntelPTCollector is very big and has 3 classes in it. It's actually cleaner if each one has its own file. This also gives more visibility to the developer about the different kinds of "tracers" that we have.

Besides that, I'm now restricting the creation of the BinaryData chunks to GetState() instead of having it in different places, which is not very clean, because the gdb-remote protocol should be as restricted as possible.

Differential Revision: https://reviews.llvm.org/D125047
2022-05-17 12:46:54 -07:00
Walter Erquinigo 1637545f68 [trace][intelpt] Support system-wide tracing [5] - Disable/enable per-core tracing based on the process state
When tracing on per-core mode, we are tracing all processes, which means
that after hitting a breakpoint, our process will stop running (thus
producing no more tracing data) but other processes will continue
writing to our trace buffers. This causes a big data loss for our trace.
As a way to remediate this, I'm adding some logic to pause and unpause
tracing based on the target's state. The earlier we do it the better,
however, I'm not adding the trigger at the earliest possible point for
simplicity of this diff. Later we can improve that part.

Differential Revision: https://reviews.llvm.org/D124962
2022-05-17 12:46:54 -07:00
Walter Erquinigo 1f49714d3e [trace][intelpt] Support system-wide tracing [4] - Support per core tracing on lldb-server
This diffs implements per-core tracing on lldb-server. It also includes tests that ensure that tracing can be initiated from the client and that the jLLDBGetState ppacket returns the list of trace buffers per core.

This doesn't include any decoder changes.

Finally, this makes some little changes here and there improving the existing code.

A specific piece of code that can't reliably be tested is when tracing
per core fails due to permissions. In this case we add a
troubleshooting message and this is the manual test:

```
/proc/sys/kernel/perf_event_paranoid set to 1

(lldb) process trace start --per-core-tracing                                         error: perf event syscall failed: Permission denied
 You might need that /proc/sys/kernel/perf_event_paranoid has a value of 0 or -1.
``

Differential Revision: https://reviews.llvm.org/D124858
2022-05-17 12:46:54 -07:00
Walter Erquinigo 26d83a431e [NFC][lldb][trace] Use uint64_t when decoding and enconding json
llvm's json parser supports uint64_t, so let's better use it for the
packets being sent between lldb and lldb-server instead of using int64_t
as an intermediate type, which might be error-prone.
2022-05-17 11:08:04 -07:00
Walter Erquinigo be738c9d1c [lldb-vscode] Fix data race in lldb-vscode when running with ThreadSanitizer
This patch fixes https://github.com/llvm/llvm-project/issues/54768. A ProgressEventReporter creates a dedicated thread that keeps checking whether there are new events that need to be sent to IDE as long as m_thread_should_exit is true. When the VSCode instance is destructed, it will set m_thread_should_exit to false, which caused a data race because at the same time its ProgressEventReporter is reading this value to determine whether it should quit. This fix simply uses mutex to ensure they cannot read and write this value at the same time.

Committed on behalf of PRESIDENT810

Reviewed By: clayborg, wallace

Differential Revision: https://reviews.llvm.org/D125073
2022-05-17 09:11:45 -07:00
Jim Ingham 7afd257ff8 Fix the std::string formatter to report errors in the case where the
string points to unaccessible memory.

The formatter tries to get the data field of the std::string, and to
check whether that fails it just checks that the ValueObjectSP
returned is not empty. But we never return empty ValueObjectSP's to
indicate failure, since doing so would lose the Error object that
tells you why fetching the ValueObject failed.

This patch adds a check for ValueObject::GetError().Success().

I also added a test case for this failure, and reworked the test case
a bit (to use run_to_source_breakpoint). I also renamed a couple of
single letter locals which don't follow the lldb coding conventions.

Differential Revision: https://reviews.llvm.org/D108228
2022-05-17 08:22:30 -07:00
Jason Molenda d2f3b6020f [NFC] Don't bother with unstripped binary w/ dSYM, don't DebugSymbols twice
This patch addresses two perf issues when we find a dSYM on macOS
after calling into the DebugSymbols framework.  First, when we have
a local (probably stripped) binaary, we find the dSYM and we may
be told about the location of the symbol rich binary (probably
unstripped) which may be on a remote filesystem.  We don't need the
unstripped binary, use the local binary we already have.
Second, after we've found the path to the dSYM, save that in the Module
so we don't call into DebugSymbols a second time later on to
rediscover it.  If the user has a DBGShellCommands set, we need to
exec that process twice, serially, which can add up.

Differential Revision: https://reviews.llvm.org/D125616
rdar://84576917
2022-05-16 15:30:39 -07:00
Jonas Devlieghere 9defb3b4b4
[lldb] Prevent underflow in crashlog.py
Avoid a OverflowError (an underflow really) when the pc is zero. This
can happen for "unknown frames" where the crashlog generator reports a
zero pc. We could omit them altogether, but if they're part of the
crashlog it seems fair to display them in lldb as well.

rdar://92686666

Differential revision: https://reviews.llvm.org/D125716
2022-05-16 15:00:36 -07:00
David Spickett 4a94e3801d [lldb][NFC] Simplify GenerateOptionUsage
Once we get into the if block we know the value of only_print_args.
Move some variables closer to point of use.

Depends on D125218

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D125219
2022-05-16 10:57:34 +00:00
David Spickett e473e79cd1 [lldb][NFC] Make cmd a reference in GenerateOptionUsage
Nowhere in lldb do we call this with a null pointer.
If we did, the first line of the function would fault anyway.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D125218
2022-05-16 10:46:56 +00:00
Jonas Devlieghere ae016e4f7c
[lldb] Don't swallow crashlog exceptions
crashlog.py catches every exception in order to format them. This
results in both the exception name as well as the backtrace getting
swallowed.

Here's an example of the current output:

  error: python exception: in method 'SBTarget_ResolveLoadAddress', argument 2 of type 'lldb::addr_t'

Compare this to the output without the custom exception handling:

  Traceback (most recent call last):
    File "[...]/site-packages/lldb/macosx/crashlog.py", line 929, in __call__
      SymbolicateCrashLogs(debugger, shlex.split(command))
    File "[...]/site-packages/lldb/macosx/crashlog.py", line 1239, in SymbolicateCrashLogs
      SymbolicateCrashLog(crash_log, options)
    File "[...]/site-packages/lldb/macosx/crashlog.py", line 1006, in SymbolicateCrashLog
      thread.dump_symbolicated(crash_log, options)
    File "[...]/site-packages/lldb/macosx/crashlog.py", line 124, in dump_symbolicated
      symbolicated_frame_addresses = crash_log.symbolicate(
    File "[...]/site-packages/lldb/utils/symbolication.py", line 540, in symbolicate
      if symbolicated_address.symbolicate(verbose):
    File "[...]/site-packages/lldb/utils/symbolication.py", line 98, in symbolicate
      sym_ctx = self.get_symbol_context()
    File "[...]/site-packages/lldb/utils/symbolication.py", line 77, in get_symbol_context
      sb_addr = self.resolve_addr()
    File "[...]/site-packages/lldb/utils/symbolication.py", line 69, in resolve_addr
      self.so_addr = self.target.ResolveLoadAddress(self.load_addr)
    File "[...]/site-packages/lldb/__init__.py", line 10675, in ResolveLoadAddress
      return _lldb.SBTarget_ResolveLoadAddress(self, vm_addr)
  OverflowError: in method 'SBTarget_ResolveLoadAddress', argument 2 of type 'lldb::addr_t'

This patch removes the custom exception handling and lets LLDB or the
default exception handler deal with it instead.

Differential revision: https://reviews.llvm.org/D125589
2022-05-14 08:58:56 -07:00
Jonas Devlieghere 447c920a8a
[lldb] Remove unused imports from crashlog.py 2022-05-14 08:58:55 -07:00
Med Ismail Bennani 174cf2f747 [lldb/API] Turn SBCompileUnit::GetIndexForLineEntry into FindLineEntryIndex (NFC)
This patch renames the `SBCompileUnit::GetIndexForLineEntry` api to be
an overload of `SBCompileUnit::FindLineEntryIndex`

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-13 18:33:05 -07:00
Jonas Devlieghere a8abb69585
[lldb] Parallelize fetching symbol files in crashlog.py
When using dsymForUUID, the majority of time symbolication a crashlog
with crashlog.py is spent waiting for it to complete. Currently, we're
calling dsymForUUID sequentially when iterating over the modules. We can
drastically cut down this time by calling dsymForUUID in parallel. This
patch uses Python's ThreadPoolExecutor (introduced in Python 3.2) to
parallelize this IO-bound operation.

The performance improvement is hard to benchmark, because even with an
empty local cache, consecutive calls to dsymForUUID for the same UUID
complete faster. With warm caches, I'm seeing a ~30% performance
improvement (~90s -> ~60s). I suspect the gains will be much bigger for
a cold cache.

dsymForUUID supports batching up multiple UUIDs. I considered going that
route, but that would require more intrusive changes. It would require
hoisting the logic out of locate_module_and_debug_symbols which we
explicitly document [1] as a feature of Symbolication.py to locate
symbol files.

[1] https://lldb.llvm.org/use/symbolication.html

Differential reviison: https://reviews.llvm.org/D125107
2022-05-13 12:25:41 -07:00
Med Ismail Bennani 2d7b49f389 [lldb/test] Skip TestCppIncompleteTypeMembers.py for -gmodules on macOS
Following 8b9caad8eb, this only skips
TestCppIncompleteTypeMembers.py on macOS if we test with `-gmodules` enabled.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-12 17:12:13 -07:00
Jim Ingham 2a21700bc5 In 92eaad2dd7 I made it possible to run
a debug session with only a remote path to the file you are debugging
using the SB API's. This patch makes it possible to do this using
target create --remote-file <some_path> without supplying a local file
as well.

Prior to this change we errored out saying that we haven't implemented
copying the binary back from the remote. I didn't implement the copy
back (in the case I'm interested in - iOS debugging - we don't
actually have a way for lldb to do that). This patch doesn't impede
doing that, I just didn't need it. I think for some object file
formats debugging w/o the binary file is hard because of what doesn't
get mapped in. I didn't try to arbitrate that, I'm assuming anybody
who has to do this knows what they are going to get.

If there's a connected platform that can check that the remote file
exists, it will do so, otherwise we trust the user's input - if it
isn't there the process launch is going to fail with no-such-file so
it will be pretty clear what went wrong.

Differential Revision: https://reviews.llvm.org/D124947
2022-05-12 17:11:01 -07:00
Med Ismail Bennani 8b9caad8eb [lldb/test] Skip TestCppIncompleteTypeMembers.py on Darwin (NFC)
This skips `TestCppIncompleteTypeMembers.py` on Darwin platforms since
it requires `-flimit-debug-info` which is not supported.

This should fix the Green Dragon bot test run:

https://green.lab.llvm.org/green/job/lldb-cmake/43678

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-12 16:54:23 -07:00
Med Ismail Bennani a6926d5761 [lldb/API] Add SBCompileUnit::GetIndexForLineEntry method to SB API
This patch adds a new `GetIndexForLineEntry` method to the `SBCompileUnit`
class. As the name suggests, given an `SBLineEntry` object, this will
return the line entry index within a specific compile unit.

This method can take a `exact` boolean that will make sure that the
provided line entry matches perfectly another line entry in the compile unit.

rdar://47450887

Differention Revision: https://reviews.llvm.org/D125437

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-05-12 16:54:22 -07:00
Tobias Ribizel b1aed14bfe [llvm][lldb] use FindLibEdit.cmake everywhere
Currently, LLVM's LineEditor and LLDB both use libedit, but find them in different (inconsistent) ways.
This causes issues e.g. when you are using a locally installed version of libedit, which will not be used
by clang-query, but by lldb if picked up by FindLibEdit.cmake

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D124673
2022-05-12 15:59:41 -07:00
Jim Ingham c6799d9843 Revision 3339000e0b caused the Language
plugin to get queried earlier on in the startup, so that for .s files
we call the language "unknown" not "not-loaded".  This test was checking
against that string, so I fixed it for the change.
2022-05-12 14:32:00 -07:00
Jim Ingham 3339000e0b We don't require users to type out the full context of a function, for
symbol name matches. Instead, we extract the incoming path's base
name, look up all the symbols with that base name, and then compare
the rest of the context that the user provided to make sure it
matches. However, we do this comparison using just a strstr. So for
instance:

break set -n foo::bar

will match not only "a::foo::bar" but "notherfoo::bar". The former is
pretty clearly the user's intent, but I don't think the latter is, and
results in breakpoints picking up too many matches.

This change adds a Language::DemangledNameContainsPath API which can
do a language aware match against the path provided. If the language
doesn't provide this we fall back to the strstr (though that's changed
to StringRef::contains in the patch).

Differential Revision: https://reviews.llvm.org/D124579
2022-05-12 12:39:28 -07:00
Greg Clayton 91d5bfdb79 Add "indexedVariables" to variables with lots of children.
Prior to this fix if we have a really large array or collection class, we would end up always creating all of the child variables for an array or collection class. If the number of children was very high this can cause delays when expanding variables. By adding the "indexedVariables" to variables with lots of children, we can keep good performance in the variables view at all times. This patch will add the "indexedVariables" key/value pair to any "Variable" JSON dictionairies when we have an array of synthetic child provider that will create more than 100 children.

We have to be careful to not call "uint32_t SBValue::GetNumChildren()" on any lldb::SBValue that we use because it can cause a class, struct or union to complete the type in order to be able to properly tell us how many children it has and this can be expensive if you have a lot of variables. By default LLDB won't need to complete a type if we have variables that are classes, structs or unions unless the user expands the variable in the variable view. So we try to only get the GetNumChildren() when we have an array, as this is a cheap operation, or a synthetic child provider, most of which are for showing collections that typically fall into this category. We add a variable reference, which indicates that something can be expanded, when the function "bool SBValue::MightHaveChildren()" is true as this call doesn't need to complete the type in order to return true. This way if no one ever expands class variables, we don't need to complete the type.

Differential Revision: https://reviews.llvm.org/D125347
2022-05-11 16:17:57 -07:00
Jim Ingham 63865e1fce Add the "sent break" message to the "gdb-remote packets" channel
It was originally only in "gdb-remote process" but it is convenient to
also have it come as part of gdb-remote packets.
2022-05-10 13:28:50 -07:00
Walter Erquinigo 285b39a31e Revert "[NFC][lldb][trace] Use uint64_t when decoding and enconding json"
This reverts commit 9d2dd6d762.

Reverting because this exposes an issue in the uint64_t json parser.
2022-05-09 22:47:05 -07:00
Walter Erquinigo 9d2dd6d762 [NFC][lldb][trace] Use uint64_t when decoding and enconding json
llvm's json parser supports uint64_t, so let's better use it for the
packets being sent between lldb and lldb-server instead of using int64_t
as an intermediate type, which might be error-prone.
2022-05-09 21:55:43 -07:00
Walter Erquinigo b6bb9e7d61 [lldb] Fix 7b73de9ec2
It turns out that the issue in
    https://lab.llvm.org/buildbot/#/builders/17/builds/21754 is that a
    size_t is attempted to be used interchangeably with uint64_t.
2022-05-09 21:29:00 -07:00
Walter Erquinigo c4172c751a [lldb] Fix 7b73de9ec2
It turns out that the issue in
https://lab.llvm.org/buildbot/#/builders/17/builds/21754 is that a
size_t is attempted to be used interchangeably with uint64_t.
2022-05-09 21:12:11 -07:00
Walter Erquinigo 909a2e3c88 [lldb] Fix 7b73de9ec2
This commit causes
https://lab.llvm.org/buildbot/#/builders/17/builds/21743 to fail
seemingly because of bad handling of the PERF_ATTR_SIZE_VER5 symbol.

This patch tries to handle better the absence of this symbol.
2022-05-09 21:02:40 -07:00
Greg Clayton 879a47a55f Add the ability to debug through an exec into ld
A previous commit enabled LLDB to be able to debug a program launched via ld: https://reviews.llvm.org/D108061.

This commit adds the ability to debug a program launched via ld when it happens during an exec into the dynamic loader. There was an issue where after the exec we would locate the rendezvous structure right away but it didn't contain any valid values and we would try to set the dyanamic loader breakpoint at address zero. This patch fixes that and adds a test.

Differential Revision: https://reviews.llvm.org/D125253
2022-05-09 16:07:40 -07:00
Walter Erquinigo 7b73de9ec2 [trace][intelpt] Support system-wide tracing [3] - Refactor IntelPTThreadTrace
I'm refactoring IntelPTThreadTrace into IntelPTSingleBufferTrace so that it can
both single threads or single cores. In this diff I'm basically renaming the
class, moving it to its own file, and removing all the pieces that are not used
along with some basic cleanup.

Differential Revision: https://reviews.llvm.org/D124648
2022-05-09 16:05:26 -07:00
Walter Erquinigo b8d1776fc5 [trace][intelpt] Support system-wide tracing [2] - Add a dummy --per-core-tracing option
This updates the documentation of the gdb-remote protocol, as well as the help messages, to include the new --per-core-tracing option.

Differential Revision: https://reviews.llvm.org/D124640
2022-05-09 16:05:26 -07:00
Pavel Labath a49d5e976e [lldb/test] Remove superfluous -std=c++11 from tests
We default to that anyway. It does not work on windows, and since
ac7747e, the flag actually takes effect.
2022-05-09 20:04:14 +02:00
Pavel Labath ac7747ef28 [lldb/test] Append CXXFLAGS_EXTRAS last in Makefile.rules
This matches what we do with CFLAGS, and it started to matter
8abfa5119a, which added some -std=-apending code.
2022-05-09 19:26:29 +02:00
Pavel Labath 8abfa5119a [lldb/test] Fix TestCppIncompleteTypeMembers.py
modify the Makefile.rules line which was interfering with the
target-specific variable values.
2022-05-09 17:11:57 +02:00
Sigurur sgeirsson fc440f27cd Filter non-external static members from SBType::GetFieldAtIndex.
See [[ https://github.com/llvm/llvm-project/issues/55040 | issue 55040 ]] where static members of classes declared in the anonymous namespace are incorrectly returned as member fields from lldb::SBType::GetFieldAtIndex(). It appears that attrs.member_byte_offset contains a sentinel value for members that don't have a DW_AT_data_member_location.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D124409
2022-05-09 12:34:13 +02:00
Pavel Labath ae7fe65cf6 [lldb/DWARF] Fix linking direction in CopyUniqueClassMethodTypes
IIUC, the purpose of CopyUniqueClassMethodTypes is to link together
class definitions in two compile units so that we only have a single
definition of a class. It does this by adding entries to the die_to_type
and die_to_decl_ctx maps.

However, the direction of the linking seems to be reversed. It is taking
entries from the class that has not yet been parsed, and copying them to
the class which has been parsed already -- i.e., it is a very
complicated no-op.

Changing the linking order allows us to revert the changes in D13224
(while keeping the associated test case passing), and is sufficient to
fix PR54761, which was caused by an undesired interaction with that
patch.

Differential Revision: https://reviews.llvm.org/D124370
2022-05-09 11:47:55 +02:00
Pavel Labath fa593b079b Revert "[lldb] parallelize calling of Module::PreloadSymbols()"
This reverts commit b7d807dbcf -- it
breaks TestMultipleDebuggers.py.
2022-05-09 11:11:01 +02:00
Sam McCall 6ed81abec2 Fix LLDB test broken by 499d0b96cb 2022-05-06 17:09:02 +02:00
Sam McCall 499d0b96cb [clang] createInvocationFromCommandLine -> createInvocation, delete former. NFC
(Followup from 40c13720a4)

Differential Revision: https://reviews.llvm.org/D125012
2022-05-06 16:21:48 +02:00
David Spickett 0dfafa4892 [lldb] Correct hex digit regex in some tests
"A-f" -> "A-F"
2022-05-06 09:28:21 +00:00
Jason Molenda 2be791e32a Insert crashing stack frame when call to null func ptr
On arm64 targets, when the crashing pc is 0, the caller
frame can be found by looking at $lr, but the crash
reports don't use that trick to show the actual crashing
frame.  This patch adds that stack frame that lldb shows.

Also fix an issue where some register names were printed
as having a prefix of 'None'.

Differential Revision: https://reviews.llvm.org/D125042
rdar://92631787
2022-05-05 17:55:22 -07:00
Jason Molenda b6388e4a00 Decr return pc mid-stack when picking UnwindPlan row
When picking the UnwindPlan row to use to backtrace,
off of the zeroth frame, decrement the return pc so
we're in the address range of the call instruction.
If this is a noretrun function call, the instruction
at the "return address" is likely an entirely different
basic block with possibly very different unwind rules,
and this can cause the backtrace to be incorrect.

Differential Revision: https://reviews.llvm.org/D124957
rdar://84651805
2022-05-05 14:18:21 -07:00
Alexandre Perez eb3136f022 Fix debugserver translation check
Currently, debugserver has a test to check if it was launched in
translation. The intent was to cover the case where an x86_64
debugserver attempts to control an arm64/arm64e process, returning
an error. However, this check also covers the case where users
are attaching to an x86_64 process, exiting out before attempting
to hand off control to the translated debugserver at
`/Library/Apple/usr/libexec/oah/debugserver`.

This diff delays the debugserver translation check until after
determining whether to hand off control to
`/Library/Apple/usr/libexec/oah/debugserver`. Only when the
process is not translated and thus has not been handed off do we
check if the debugserver is translated, erroring out in that case.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D124814
2022-05-05 11:31:23 -07:00
serge-sans-paille f416e57339 [lldb] Fix ppc64 detection in lldb
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 f114f00948 with a new test
setup that doesn't involves (unsupported) corefiles.

Differential Revision: https://reviews.llvm.org/D124760
2022-05-05 09:22:02 +02:00
Jason Molenda a6553d97df Remove expected fail for TestStepNoDebug on AArch64
My fix in https://reviews.llvm.org/D124492 should fix
this - I got an "unexpected pass" failure from an
Aarch64 Ubuntu bot when I landed my fix.
2022-05-04 15:28:02 -07:00
Jason Molenda df552edb08 Update the CFA to use $sp when $fp is restored on arm64
In UnwindAssemblyInstEmulation we correctly recognize when a LDP
restores the fp & lr in an epilogue, and mark them as having the
caller's contents now, but we don't update the CFA register rule
at that point to indicate that the CFA is now calculated in terms
of $sp.  This doesn't impact the backtrace because the register
contents are all <same> now, but it can confuse the stepper when
the StackID changes mid-epilogue.

Differential Revision: https://reviews.llvm.org/D124492
rdar://92064415
2022-05-04 14:54:17 -07:00
Luboš Luňák b7d807dbcf [lldb] parallelize calling of Module::PreloadSymbols()
If LLDB index cache is enabled and everything is cached, then loading of debug
info is essentially single-threaded, because it's done from PreloadSymbols()
called from GetOrCreateModule(), which is called from a loop calling
LoadModuleAtAddress() in DynamicLoaderPOSIXDYLD. Parallelizing the entire
loop could be unsafe because of GetOrCreateModule() operating on a module
list, so instead move only the PreloadSymbols() call to Target::ModulesDidLoad()
and parallelize there, which should be safe.

This may greatly reduce the load time if the debugged program uses a large
number of binaries (as opposed to monolithic programs where this presumably
doesn't make a difference). In my specific case of LibreOffice Calc this reduces
startup time from 6s to 2s.

Differential Revision: https://reviews.llvm.org/D122975
2022-05-04 19:58:25 +02:00
Aaron Ballman 2df9bd30e4 Do not rely on implicit int for this test
This should address failing test bots:
https://lab.llvm.org/buildbot/#/builders/68/builds/31828
2022-05-04 09:07:57 -04:00
Aaron Ballman 6234313c6d Fix failing buildbot for lldb
This should address the issue found by:
https://lab.llvm.org/buildbot/#/builders/68/builds/31827
2022-05-04 08:42:52 -04:00
Luboš Luňák 20048f3150 [lldb] use one shared ThreadPool and task groups
As a preparation for parallelizing loading of symbols (D122975),
it is necessary to use just one thread pool to avoid using
a thread pool from inside a task of another thread pool.

Differential Revision: https://reviews.llvm.org/D123226
2022-05-04 06:18:20 +02:00
Weverything 3dd00461f9 [trace][intelpt] Fix out-of-bounds access.
The StringRef single argument constructor expects a null-terminated
string.  Explicitly pass the size to prevent reading pass the end
of the array.
2022-05-03 16:07:58 -07:00
Jonas Devlieghere b945b62cf3
[lldb] Add a function to check if lldb is running in an interactive session
This patch adds a function to check if lldb is running in an interactive
debug session. Currently this API only works on macOS. It's expected to
be used in combination with Host::OpenFileInExternalEditor.

Differential revision: https://reviews.llvm.org/D124872
2022-05-03 15:11:57 -07:00
Jonas Devlieghere 3d08c778c0
[lldb] Session transcript should use the async debugger streams
When writing out the session transcript, print output to the
asynchronous debugger stream to prevent it from potentially interleaving
with other output.

Differential revision: https://reviews.llvm.org/D124873
2022-05-03 15:11:57 -07:00
Dave Lee 2f9fc576be [lldb] Add setting for max depth of value object printing (NFC)
This adds a setting (`target.max-children-depth`) that will provide a default value for the `--depth` flag used by `expression` and `frame variable`.

The new setting uses the same default that's currently fixed in source: `UINT32_MAX`.

This provides two purposes:

1. Allowing downstream forks to provide a customized default.
2. Allowing users to set their own default.

Following `target.max-children-count`, a warning is emitted when the max depth is reached. The warning lets users know which flags or settings they can customize. This warning is shown only when the limit is the default value.

rdar://87466495

Differential Revision: https://reviews.llvm.org/D123954
2022-05-03 10:39:42 -07:00
David Spickett cf05de7168 [lldb][NFC] Refactor printing of short options in help
Instead of building a set twice for optional and required,
build a set for each while walking the options once.

Then take advantage of set being sorted meaning we don't
have to enforce the upper/lower order ourselves.

Just cleaned up the formatting on the later loops.
Combined the if conditions and used a single line if.

Depends on D123501

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D123502
2022-05-03 15:18:39 +00:00
David Spickett 61f2d30746 [lldb][NFC] Simplify part of Options::GenerateOptionUsage
Use llvm::enumerate, remove an unused arg name stream and
replace repeated uses of indexing to get the option def.

We could use map instead of multimap but I'm not 100% that
would be NFC. All short options should be unique in theory.

Depends on D123500

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D123501
2022-05-03 14:32:26 +00:00
David Spickett ca0b416659 [lldb][NFC] Add more tests for GenerateOptionsUsage
This adds a few targeted tests to make sure that when refactoring
this function later I don't break these properties.

Some are tested in passing elsewhere but this makes it more
obvious what went wrong when it fails.

This doesn't cover everything the function does, I couldn't
find any examples that would exercise some of the code.

Reviewed By: jingham

Differential Revision: https://reviews.llvm.org/D123500
2022-05-03 13:40:14 +00:00
David Spickett 7667d80594 Revert "[lldb] Fix ppc64 detection in lldb"
This reverts commit f114f00948.

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 13:24:10 +00:00
serge-sans-paille f114f00948 [lldb] Fix ppc64 detection in lldb
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
2022-05-03 12:17:23 +02:00
Pavel Labath 51e72570d7 [lldb] Fix nondeterminism in DWARFIndexCachingTest
The entries in the input map need to be sorted as well, as there's no
guarantee that the entries (ConstStrings) will be inserted in the proper
order.
2022-05-03 10:28:47 +02:00
Jonas Devlieghere e53019a8ff
[lldb] Make GetSharedModuleWithLocalCache consider the device support directory
Make GetSharedModuleWithLocalCache consider the device support
directory. In the past we only needed the device support directory to
debug remote processes. Since the introduction of Apple Silicon and
Rosetta this stopped being true.

When debugging a Rosetta process on macOS we need to consider the
Rosetta expanded shared cache. This patch and it dependencies move that
logic out of PlatfromRemoteDarwinDevice into a new abstract class called
PlatfromDarwinDevice. The new platform sit in between PlatformDarwin and
PlatformMacOSX and PlatformRemoteDarwinDevice and has all the necessary
logic to deal with the device support directory.

Technically I could have moved everything in PlatfromDarwinDevice into
PlatfromDarwin but decided that this logic is sufficiently self
contained that it warrants its own abstraction.

rdar://91966349

Differential revision: https://reviews.llvm.org/D124801
2022-05-02 21:07:11 -07:00
Jonas Devlieghere 322b413041
[lldb] Move GetSharedModuleWithLocalCache to PlatformDarwinDevice (NFC)
Refactoring in preparation of D124801.

Differential revision: https://reviews.llvm.org/D124800
2022-05-02 17:34:40 -07:00
Jonas Devlieghere 41c0ff1e74
[lldb] Hoist device support out of PlatformRemoteDarwinDevice (NFC)
Refactoring in preparation of D124801.

Differential revision: https://reviews.llvm.org/D124799
2022-05-02 17:34:40 -07:00
Jonas Devlieghere d0067738e0
[lldb] Remove unused PlatformRemoteDarwinDevice::FindFileInAllSDKs
As far as I can tell this function is unused both upstream and
downstream.
2022-05-02 17:34:39 -07:00
Jonas Devlieghere d75cc08593
[lldb] Remove PlatformRemoteMacOSX::GetFileWithUUID overload (NFC)
There's no reason PlatformRemoteMacOSX has to override GetFileWithUUID.
2022-05-02 17:34:36 -07:00
Walter Erquinigo 5de0a3e9da [trace][intelpt] Support system-wide tracing [1] - Add a method for accessing the list of logical core ids
In order to open perf events per core, we need to first get the list of
core ids available in the system. So I'm adding a function that does
that by parsing /proc/cpuinfo. That seems to be the simplest and most
portable way to do that.

Besides that, I made a few refactors and renames to reflect better that
the cpu info that we use in lldb-server comes from procfs.

Differential Revision: https://reviews.llvm.org/D124573
2022-05-02 08:48:49 -07:00
Jason Molenda 9c8179f9ce LocationListLookup test case failing on lldb-arm-ubuntu
Skip on linux+arm for now until I can try to repo the setup of the
lldb-arm-ubuntu bot.  The name of the binary in argv[0] was not
able to be retrieved here; if the compiler's codegen had it stored
in a caller saved register, because it's not needed at this point,
it may not be retreivable.
2022-04-29 15:00:20 -07:00
Jason Molenda 6e56c4961a Decr pc when looking for DWARF loc list entry mid-stack
When looking for a variable location in a DWARF location list,
we search the list of ranges to find one that includes the pc.
With a function mid-stack, the "pc" is the return pc instead of
the call instruction, and in optimized code this can be another
function or a different basic block (with different variable
locations).  Back up the "pc" value mid-stack to find the correct
location list entry.

Differential Revision: https://reviews.llvm.org/D124597
rdar://63903416
2022-04-29 14:34:06 -07:00
Martin Storsjö 2a84a86184 [lldb] Fix initialization of LazyBool/bool variables m_overwrite/m_overwrite_lazy. NFCI.
This silences a GCC warning after
1f7b58f2a5 / D122680:

lldb/source/Commands/CommandObjectCommands.cpp:1650:22: warning: enum constant in boolean context [-Wint-in-bool-context]
 1650 |   bool m_overwrite = eLazyBoolCalculate;
      |                      ^~~~~~~~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D123204
2022-04-29 21:33:37 +03:00
Greg Clayton 268089b6ac Fix the encoding and decoding of UniqueCStringMap<T> objects when saved to cache files.
UniqueCStringMap<T> objects are a std::vector<UniqueCStringMap::Entry> objects where the Entry object contains a ConstString + T. The values in the vector are sorted first by ConstString and then by the T value. ConstString objects are simply uniqued "const char *" values and when we compare we use the actual string pointer as the value we sort by. This caused a problem when we saved the symbol table name indexes and debug info indexes to disk in one process when they were sorted, and then loaded them into another process when decoding them from the cache files. Why? Because the order in which the ConstString objects were created are now completely different and the string pointers will no longer be sorted in the new process the cache was loaded into.

The unit tests created for the initial patch didn't catch the encoding and decoding issues of UniqueCStringMap<T> because they were happening in the same process and encoding and decoding would end up createing sorted UniqueCStringMap<T> objects due to the constant string pool being exactly the same.

This patch does the sort and also reserves the right amount of entries in the UniqueCStringMap::m_map prior to adding them all to avoid doing multiple allocations.

Added a unit test that loads an object file from yaml, and then I created a cache file for the original file and removed the cache file's signature mod time check since we will generate an object file from the YAML, and use that as the object file for the Symtab object. Then we load the cache data from the array of symtab cache bytes so that the ConstString "const char *" values will not match the current process, and verify we can lookup the 4 names from the object file in the symbol table.

Differential Revision: https://reviews.llvm.org/D124572
2022-04-29 11:31:47 -07:00
Jim Ingham aa7470a1b3 Add a paragraph showing how to use container commands.
Differential Revision: https://reviews.llvm.org/D124028
2022-04-29 11:11:52 -07:00
Jim Ingham dca2bc4081 Add a mutex to the ThreadPlanStackMap class.
We've seen very occasional crashes that we can only explain by
simultaneous access to the ThreadPlanStackMap, so I'm adding a
mutex to protect it.

Differential Revision: https://reviews.llvm.org/D124029
2022-04-29 11:07:22 -07:00
Dimitry Andric 7abfaa0a81 [lldb] Define LLDB_VERSION_PATCH correctly
In commit ccf1469a4c lldb got its own generated Version.inc file, with
`LLDB_VERSION` macros. However, it used `LLDB_VERSION_PATCHLEVEL`
instead of the actually correct `LLDB_VERSION_PATCH`. Correct this.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D124672
2022-04-29 19:29:51 +02:00
David Spickett f8463da4a3 [lldb] Allow EXE or exe in toolchain-msvc.test
I suspect that one of link or cl is found by shutil.which
and one isn't, hence the case difference. It doesn't really
matter for what the test is looking for.
2022-04-29 12:22:33 +00:00
David Spickett cacaa445c3 Reland "[lldb] Use shutil.which in Shell tests find_executable"
This reverts commit d9247cc848.

With the Windows tests updated to expect .EXE suffixes. This changed
because shutil.which uses PATHEXT which will contain, amongst others,
"EXE".

Also I noticed the "." in ".exe" was the wildcard dot not literal
dot so I've escaped those.
2022-04-29 11:25:09 +00:00
David Spickett d9247cc848 Revert "[lldb] Use shutil.which in Shell tests find_executable"
This reverts commit 713752610e.

Some test output needs updating for Windows builders:
https://lab.llvm.org/buildbot/#/builders/83/builds/18356
2022-04-29 11:02:59 +00:00
David Spickett 713752610e [lldb] Use shutil.which in Shell tests find_executable
In build.py we have our own find_executable that looks
a lot like the distutils one that I switched to shutil.which.

This find_executable isn't quite the same as shutil.which
so I've refactored it to call that in the correct way.

Note that the path passed to shutil.which is in the form that
PATH would be, meaning separators are allowed.
```
>>> shutil.which("gcc", path="/home/david.spickett:/bin")
'/bin/gcc'
```

We just need to make sure it doesn't ignore the existing PATH
and normalise the result if it does find the binary.

The .exe extension is automatically added to the binary name
if we are on Windows.

Depends on D124601

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D124604
2022-04-29 10:01:26 +00:00
David Spickett 14869bd2df [lldb] Use shutil.which instead of distutils find_executable
distutils is deprecated and shutil.which is the suggested
replacement for this function.

https://peps.python.org/pep-0632/#migration-advice
https://docs.python.org/3/library/shutil.html#shutil.which

It was added in Python3.3 but given that we're already using
shutil.which elsewhere I think this is ok/no worse than before.

We do have our own find_executable in lldb/test/Shell/helper/build.py
but I'd rather leave that as is for now. Also we have our own versions
of which() but again, a change for another time.

This work is part of #54337.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D124601
2022-04-29 08:41:34 +00:00
Jonas Devlieghere 02c2b472b5
[lldb] Remove ConnectionFileDescriptorTest.Connectv(4|6)
These tests are timing out on the bots.
2022-04-28 15:40:21 -07:00
Jonas Devlieghere 9aa6a47973
[lldb] Fix crash when launching in terminal
This patch fixes a crash when using process launch -t to launch the
inferior from a TTY. The issue is that on Darwin, Host.mm is calling
ConnectionFileDescriptor::Connect without a socket_id_callback_type. The
overload passes nullptr as the function ref, which gets called
unconditionally as the socket_id_callback.

One potential way to fix this is to change all the lambdas to include a
null check, but instead I went with an empty lambda.

Differential revision: https://reviews.llvm.org/D124535
2022-04-28 14:39:28 -07:00
Jonas Devlieghere f6b7fd20a5
[lldb] Remove patch reject file (.rej) 2022-04-28 08:16:26 -07:00
David Spickett b809c4cdb7 [lldb] Add FixAnyAddress to ABI plugins
FixAnyAddress is to be used when we don't know or don't care
whether we're fixing a code or data address.

By using FixAnyAddress over the others, you document that no
specific choice was made.

On all existing platforms apart from Arm Thumb, you could use
either FixCodeAddress or FixDataAddress and be fine. Up until
now I've chosen to use FixDataAddress but if I had
chosen to use FixCodeAddress that would have broken Arm Thumb.

Hence FixAnyAddress, to give you the "safest" option when you're
in generic code.

Uses of FixDataAddress in memory region code have been changed
to FixAnyAddress. The functionality is unchanged.

Reviewed By: omjavaid, JDevlieghere

Differential Revision: https://reviews.llvm.org/D124000
2022-04-28 14:57:40 +01:00
Pavel Labath 0cbad66354 [lldb/DWARF] Fix a typo in 57f99d0dc3
The lambda should take a reference argument.
2022-04-28 15:11:00 +02:00
Pavel Labath 57f99d0dc3 [lldb] Reduce duplication in DWARFASTParserClang::CopyUniqueClassMethodTypes
Use lambdas to replace identical bits of code.
2022-04-28 10:58:54 +02:00
Jonas Devlieghere 5205c17749
[lldb] Fix escaping when launching in terminal with AppleScript
Fix escaping when launching in terminal with AppleScript. The invocation
we're building up is wrapped in single quotes when passed to bash and
wrapped in double quotes for AppleScript.

Here's an example invocation with the new escaping:

  tell application "Terminal"
    activate
          do script "/bin/bash -c 'arch -arch arm64 'darwin-debug'
            --unix-socket=/tmp/dL2jSh --arch=arm64 --working-dir
            \"/private/tmp/with spaces\" --disable-aslr --  \"foo\"
            \"bar\" \"baz\" ; echo Process exited with status $?';exit"
  end tell

Previously we were using unescaped single quotes which resulted in the
whole bash invocation being passed in pieces. That works most of the
time but breaks when you have a space in your current working directory
for example.

rdar://91870763

Differential revision: https://reviews.llvm.org/D124568
2022-04-27 16:37:42 -07:00
David Blaikie 0da640cb87 DWP parsing: Use the index by hash when available
Rather than looking up by offset - actually use the hash table to
perform faster lookup where possible. (for DWARFv4 DWP compilation units
the hash isn't in the header - it's in the root DIE, but to parse the
DIE you need the abbrev section and to get the abbrev section you need
the index - so in that case lookup by offset is required)
2022-04-27 21:46:27 +00:00
Zequan Wu afd639071b [LLDB][NativePDB] Minor fix ParseInlinesite.
- Don't reset cur_line_offset to llvm::None when we don't have next_line_offset, because we may need to reuse it in new range after a code end.
- Don't use CombineConsecutiveEntriesWithEqualData for inline_site_sp->ranges, because that will combine consecutive entries with same data in the vector regardless of the entry's range. Originally, I thought that it only combine consecutive entries if adjacent entries' ranges are adjoining or intersecting with each other.
2022-04-27 10:56:03 -07:00
Jonas Devlieghere 0e9af88b70
Remove Python 2 checks from the test suite
We dropped downstream support for Python 2 in the previous release. Now
that we have branched for the next release the window where this kind of
change could introduce conflicts is closing too. Remove Python 2 checks
from the test suite.

Differential revision: https://reviews.llvm.org/D124429
2022-04-27 08:26:26 -07:00
Jonas Devlieghere 9053767330
Remove Python 2 support from the ScriptInterpreter plugin
We dropped downstream support for Python 2 in the previous release. Now
that we have branched for the next release the window where this kind of
change could introduce conflicts is closing too. Start by getting rid of
Python 2 support in the Script Interpreter plugin.

Differential revision: https://reviews.llvm.org/D124429
2022-04-27 08:26:25 -07:00
Pavel Labath eeaa3b5478 [lldb] Remove sanity check from TestWithLimitDebugInfo
The trick with opening the .o file does not work on arm (unhandled
relocations), and I can't think of a quick fix for that.
2022-04-27 16:01:54 +02:00
Pavel Labath 089a1d9deb [lldb] Fix TestWithLimitDebugInfo.py
The test was broken (in the sense that it was not testing what it was
supposed to test) in two ways:
- a Makefile refactor caused it to stop being built with
  -flimit-debug-info
- clang's constructor homing changed the "home" of the type

This patch fixes the Makefile, and modifies the source code to produce
the same result with both type homing strategies. Due to constructor
homing I had to use a different implicitly-defined function for the test
-- I chose the assignment operator.

I also added some sanity checks to the test to ensure that the test is
indeed operating on limited debug info.
2022-04-27 15:08:58 +02:00
Pavel Labath f513b5fc47 [lldb] Make test names unique 2022-04-27 15:08:58 +02:00
Jason Molenda a2681c4330 Don't push null ExecutionContext on CommandInterp exectx stack
The driver can push a null ExecutionContext on to this stack,
and later calls to SBCommandInterpreter::HandleCommand which
don't specify an ExecutionContext can pull an entry from the
stack, resulting in settings that aren't applied.

Differential Revision: https://reviews.llvm.org/D111209
rdar://81489207
2022-04-26 18:32:18 -07:00
Jeffrey Tan 0ffcec418e Fix missing import for test
The last fix missed an import in one test file causing skipIfWindows attribute
can't be recognized.
I feel embarrassed to miss it. I have run all tests on Mac to make sure them
passing in this patch.

Differential Revision: https://reviews.llvm.org/D124479
2022-04-26 16:40:45 -07:00
Jeffrey Tan d738d4717f Disable symbol on-demand feature for Windows
Symbol on-demand feature is never tested on Windows so it is not a surprise
that we are getting Buildbot failure from Windows:
https://lab.llvm.org/buildbot/#/builders/83/builds/18228

This patch disables symbol on-demand feature on Windows. I will find a Windows
machine to test and re-enable symbol on-demand feature as follow-up.

Differential Revision: https://reviews.llvm.org/D124471
2022-04-26 13:35:34 -07:00
Jeffrey Tan 7b81192d46 Introduce new symbol on-demand for debug info
This diff introduces a new symbol on-demand which skips
loading a module's debug info unless explicitly asked on
demand. This provides significant performance improvement
for application with dynamic linking mode which has large
number of modules.
The feature can be turned on with:
"settings set symbols.load-on-demand true"

The feature works by creating a new SymbolFileOnDemand class for
each module which wraps the actual SymbolFIle subclass as member
variable. By default, most virtual methods on SymbolFileOnDemand are
skipped so that it looks like there is no debug info for that module.
But once the module's debug info is explicitly requested to
be enabled (in the conditions mentioned below) SymbolFileOnDemand
will allow all methods to pass through and forward to the actual SymbolFile
which would hydrate module's debug info on-demand.

In an internal benchmark, we are seeing more than 95% improvement
for a 3000 modules application.

Currently we are providing several ways to on demand hydrate
a module's debug info:
* Source line breakpoint: matching in supported files
* Stack trace: resolving symbol context for an address
* Symbolic breakpoint: symbol table match guided promotion
* Global variable: symbol table match guided promotion

In all above situations the module's debug info will be on-demand
parsed and indexed.

Some follow-ups for this feature:
* Add a command that allows users to load debug info explicitly while using a
  new or existing command when this feature is enabled
* Add settings for "never load any of these executables in Symbols On Demand"
  that takes a list of globs
* Add settings for "always load the the debug info for executables in Symbols
  On Demand" that takes a list of globs
* Add a new column in "image list" that shows up by default when Symbols On
  Demand is enable to show the status for each shlib like "not enabled for
  this", "debug info off" and "debug info on" (with a single character to
  short string, not the ones I just typed)

Differential Revision: https://reviews.llvm.org/D121631
2022-04-26 10:42:06 -07:00
Walter Erquinigo 35e60f5de1 [NFC][trace] simplify the instruction dumper
TraceInstructionDumper::DumpInstructions was becoming too big, so I'm
refactoring it into smaller functions. I also made some static methods proper
instance methods to simplify calls. Other minor improvements are also done.

Differential Revision: https://reviews.llvm.org/D124064
2022-04-25 20:02:48 -07:00
Walter Erquinigo 059f39d2f4 [trace][intel pt] Support events
A trace might contain events traced during the target's execution. For
example, a thread might be paused for some period of time due to context
switches or breakpoints, which actually force a context switch. Not only
that, a trace might be paused because the CPU decides to trace only a
specific part of the target, like the address filtering provided by
intel pt, which will cause pause events. Besides this case, other kinds
of events might exist.

This patch adds the method `TraceCursor::GetEvents()`` that returns the
list of events that happened right before the instruction being pointed
at by the cursor. Some refactors were done to make this change simpler.

Besides this new API, the instruction dumper now supports the -e flag
which shows pause events, like in the following example, where pauses
happened due to breakpoints.

```
thread #1: tid = 2717361
  a.out`main + 20 at main.cpp:27:20
    0: 0x00000000004023d9    leaq   -0x1200(%rbp), %rax
  [paused]
    1: 0x00000000004023e0    movq   %rax, %rdi
  [paused]
    2: 0x00000000004023e3    callq  0x403a62                  ; std::vector<int, std::allocator<int> >::vector at stl_vector.h:391:7
  a.out`std::vector<int, std::allocator<int> >::vector() at stl_vector.h:391:7
    3: 0x0000000000403a62    pushq  %rbp
    4: 0x0000000000403a63    movq   %rsp, %rbp
```

The `dump info` command has also been updated and now it shows the
number of instructions that have associated events.

Differential Revision: https://reviews.llvm.org/D123982
2022-04-25 19:01:23 -07:00
Jeffrey Tan 5cbf516cb7 Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class.
This is a preparatory patch for https://reviews.llvm.org/D121631.
It refactors protected virtual members of SymbolFile
into a new SymbolFileCommon class per suggestion in:
https://reviews.llvm.org/D121631

This will avoid the friendship declaration in that patch.

Differential Revision: https://reviews.llvm.org/D124110
2022-04-25 18:33:47 -07:00
Will Hawkins e07c092b85
[lldb] Update online help text (consistency, typo)
Update the online help text for breakpoint set to be
consistent with respect to the spelling of Objective-C
and fix a few space-related typos.

Differential revision: https://reviews.llvm.org/D124338
2022-04-25 16:31:26 -07:00
Zequan Wu 827ff1e576 [LLDB][NativePDB] Fix incorrect file index of inlinees introduced by f00cd23cae 2022-04-25 16:07:04 -07:00
Shafik Yaghmour fd14646043 [LLDB] Applying clang-tidy modernize-use-override over LLDB
Applied clang-tidy modernize-use-override over LLDB and added it to the LLDB .clang-tidy config.

Differential Revision: https://reviews.llvm.org/D123340
2022-04-22 13:29:47 -07:00
Zequan Wu 1921b19576 [LLDB][NativePDB] Make sure the number of param symbol records is the same as the number get from function type record before setting parameters. 2022-04-21 16:06:58 -07:00
Alexander Yermolovich 014cd37f51 [BOLT][DWARF] Implement monolithic DWARF5
Added implementation to support DWARF5 in monolithic mode.
Next step DWARF5 split dwarf support.

Reviewed By: maksfb

Differential Revision: https://reviews.llvm.org/D121876
2022-04-21 16:02:23 -07:00
Pavel Labath 1056c56786 [lldb] Adjust libc++ string formatter for changes in D123580
The code needs more TLC, but for now I've tried making only the changes
that are necessary to get the tests passing -- postponing the more
invasive changes after I create a more comprehensive test.

In a couple of places I have changed the index-based element accesses to
name-based ones (as these are less sensitive to code perturbations). I'm
not sure why the code was using indexes in the first place, but I've
(manually) tested the change with various libc++ versions, and found no
issues with this approach.

Differential Revision: https://reviews.llvm.org/D124113
2022-04-21 14:07:56 +02:00
Muhammad Omair Javaid e3cd8fedca [LLDB] Skip TestCrashDuringStep.py AArch64/Windows
TestCrashDuringStep.py hangs on AArch64 windows with no resonable
possible fix. I am marking it skipped for now.
2022-04-21 05:10:37 +05:00
Muhammad Omair Javaid 5341b5f8d3 [LLDB] Update inspect getargspec to getfullargspec
This patch replaces getargspec with getfullargspec in funcutils.py.
getargspec has been deprecated by python 11x release. This is
important to run LLDB testsuite in Windows/Arm64 platform
where Python native will be available from python release onwards.

Note: getfullargspec is not available in python 2

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D121786
2022-04-21 01:33:26 +05:00
Zequan Wu 2fa2734690 [LLDB][NativePDB] Fix the case when S_DEFRANGE_SUBFIELD_REGISTERs are out of order.
Previously, I was assuming that S_DEFRANGE_SUBFIELD_REGISTERs are always in the
increasing order of offset_in_parent until I saw a counter example.

Using `std::map` so that they are sorted by offset_in_parent.

Differential Revision: https://reviews.llvm.org/D124061
2022-04-20 10:33:00 -07:00
Aaron Ballman ef50d817b6 Speculatively fix build bots
This should address build failures found in:

https://lab.llvm.org/buildbot/#/builders/217/builds/3610
https://lab.llvm.org/buildbot/#/builders/215/builds/4609
https://lab.llvm.org/buildbot/#/builders/68/builds/31012
2022-04-20 11:48:06 -04:00
Fangrui Song c129220eaa [lldb/gdb-remote] Fix -Wswitch after D116462 2022-04-19 18:01:06 -07:00
David Spickett 68e73eaee6 [lldb] Handle empty search string in "memory find"
Given that you'd never find empty string, just error.

Also add a test that an invalid expr generates an error.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D123793
2022-04-19 09:19:38 +00:00
Saleem Abdulrasool 2696d82fa0 Windows: correct iteration of additional search paths
This adjusts the path iteration - `paths` is a null-terminated sequence
of C strings, creating an array from a single contiguous buffer.  We
would previously continue to iterate indefinitely as we did not check if
we had encountered the terminator.

Found by inspection.
2022-04-16 18:01:02 -07:00
Zequan Wu dc100ebfda [LLDB][NativePDB] Followup c50817d1be 2022-04-15 12:08:44 -07:00
Zequan Wu c50817d1be [LLDB][NativePDB] Don't create inlined function parameters when it's malformed. 2022-04-15 11:59:11 -07:00
Zequan Wu 2f78f9455f [LLDB][NativePDB] Fix subfield_register_simple_type.s test 2022-04-15 10:36:25 -07:00
Jonas Devlieghere af91446aa2
[lldb] Show the DBGError if dsymForUUID can't find a dSYM
Show the user the DBGError (if available) when dsymForUUID fails.

rdar://90949180

Differential revision: https://reviews.llvm.org/D123743
2022-04-14 16:54:00 -07:00
Jonas Devlieghere 03049c5125
Revert "[lldb] Pin the shared cache when iterating over its images"
This reverts commit af969141fa because it
didn't have the intended performance benefit to offset the increase in
our (virtual) memory usage.
2022-04-14 16:23:56 -07:00
Jonas Devlieghere 428775d518
[lldb] Remove TestShell.test
Remove TestShell.test because it's failing on the bot with "this is a
non-interactive debug session, cannot get permission to debug
processes." The only thing that's special about this test is the shell
we're launching with. I need to do a bit of digging to understand why
that's causing this error.

rdar://91766931
2022-04-14 12:10:54 -07:00
Zequan Wu 3dbf524ad7 [LLDB][NativePDB] Fix a crash when S_DEFRANGE_SUBFIELD_REGISTER descirbes a simple type
When a variable is simple type and has 64 bits, the debug info may look like the following when targeting 32bit windows. The variable's content is split into two 32bits registers.
```
480 | S_LOCAL [size = 12] `x`
      type=0x0013 (__int64), flags = param
492 | S_DEFRANGE_SUBFIELD_REGISTER [size = 20]
      register = EAX, may have no name = true, offset in parent = 0
      range = [0001:0073,+7), gaps = []
512 | S_DEFRANGE_SUBFIELD_REGISTER [size = 20]
      register = ECX, may have no name = true, offset in parent = 4
      range = [0001:0073,+7), gaps = []
```

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D122943
2022-04-14 11:06:21 -07:00
Zequan Wu ef7cba7148 [LLDB][NativePDB] Fix inline line info in line table
It fixes the following case:
```
0602      line 1 (+1)
0315      code 0x15 (+0x15)
0B2B      code 0x20 (+0xB) line 2 (+1)
0602      line 3 (+1)
0311      code 0x31 (+0x11)
...
```

Inline ranges should have following mapping:
`[0x15, 0x20) -> line 1`
`[0x20, 0x31) -> line 2`
Inline line entries:
`0x15, line 1`, `0x20, line 2`, `0x31, line 3`.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D123092
2022-04-14 11:00:56 -07:00
Jonas Devlieghere 99d9c44434
[lldb] Port Process::PrintWarning* to use the new diagnostic events
Port the two Process::PrintWarning functions to use the new diagnostic
events through Debugger::ReportWarning. I kept the wrapper function in
the process, but delegated the work to the Module. Consistent with the
current code, the Module ensures the warning is only printed once per
module.

Differential revision: https://reviews.llvm.org/D123698
2022-04-14 11:00:21 -07:00
Jonas Devlieghere 64d9b233b9
[lldb] Prevent crash when adding a stop hook with --shlib
Currently, lldb crashes when adding a stop hook with --shlib because we
unconditionally use the target in SymbolContextSpecifier::AddSpecification.
This patch prevents the crash and add a test.

rdar://68524781

Differential revision: https://reviews.llvm.org/D123746
2022-04-14 11:00:21 -07:00
Jonas Devlieghere 6443d0d413
[lldb] Remove reproducer logic from LocateSymbolFileMacOSX 2022-04-13 16:27:02 -07:00
Jonas Devlieghere 80c600fe98
[lldb] Format LocateSymbolFileMacOSX (NFC) 2022-04-13 16:27:02 -07:00
Jonas Devlieghere 343f3de559
[lldb] Fix a bug in the decorator matching logic.
This changes the decorator helper `_match_decorator_property` to
consider `None` as the actual value as not a match. Using `None` for the
pattern continues to be considered a match.

I discovered the issue because marking a test as NO_DEBUG_INFO_TESTCASE
will cause the call to `self.getDebugInfo()` to return `None` and
incorrectly skip or XFAIL the corresponding test.

I used the above scenario to create a test for the decorators.

Differential revision: https://reviews.llvm.org/D123401
2022-04-13 15:07:33 -07:00
Jonas Devlieghere 763ff89c0e
[debugserver ] Un-conditionalize use of libcompression
Jason removed the include guards in 681f6c2f55. This patch removes the
corresponding CMake logic as well.

Differential revision: https://reviews.llvm.org/D123616
2022-04-13 14:36:25 -07:00
Jonas Devlieghere acc56e55fe
[lldb] Expand $ when using tcsh
Unlike for any of the other shells, we were escaping $ when using tcsh.
There's nothing special about $ in tcsh and this prevents you from
expanding shell variables, one of the main reasons this functionality
exists in the first place.

Differential revision: https://reviews.llvm.org/D123690
2022-04-13 13:01:09 -07:00
Nathan Sidwell 201c4b9cc4 [demangler] Rust demangler buffer return
The rust demangler has some odd buffer handling code, which will copy
the demangled string into the provided buffer, if it will fit.
Otherwise it uses the allocated buffer it made.  But the length of the
incoming buffer will have come from a previous call, which was the
length of the demangled string -- not the buffer size.  And of course,
we're unconditionally allocating a temporary buffer in the first
place.  So we don't actually get buffer reuse, and we get a memcpy in
somecases.

However, nothing in LLVM ever passes in a non-null pointer.  Neither
does anything pass in a status pointer that is then made use of.  The
only exercise these have is in the test suite.

So let's just make the rust demangler have the same API as the dlang
demangler.

Reviewed By: tmiasko

Differential Revision: https://reviews.llvm.org/D123420
2022-04-13 08:50:04 -07:00
Pavel Labath 7d70b1a405 [lldb] Fixup af921006d3 for non-linux platforms 2022-04-13 15:38:36 +02:00
Pavel Labath af921006d3 [lldb] Remove the global platform list
This patch moves the platform creation and selection logic into the
per-debugger platform lists. I've tried to keep functional changes to a
minimum -- the main (only) observable difference in this change is that
APIs, which select a platform by name (e.g.,
Debugger::SetCurrentPlatform) will not automatically pick up a platform
associated with another debugger (or no debugger at all).

I've also added several tests for this functionality -- one of the
pleasant consequences of the debugger isolation is that it is now
possible to test the platform selection and creation logic.

This is a product of the discussion at
<https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>.

Differential Revision: https://reviews.llvm.org/D120810
2022-04-13 14:41:13 +02:00
Jonas Devlieghere a3d69a193a
[lldb] Re-enable TestStepNoDebug.py on AS
This test showed up as an unexpected pass and is now consistently
passing on Apple Silicon.
2022-04-12 20:28:29 -07:00
Jonas Devlieghere 990d0c7109
[lldb] Print diagnostic prefixes (error, warning) in color
Print diagnostic prefixes (error, warning) in their respective colors
when colors are enabled.
2022-04-12 20:28:29 -07:00
Raphael Isemann 07a722c574
[lldb] Escape semicolons for all shells
LLDB supports having globbing regexes in the process launch arguments
that will be resolved using the user's shell. This requires that we pass
the launch args to the shell and then read back the expanded arguments
using LLDB's argdumper utility.

As the shell will not just expand the globbing regexes but all special
characters, we need to escape all non-globbing charcters such as $, &,
<, >, etc. as those otherwise are interpreted and removed in the step
where we expand the globbing characters. Also because the special
characters are shell-specific, LLDB needs to maintain a list of all the
characters that need to be escaped for each specific shell.

This patch adds the missing semicolon character to the escape list for
all currently supported shells. Without this having a semicolon in the
binary path or having a semicolon in the launch arguments will cause the
argdumping process to fail. E.g., lldb -- ./calc "a;b" was failing
before but is working now.

Fixes rdar://55776943

Differential revision: https://reviews.llvm.org/D104629
2022-04-12 18:13:55 -07:00
Walter Erquinigo 44103c96fa [trace][intelpt] Remove code smell when printing the raw trace size
Something ugly I did was to report the trace buffer size to the DecodedThread,
which is later used as part of the `dump info` command. Instead of doing that,
we can just directly ask the trace for the raw buffer and print its size.

I thought about not asking for the entire trace but instead just for its size,
but in this case, as our traces as not extremely big, I prefer to ask for the
entire trace, ensuring it could be fetched, and then print its size.

Differential Revision: https://reviews.llvm.org/D123358
2022-04-12 13:08:03 -07:00
Walter Erquinigo bdf3e7e5b8 [trace][intelpt] Add task timer classes
I'm adding two new classes that can be used to measure the duration of long
tasks as process and thread level, e.g. decoding, fetching data from
lldb-server, etc. In this first patch, I'm using it to measure the time it takes
to decode each thread, which is printed out with the `dump info` command. In a
later patch I'll start adding process-level tasks and I might move these
classes to the upper Trace level, instead of having them in the intel-pt
plugin. I might need to do that anyway in the future when we have to
measure HTR. For now, I want to keep the impact of this change minimal.

With it, I was able to generate the following info of a very big trace:

```
(lldb) thread trace dump info                                                                                                            Trace technology: intel-pt

thread #1: tid = 616081
  Total number of instructions: 9729366

  Memory usage:
    Raw trace size: 1024 KiB
    Total approximate memory usage (excluding raw trace): 123517.34 KiB
    Average memory usage per instruction (excluding raw trace): 13.00 bytes

  Timing:
    Decoding instructions: 1.62s

  Errors:
    Number of TSC decoding errors: 0
```

As seen above, it took 1.62 seconds to decode 9.7M instructions. This is great
news, as we don't need to do any optimization work in this area.

Differential Revision: https://reviews.llvm.org/D123357
2022-04-12 13:08:03 -07:00
Jonas Devlieghere a66ff2316e
[lldb] Re-enable fixed on-device tests
These tests were fixed by 833882b327.
2022-04-12 11:39:25 -07:00
Pavel Labath 45428412fd [lldb] Adjust libc++ string formatter for changes in D122598
The __size_ member is now in a slightly different location.
2022-04-12 15:44:16 +02:00
David Spickett 0231a90bc4 [lldb][AArch64] Automatically add all extensions to disassembler
This means we don't have to remember to update this code as much.

This is all tested in lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
which I added previously.

We don't have a way to get the latest base architecture yet
so that remains manual. Having all the extensions specified
will probably be equivalent to the latest architecture version
in any case.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D123582
2022-04-12 12:31:43 +00:00
Luboš Luňák 195a8b977e don't extra notify ModulesDidLoad() from LoadModuleAtAddress()
Places calling LoadModuleAtAddress() already call ModulesDidLoad()
after a loop calling LoadModuleAtAddress(), so it's not necessary
to call it from there, and the batched ModulesDidLoad() may be
more efficient than this place calling it one after one.

This also makes the ModuleLoadedNotifys test pass on Linux now that
the duplicates no longer bring down the average of modules notified
per call.

Differential Revision: https://reviews.llvm.org/D123128
2022-04-12 00:36:33 +02:00
Jonas Devlieghere cbcb3bcee3
[lldb] Don't report progress in the REPL
Don't report progress events in the REPL. Most of the progress events
are debugger specific which are useful when you're debugging, but not so
much when you're waiting for the next line to be executed in the REPL.

This patch disables reporting of progress events when in REPL mode.

rdar://91502950

Differential revision: https://reviews.llvm.org/D123426
2022-04-11 13:06:40 -07:00