17527 Commits

Author SHA1 Message Date
Jonas Devlieghere
1b812f9cd6
[lldb] Log to system log instead of stderr from Host::SystemLog (#83366)
Currently, calls to Host::SystemLog print to stderr on all host
platforms except Darwin. This severely limits its value on the command
line, where we don't want to overload the user with log messages. Switch
to using the syslog function on POSIX systems to send messages to the
system logger instead of stdout.

On Darwin systems this sends the log message to os_log, which matches
what we do today. Nevertheless I kept the current implementation that
uses os_log directly as it gives us more freedom.

I'm not sure if there's an equivalent on Windows, so I kept the existing
behavior of logging to stderr.
2024-03-05 10:56:01 -08:00
Jonas Devlieghere
1da5db97cb
[lldb] Use sort-ordering for indexes when sorting by size (#83889)
Use sort-ordering for indexes when sorting by size. This addresses
Jason's post commit review feedback.
2024-03-04 10:44:17 -08:00
Mehdi Amini
e52650cfc3 Fix LLDB build after renaming the base class for ThreadPool to ThreadPoolInterface
The header was updated but not the implementation.
2024-03-02 19:30:33 -08:00
Daniil Kovalev
b14220e075
[lldb][X86] Fix setting target features in ClangExpressionParser (#82364)
Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended
to `Features` vector of `TargetOptions` unconditionally. This vector is
later reset in `TargetInfo::CreateTargetInfo` and filled using info from
`FeaturesAsWritten` vector, so previous modifications of the `Features`
vector have no effect. For x86_64 triple, we append "sse2"
unconditionally in `X86TargetInfo::initFeatureMap`, so despite the
`Features` vector reset, we still have the desired sse features enabled.
The corresponding code in `X86TargetInfo::initFeatureMap` is marked as
FIXME, so we should not probably rely on it and should set desired
features properly in `ClangExpressionParser`.

This patch changes the vector the features are appended to from
`Features` to `FeaturesAsWritten`. It's not reset later and is used to
compute resulting `Features` vector.
2024-03-02 13:09:47 +03:00
Fangrui Song
ebaf26dabe [lldb] Fix -Wformat after #83602 2024-03-01 12:09:32 -08:00
Jonas Devlieghere
af009451ec
[lldb] Fix thread backtrace --count (#83602)
The help output for `thread backtrace` specifies that you can pass -1 to
`--count` to display all the frames.

```
-c <count> ( --count <count> )
            How many frames to display (-1 for all)
```

However, that doesn't work:

```
(lldb) thread backtrace --count -1
error: invalid integer value for option 'c'
```

The problem is that we store the option value as an unsigned and the
code to parse the string correctly rejects it. There's two ways to fix
this:

1. Make `m_count` a signed value so that it accepts negative values and
appease the parser. The function that prints the frames takes an
unsigned so a negative value will just become a really large positive
value, which is what the current implementation relies on.
2. Keep `m_count` unsigned and instead use 0 the magic value to show all
frames. I don't really see a point in not showing any frames at all,
plus that's already broken (`error: error displaying backtrace for
thread: "0x0001"`).

This patch implements (2) and at the same time improve the error
reporting so that we print the invalid value when we cannot parse it.

rdar://123881767
2024-03-01 11:06:58 -08:00
Chelsea Cassanova
137ed17016
[lldb][progress] Hook up new broadcast bit and progress manager (#83069)
This commit adds the functionality to broadcast events using the
`Debugger::eBroadcastProgressCategory`
bit (https://github.com/llvm/llvm-project/pull/81169) by keeping track
of these reports with the `ProgressManager`
class (https://github.com/llvm/llvm-project/pull/81319). The new bit is
used in such a way that it will only broadcast the initial and final
progress reports for specific progress categories that are managed by
the progress manager.

This commit also adds a new test to the progress report unit test that
checks that only the initial/final reports are broadcasted when using
the new bit.
2024-03-01 10:56:45 -08:00
Jonas Devlieghere
8fa33013de
[lldb] Add support for sorting by size to target module dump symtab (#83527)
This patch adds support to sort the symbol table by size. The command
already supports sorting and it already reports sizes. Sorting by size
helps diagnosing size issues.

rdar://123788375
2024-03-01 08:34:36 -08:00
Jason Molenda
e8ce864a36 Revert "[lldb] Add SBProcess methods for get/set/use address masks (#83095)"
This reverts commit 9a12b0a60084b2b92f728e1bddec884a47458459.

TestAddressMasks fails its first test on lldb-x86_64-debian,
lldb-arm-ubuntu, lldb-aarch64-ubuntu bots.  Reverting while
investigating.
2024-02-29 17:29:24 -08:00
Jason Molenda
9a12b0a600
[lldb] Add SBProcess methods for get/set/use address masks (#83095)
I'm reviving a patch from phabracator, https://reviews.llvm.org/D155905
which was approved but I wasn't thrilled with all the API I was adding
to SBProcess for all of the address mask types / memory regions. In this
update, I added enums to control type address mask type (code, data,
any) and address space specifiers (low, high, all) with defaulted
arguments for the most common case.

This patch is also fixing a bug in the "addressable bits to address
mask" calculation I added in AddressableBits::SetProcessMasks. If lldb
were told that 64 bits are valid for addressing, this method would
overflow the calculation and set an invalid mask. Added tests to check
this specific bug while I was adding these APIs.

rdar://123530562
2024-02-29 17:02:42 -08:00
Michael Buch
07ffb7e294
[lldb][ClangASTImporter] Import record layouts from origin if available (#83295)
Layout information for a record gets stored in the `ClangASTImporter`
associated with the `DWARFASTParserClang` that originally parsed the
record. LLDB sometimes moves clang types from one AST to another (in the
reproducer the origin AST was a precompiled-header and the destination
was the AST backing the executable). When clang then asks LLDB to
`layoutRecordType`, it will do so with the help of the
`ClangASTImporter` the type is associated with. If the type's origin is
actually in a different LLDB module (and thus a different
`DWARFASTParserClang` was used to set its layout info), we won't find
the layout info in our local `ClangASTImporter`.

In the reproducer this meant we would drop the alignment info of the
origin type and misread a variable's contents with `frame var` and
`expr`.

There is logic in `ClangASTSource::layoutRecordType` to import an
origin's layout info. This patch re-uses that infrastructure to import
an origin's layout from one `ClangASTImporter` instance to another.

rdar://123274144
2024-02-29 21:40:02 +00:00
Michael Buch
8c10032665
[lldb][NFC] Move helpers to import record layout into ClangASTImporter (#83291)
This patch moves the logic for copying the layout info of a
`RecordDecl`s origin into a target AST.

A follow-up patch re-uses the logic from within the `ClangASTImporter`,
so the natural choice was to move it there.
2024-02-29 21:32:28 +00:00
Sudharsan Veeravalli
de5518836e
[LLDB] Fix crash when using tab completion on class variables (#83234)
We weren't checking to see if the partial_path was empty before adding
completions and this led to crashes when the class object and a variable
both start with the same substring.

Fixes [#81536](https://github.com/llvm/llvm-project/issues/81536)

---------

Co-authored-by: Michael Buch <michaelbuch12@gmail.com>
2024-02-29 09:40:27 +00:00
jimingham
5784bf85bc
Fix interactive use of "command script add". (#83350)
There was a think-o in a previous commit that made us only able to
define 1 line commands when using command script add interactively.

There was also no test for this feature, so I fixed the think-o and
added a test.
2024-02-28 17:26:29 -08:00
jimingham
97281708ac
Change image list -r so that it actually shows the ref count and whether the image is in the shared cache. (#83341)
The help for the `-r` option to `image list` says:

       -r[<width>] ( --ref-count=[<width>] )
Display the reference count if the module is still in the shared module
cache.

but that's not what it actually does. It unconditionally shows the
use_count for all Module shared pointers, regardless of whether they are
still in the shared module cache or whether they are just in the
ModuleCollection and other entities are keeping them alive. That seems
like a more useful behavior, but then it is also useful to know what's
in the shared cache, so I changed this to:

       -r[<width>] ( --ref-count=[<width>] )
Display whether the module is still in the the shared module cache
(Y/N), and its shared pointer use_count.

So instead of just `{5}` you will see `{Y 5}` if it is in the shared
cache and `{N 5}` if not.

I didn't add tests for this because I'm not sure how much we want to fix
shared cache behavior in the testsuite.
2024-02-28 16:14:19 -08:00
Walter Erquinigo
cd344a4c20
[LLDB] Fix completion of space-only lines in the REPL on Linux (#83203)
https://github.com/modularml/mojo/issues/1796 discovered that if you try
to complete a space-only line in the REPL on Linux, LLDB crashes. I
suspect that editline doesn't behave the same way on linux and on
darwin, because I can't replicate this on darwin.

Adding a boundary check in the completion code prevents the crash from
happening.
2024-02-28 11:43:36 -05:00
jimingham
2d704f4bf2
Start to clean up the process of defining command arguments. (#83097)
Partly, there's just a lot of unnecessary boiler plate. It's also
possible to define combinations of arguments that make no sense (e.g.
eArgRepeatPlus followed by eArgRepeatPlain...) but these are never
checked since we just push_back directly into the argument definitions.

This commit is step 1 of this cleanup - do the obvious stuff. In it, all
the simple homogenous argument lists and the breakpoint/watchpoint
ID/Range types, are set with common functions. This is an NFC change, it
just centralizes boiler plate. There's no checking yet because you can't
get a single argument wrong.

The end goal is that all argument definition goes through functions and
m_arguments is hidden so that you can't define inconsistent argument
sets.
2024-02-27 10:34:01 -08:00
Alex Langford
0ef66fcc85
[lldb] Use CreateOptionParsingError in CommandObjectBreakpoint (#83086)
This updates the remaining SetOptionValue methods in
CommandObjectBreakpoint to use CreateOptionParsingError.

I found a few minor bugs that were fixed during this refactor (e.g.
using the wrong flag in an error message). That is one of the benefits
of centralizing error message creation.

I also found some option parsing code that is written incorrectly. I do
not make an attempt to update those here because this PR is primarily
about changing existing error handling code, not adding new error
handling code.
2024-02-27 10:25:56 -08:00
Adrian Prantl
8a87f763a6
Aim debugserver workaround more precisely. (#83099) 2024-02-27 08:14:46 -08:00
Adrian Prantl
01450dd1c6 Change debugserver to report the cpu(sub)type of process, not the host.
This way debugserver can correctly report qProcessInfo for arm64
processes on arm64e-capable hosts.

Patch implemented with help from Jason Molenda!
2024-02-26 09:57:07 -08:00
Adrian Prantl
f9f331652d Replace ArchSpec::PiecewiseCompare() with Triple::operator==()
Looking ast the definition of both functions this is *almost* an NFC
change, except that Triple also looks at the SubArch (important) and
ObjectFormat (less so).

This fixes a bug that only manifests with how Xcode uses the SBAPI to
attach to a process by name: it guesses the architecture based on the
system. If the system is arm64 and the Process is arm64e Target fails
to update the triple because it deemed the two to be equivalent.

rdar://123338218
2024-02-26 09:57:07 -08:00
Adrian Prantl
3f91bdfdd5 Revert "Replace ArchSpec::PiecewiseCompare() with Triple::operator==()"
This reverts commit 5e6bed8c0ea2f7fe380127763c8f753adae0fc1b while investigating the bots.
2024-02-23 15:26:14 -08:00
Jason Molenda
87fadb3929
[lldb] Correctly annotate threads at a bp site as hitting it (#82709)
This is next in my series of "fix the racey tests that fail on
greendragon" addressing the failure of TestConcurrentManyBreakpoints.py
where we set a breakpoint in a function that 100 threads execute, and we
check that we hit the breakpoint 100 times. But sometimes it is only hit
99 times, and the test fails.

When we hit a software breakpoint, the pc value for the thread is the
address of the breakpoint instruction - as if it had not been hit yet.
And because a user might ADD a breakpoint for the current pc from the
commandline, when we go to resume execution, any thread that is sitting
at a breakpoint site will be silently advanced past the breakpoint
instruction (disable bp, instruction step that thread, re-enable bp)
before resuming -- whether that thread has hit its breakpoint or not.

What this test is exposing is that there is another corner case, a
thread that is sitting at a breakpoint site but has not yet executed the
breakpoint instruction. The thread will have no stop reason, no mach
exception, so it will not be recorded as having hit the breakpoint
(because it hasn't yet). But when we resume execution, because it is
sitting at a breakpoint site, we advance past it and miss the breakpoint
hit.

In 2016 Abhishek Aggarwal handled a similar issue with a patch in
`ProcessGDBRemote::SetThreadStopInfo()`, adding a breakpoint StopInfo
for a thread sitting at a breakpoint site that has no stop reason.
debugserver's `jThreadsInfo` would not correctly execute Abhishek's code
though because it would respond with `"reason":"none"` for a thread with
no stop reason, and `SetThreadStopInfo()` expected an empty reason here.
The first part of my patch is to clear the `reason` if it is `"none"` so
we flow through the code correctly.

On Darwin, though, our stop reply packet (Txx...) includes the
`threads`, `thread-pcs`, and `jstopinfo` keys, which give us the tids
for all current threads, the pc values for those threads, and
`jstopinfo` has a JSON dictionary with the mach exceptions for all
threads that have a mach exception. In
`ProcessGDBRemote::CalculateThreadStopInfo()` we set the StopInfo for
each thread for a private stop and if we have `jstopinfo` it is the
source of all the StopInfos. I have to add the same logic here, to give
the thread a breakpoint StopInfo even though it hasn't executed the
breakpoint yet. In this case we are very early in thread construction
and I only have the information in the Txx stop reply packet -- tids,
pcs, and jstopinfo, so I can't use the normal general mechanisms of
going through the RegisterContext to get the pc, it's a bit different.

If I hack debugserver to not issue `jstopinfo`,
`CalculateThreadStopInfo` will fall back to sending `qThreadStopInfo`
for each thread and going through
`ProcessGDBRemote::SetThreadStopInfo()` to set the stop infos (and with
the `reason:none` fix, use Abhishek's code).

rdar://110549165
2024-02-23 14:45:22 -08:00
Adrian Prantl
25940956e6
Replace ArchSpec::PiecewiseCompare() with Triple::operator==() (#82804)
Looking ast the definition of both functions this is *almost* an NFC
change, except that Triple also looks at the SubArch (important) and
ObjectFormat (less so).

This fixes a bug that only manifests with how Xcode uses the SBAPI to
attach to a process by name: it guesses the architecture based on the
system. If the system is arm64 and the Process is arm64e Target fails to
update the triple because it deemed the two to be equivalent.

rdar://123338218
2024-02-23 14:00:15 -08:00
Adrian Prantl
55bc0488af
Improve and modernize logging for Process::CompleteAttach() (#82717)
Target::SetArchitecture() does not necessarily set the triple that is
being passed in, and will unconditionally log the real architecture to
the log channel. By flipping the order between the log outputs, the
resulting combined log makes a lot more sense to read.
2024-02-23 08:00:58 -08:00
Jonas Devlieghere
354401f8d3
[lldb] Fix GetTerminalWidth after afd469023aad
afd469023aad fixed the type of the term-width setting but the getter
(Debugger::GetTerminalWidth) was still trying to get the terminal width
as an unsigned. This fixes TestXMLRegisterFlags.py.
2024-02-22 23:54:13 -08:00
Jonas Devlieghere
afd469023a
[lldb] Fix term-width setting (#82736)
I noticed that the term-width setting would always report its default
value (80) despite the driver correctly setting the value with
SBDebugger::SetTerminalWidth.

```
(lldb) settings show term-width
term-width (int) = 80
```

The issue is that the setting was defined as a SInt64 instead of a
UInt64 while the getter returned an unsigned value. There's no reason
the terminal width should be a signed value. My best guess it that it
was using SInt64 because UInt64 didn't support min and max values. I
fixed that and correct the type and now lldb reports the correct
terminal width:

```
(lldb) settings show term-width
term-width (unsigned) = 189
```

rdar://123488999
2024-02-22 21:48:49 -08:00
Alex Langford
7e1432f125
[lldb] Standardize command option parsing error messages (#82273)
I have been looking to simplify parsing logic and improve the interfaces
so that they are both easier to use and harder to abuse. To be specific,
I am referring to functions such as `OptionArgParser::ToBoolean`: I
would like to go from its current interface to something more like
`llvm::Error<bool> ToBoolean(llvm::StringRef option_arg)`.

Through working on that, I encountered 2 inconveniences:
1. Option parsing code is not uniform. Every function writes a slightly
different error message, so incorporating an error message from the
`ToBoolean` implementation is going to be laborious as I figure out what
exactly needs to change or stay the same.
2. Changing the interface of `ToBoolean` would require a global atomic
change across all of the Command code. This would be quite frustrating
to do because of the non-uniformity of our existing code.

To address these frustrations, I think it would be easiest to first
standardize the error reporting mechanism when parsing options in
commands. I do so by introducing `CreateOptionParsingError` which will
create an error message of the shape:
Invalid value ('${option_arg}') for -${short_value} ('${long_value}'):
${additional_context}

Concretely, it would look something like this:
(lldb) breakpoint set -n main -G yay
error: Invalid value ('yay') for -G (auto-continue): Failed to parse as
boolean

After this, updating the interfaces for parsing the values themselves
should become simpler. Because this can be adopted incrementally, this
should be able to done over the course of time instead of all at once as
a giant difficult-to-review change. I've changed exactly one function
where this function would be used as an illustration of what I am
proposing.
2024-02-21 19:26:43 -08:00
Greg Clayton
5a45d32b5b
[lldb] Add more ways to find the .dwp file. (#81067)
When using split DWARF we can run into many different ways to store
debug info:
- lldb loads `<exe>` which contains skeleton DWARF and needs to find
`<exe>.dwp`
- lldb loads `<exe>` which is stripped but has .gnu_debuglink pointing
to `<exe>.debug` with skeleton DWARF and needs to find `<exe>.dwp`
- lldb loads `<exe>` which is stripped but has .gnu_debuglink pointing
to `<exe>.debug` with skeleton DWARF and needs to find `<exe>.debug.dwp`
- lldb loads `<exe>.debug` and needs to find `<exe>.dwp`

Previously we only handled the first two cases. This patch adds support
for the latter two.
2024-02-20 18:17:01 -08:00
jimingham
563ef30601
Add the RegisterCompleter to eArgTypeRegisterName in g_argument_table (#82428)
This is a follow-on to:

https://github.com/llvm/llvm-project/pull/82085

The completer for register names was missing from the argument table. I
somehow missed that the only register completer test was x86_64, so that
test broke.

I added the completer in to the right slot in the argument table, and
added a small completions test that just uses the alias register names.
If we end up having a platform that doesn't define register names, we'll
have to skip this test there, but it should add a sniff test for
register completion that will run most everywhere.
2024-02-20 14:18:03 -08:00
Shubham Sandeep Rastogi
9ed8b272c3 Revert "Centralize the handling of completion for simple argument lists. (#82085)"
This reverts commit 21631494b068d9364b8dc8f18e59adee9131a0a5.

Reverted because of greendragon failure:

******************** TEST 'lldb-api :: functionalities/completion/TestCompletion.py' FAILED ********************
Script:
2024-02-19 18:19:59 -08:00
jimingham
21631494b0
Centralize the handling of completion for simple argument lists. (#82085)
Most commands were adding argument completion handling by themselves,
resulting in a lot of unnecessary boilerplate. In many cases, this could
be done generically given the argument definition and the entries in the
g_argument_table.

I'm going to address this in a couple passes. In this first pass, I
added handling of commands that have only one argument list, with one
argument type, either single or repeated, and changed all the commands
that are of this sort (and don't have other bits of business in their
completers.)

I also added some missing connections between arg types and completions
to the table, and added a RemoteFilename and RemotePath to use in places
where we were using the Remote completers. Those arguments used to say
they were "files" but they were in fact remote files.

I also added a module arg type to use where we were using the module
completer. In that case, we should call the argument module.
2024-02-19 16:43:08 -08:00
Jonas Devlieghere
513d9f2395
[ptrauth] Teach LLVM & LLDB about LLVM_ptrauth_authentication_mode (#82272)
Teach LLVM & LLDB about `DW_AT_LLVM_ptrauth_authentication_mode`
2024-02-19 15:29:00 -08:00
Jonas Devlieghere
1b26c25f7e
[llvm] Upstream the BridgeOS triple enum value (NFC)
This upstreams the BridgeOS target triple enum value.
2024-02-19 12:20:23 -08:00
Wanyi
dd7386d85f
[Reland] Report only loaded debug info in statistics dump (#81706) (#82207)
Updates:

- The previous patch changed the default behavior to not load dwos in
`DWARFUnit`
~~`SymbolFileDWARFDwo *GetDwoSymbolFile(bool load_all_debug_info =
false);`~~
`SymbolFileDWARFDwo *GetDwoSymbolFile(bool load_all_debug_info = true);`
- This broke some lldb-shell tests (see
https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/16273/)
- TestDebugInfoSize.py
- with symbol on-demand, by default statistics dump only reports
skeleton debug info size
- `statistics dump -f` will load all dwos. debug info = skeleton debug
info + all dwo debug info

Currently running `statistics dump` will trigger lldb to load debug info
that's not yet loaded (eg. dwo files). Resulted in a delay in the
command return, which, can be interrupting.

This patch also added a new option `--load-all-debug-info` asking
statistics to dump all possible debug info, which will force loading all
debug info available if not yet loaded.
2024-02-19 00:33:23 -05:00
Jonas Devlieghere
339baae3e2
Revert "Report only loaded debug info in statistics dump (#81706)" (#82150)
This reverts commit 21ddd7ff2b166c5e133b460b1a09ee8adb786ccd because it
breaks a bunch of tests:

https://lab.llvm.org/buildbot/#/builders/68/builds/69018
https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/16273
2024-02-17 21:38:11 -08:00
Jonas Devlieghere
fbce244299
[lldb] Call Import_AppendInittab before Py_Initialize (#82095)
The Python documentation [1] says that `PyImport_AppendInittab` should
be called before `Py_Initialize()`. Starting with Python 3.12, this is
enforced with a fatal error:

  Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab()
  may not be called after Py_Initialize()

This commit ensures we only modify the table of built-in modules if
Python hasn't been initialized. For Python embedded in LLDB, that means
this happen exactly once, before the first call to `Py_Initialize`,
which becomes a NO-OP after. However, when lldb is imported in an
existing Python interpreter, Python will have already been initialized,
but by definition, the lldb module will already have been loaded, so
it's safe to skip adding it (again).

This fixes #70453.

[1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab
2024-02-17 15:10:09 -08:00
Wanyi
21ddd7ff2b
Report only loaded debug info in statistics dump (#81706)
Currently running `statistics dump` will trigger lldb to load debug info
that's not yet loaded (eg. dwo files). Resulted in a delay in the
command return, which, can be interrupting.

This patch also added a new option `--load-all-debug-info` asking
statistics to dump all possible debug info, which will force loading all
debug info available if not yet loaded.
2024-02-17 14:38:18 -05:00
Vlad Serebrennikov
4214f25dcc Re-land "[lldb] Fix FindDirectNestedType not working with class templates (#81666)"
This patch attempts to fix lookup in class template specialization.

The first fixed problem is that during type lookup `DeclContextGetName`
have been dropping template arguments. So when such a name was compared
against a name in `DW_AT_name`, which contains template arguments, false
mismatches have been occurring.

The second fixed problem is that LLDB's printing policy hasn't been
matching Clang's printing policy when it comes to integral non-type
template arguments. This again caused some false mismatches during type
lookup, because Clang puts e.g. `3U` in debug info for class
specializations, but LLDB has been expecting just `3`. This patch brings
printing policy in line with what Clang does.
2024-02-16 22:47:09 +03:00
Shubham Sandeep Rastogi
831ba95400 Revert "[lldb] Fix FindDirectNestedType not working with class templates (#81666)"
This reverts commit 7b7d411de9f731d2bcf6b093f6cee2cf57a5196e.
2024-02-16 11:00:35 -08:00
Vlad Serebrennikov
7b7d411de9
[lldb] Fix FindDirectNestedType not working with class templates (#81666)
This patch attempts to fix lookup in class template specialization.

The first fixed problem is that during type lookup `DeclContextGetName`
have been dropping template arguments. So when such a name was compared
against a name in `DW_AT_name`, which contains template arguments, false
mismatches have been occurring.

The second fixed problem is that LLDB's printing policy hasn't been
matching Clang's printing policy when it comes to integral non-type
template arguments. This again caused some false mismatches during type
lookup, because Clang puts e.g. `3U` in debug info for class
specializations, but LLDB has been expecting just `3`. This patch brings
printing policy in line with what Clang does.
2024-02-16 20:40:27 +04:00
Jason Molenda
4cf458c696 Fix help doc for 'enable-background-lookup' obsolete setting
The setting name that was settled on is symbols.auto-download.
2024-02-15 23:53:14 -08:00
Chelsea Cassanova
327d2f8c6c
[lldb][progress] Add progress manager class (#81319)
Per discussions from https://github.com/llvm/llvm-project/pull/81026, it
was decided that having a class that manages a map of progress reports
would be beneficial in order to categorize them. This class is a part of
the overall `Progress` class and utilizes a map that keeps a count of
how many times a progress report category has been sent. This would be
used with the new debugger broadcast bit added in
https://github.com/llvm/llvm-project/pull/81169 so that a user listening
with that bit will receive grouped progress reports.
2024-02-15 15:46:47 -08:00
Dave Lee
1da4494184
[lldb] Add comment on cross printing of summary/value (#81681)
Adds a comment to indicate intention of a piece of value printing code.

I was initially surprised to see this code (distilled for emphasis):

```cpp
if (str.empty()) {
  if (style == eValueObjectRepresentationStyleValue)
    str = GetSummaryAsCString();
  else if (style == eValueObjectRepresentationStyleSummary)
    str = GetValueAsCString();
}
```

My first thought was "is this a bug?", but I realized it was likely intentional. This 
change adds a comment to indicate yes, this is intentional.
2024-02-14 13:13:23 -08:00
Jason Molenda
aab48c99c2
[lldb] Detect a Darwin kernel issue and work around it (#81573)
On arm64 machines, when there is a hardware breakpoint or watchpoint
set, and lldb has instruction-stepped a thread, and then done a
Process::Resume, we will sometimes receive an extra "instruction step
completed" mach exception and the pc has not advanced. From a user's
perspective, they hit Continue and lldb stops again at the same spot.
From the testsuite's perspective, this has been a constant source of
testsuite failures for any test using hardware watchpoints and
breakpoints, the arm64 CI bots seem especially good at hitting this
issue.

Jim and I have been slowly looking at this for a few months now, and
finally I decided to try to detect this situation in lldb and silently
resume the process again when it happens.

We were already detecting this "got an insn-step finished mach exception
but this thread was not instruction stepping" combination in
StopInfoMachException where we take the mach exception and create a
StopInfo object for it. We had a lot of logging we used to understand
the failure as it was hit on the bots in assert builds.

This patch adds a new case to `Thread::GetPrivateStopInfo()` to call the
StopInfo's (new) `IsContinueInterrupted()` method. In
StopInfoMachException, where we previously had logging for assert
builds, I now note it in an ivar, and when
`Thread::GetPrivateStopInfo()` asks if this has happened, we check all
of the combination of events that this comes up: We have a hardware
breakpoint or watchpoint, we were not instruction stepping this thread
but got an insn-step mach exception, the pc is the same as the previous
stop's pc. And in that case, `Thread::GetPrivateStopInfo()` returns no
StopInfo -- indicating that this thread would like to resume execution.

The `Thread` object has two StackFrameLists, `m_curr_frames_sp` and
`m_prev_frames_sp`. When a thread resumes execution, we move
`m_curr_frames_sp` in to `m_prev_frames_sp` and when it stops executing,
w euse `m_prev_frames_sp` to seed the new `m_curr_frames_sp` if most of
the stack is the same as before.

In this same location, I now save the Thread's RegisterContext::GetPC
into an ivar, `m_prev_framezero_pc`. StopInfoMachException needs this
information to check all of the conditions I outlined above for
`IsContinueInterrupted`.

This has passed exhaustive testing and we do not have any testsuite
failures for hardware watchpoints and breakpoints due to this kernel bug
with the patch in place. In focusing on these tests for thousands of
runs, I have found two other uncommon race conditions for the
TestConcurrent* tests on arm64. TestConcurrentManyBreakpoints.py (which
uses no hardware watchpoint/breakpoints) will sometimes only have 99
breakpoints when it expects 100, and any of the concurrent tests using
the shared harness (I've seen it in
TestConcurrentWatchBreakDelay.py,
TestConcurrentTwoBreakpointsOneSignal.py,
TestConcurrentSignalDelayWatch.py) can fail when the test harness checks
that there is only one thread still running at the end, and it finds two
-- one of them under pthread_exit / pthread_terminate. Both of these
failures happen on github main without my changes, and with my changes -
they are unrelated race conditions in these tests, and I'm sure I'll be
looking into them at some point if they hit the CI bots with frequency.
On my computer, these are in the 0.3-0.5% of the time class. But the CI
bots do have different timing.
2024-02-14 13:06:20 -08:00
Alex Langford
307cd88354
[lldb][NFCI] Remove CommandObjectProcessHandle::VerifyCommandOptionValue (#79901)
I was refactoring something else but ran into this function. It was
somewhat confusing to read through and understand, but it boils down to
two steps:
- First we try `OptionArgParser::ToBoolean`. If that works, then we're
good to go.
- Second, we try `llvm::to_integer` to see if it's an integer. If it
parses to 0 or 1, we're good.
- Failing either of the steps above means we cannot parse it into a
bool.

Instead of having an integer out param and a bool return value, the
interface is better served with an optional<bool> -- Either it parses
into true or false, or you get back nothing (nullopt).
2024-02-14 10:20:58 -08:00
Jim Ingham
3647ff159a Used std::vector::reserve when I meant std::vector::resize.
The Linux std has more asserts enabled by default, so it
complained, even though this worked on Darwin...
2024-02-13 16:12:20 -08:00
Felipe de Azevedo Piovezan
91f4a84a15
[lldb][DWARFIndex] Use IDX_parent to implement GetFullyQualifiedType query (#79932)
This commit changes DebugNamesDWARFIndex so that it now overrides
`GetFullyQualifiedType` and attempts to use DW_IDX_parent, when
available, to speed up such queries. When this type of information is
not available, the base-class implementation is used.

With this commit, we now achieve the 4x speedups reported in [1].

[1]:
https://discourse.llvm.org/t/rfc-improve-dwarf-5-debug-names-type-lookup-parsing-speed/74151/38
2024-02-13 13:20:49 -08:00
jimingham
a69ecb2420
Add the ability to define a Python based command that uses CommandObjectParsed (#70734)
This allows you to specify options and arguments and their definitions
and then have lldb handle the completions, help, etc. in the same way
that lldb does for its parsed commands internally.

This feature has some design considerations as well as the code, so I've
also set up an RFC, but I did this one first and will put the RFC
address in here once I've pushed it...

Note, the lldb "ParsedCommand interface" doesn't actually do all the
work that it should. For instance, saying the type of an option that has
a completer doesn't automatically hook up the completer, and ditto for
argument values. We also do almost no work to verify that the arguments
match their definition, or do auto-completion for them. This patch
allows you to make a command that's bug-for-bug compatible with built-in
ones, but I didn't want to stall it on getting the auto-command checking
to work all the way correctly.

As an overall design note, my primary goal here was to make an interface
that worked well in the script language. For that I needed, for
instance, to have a property-based way to get all the option values that
were specified. It was much more convenient to do that by making a
fairly bare-bones C interface to define the options and arguments of a
command, and set their values, and then wrap that in a Python class
(installed along with the other bits of the lldb python module) which
you can then derive from to make your new command. This approach will
also make it easier to experiment.

See the file test_commands.py in the test case for examples of how this
works.
2024-02-13 11:09:47 -08:00
jimingham
a04c6366b1
Don't count all the frames just to skip the current inlined ones. (#80918)
The algorithm to find the DW_OP_entry_value requires you to find the
nearest non-inlined frame. It did that by counting the number of stack
frames so that it could use that as a loop stopper.

That is unnecessary and inefficient. Unnecessary because GetFrameAtIndex
will return a null frame when you step past the oldest frame, so you
already have the "got to the end" signal without counting all the stack
frames.
And counting all the stack frames can be expensive.
2024-02-13 11:06:32 -08:00