Commit Graph

6092 Commits

Author SHA1 Message Date
Augusto Noronha c18304e600 [lldb] Remote accidental logs left in TestGuiExpandThreadsTree 2022-07-22 16:06:49 -07:00
Augusto Noronha 3b8a1cc38a [lldb] Disable TestGuiExpandThreadsTree 2022-07-22 16:00:51 -07:00
David Spickett 1ac12a5177 [lldb][ARM] Invert emulation test assert message
Previously you got:
AssertionError: False is not True : Emulation test succeeded.

Which is a bit of a head scratcher. The message is used when
the test fails, not when it succeeds.
2022-07-22 09:35:30 +00:00
Michael Buch 8184b252cd [LLDB][ClangExpression] Allow expression evaluation from within C++ Lambdas
This patch adds support for evaluating expressions which reference
a captured `this` from within the context of a C++ lambda expression.
Currently LLDB doesn't provide Clang with enough information to
determine that we're inside a lambda expression and are allowed to
access variables on a captured `this`; instead Clang simply fails
to parse the expression.

There are two problems to solve here:
1. Make sure `clang::Sema` doesn't reject the expression due to an
illegal member access.
2. Materialize all the captured variables/member variables required
to evaluate the expression.

To address (1), we currently import the outer structure's AST context
onto `$__lldb_class`, making the `contextClass` and the `NamingClass`
match, a requirement by `clang::Sema::BuildPossibleImplicitMemberExpr`.

To address (2), we inject all captured variables as locals into the
expression source code.

**Testing**

* Added API test
2022-07-22 08:02:09 +01:00
Michael Buch 317c8bf84d [LLDB][Expression] Allow instantiation of IR Entity from ValueObject
This is required in preparation for the follow-up patch which adds
support for evaluating expressions from within C++ lambdas. In such
cases we need to materialize variables which are not part of the
current frame but instead are ivars on a 'this' pointer of the current
frame.
2022-07-22 08:02:08 +01:00
Michał Górny b61b8efcf3 [lldb] [gdb-remote] Fix process ID after following forked child
Update the process ID after handling fork/vfork to ensure that
the process plugin reports the correct PID immediately.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D130037
2022-07-21 17:11:38 +02:00
Pavel Labath cd18e2ea3f [lldb/test] Fix flakyness in TestNonStop.test_stdio
The test was assuming that the output will come in two messages. The
truth is that it will come in **at least** two messages.
2022-07-21 16:53:13 +02:00
Michael Buch 140bcd369b [LLDB][ClangExpression] Fix initialization of static enum alias members
`IntegerLiteral::Create` operates on integer types. For that reason
when we parse DWARF into an AST, when we encounter a constant
initialized enum member variable, we try to determine the underlying
integer type before creating the `IntegerLiteral`. However, we
currently don't desugar the type and for enum typedefs
`dyn_cast<EnumType>` fails. In debug builds this triggers following
assert:

```
Assertion failed: (type->isIntegerType() && "Illegal type in IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892
```

This patch turns the `dyn_cast<EnumType>` into a `getAs<EnumType>`
which `dyn_cast`s the canonical type, allowing us to get to the
underlying integer type.

**Testing**

* API test
* Manual repro is fixed

Differential Revision: https://reviews.llvm.org/D130213
2022-07-21 14:23:41 +01:00
Michael Buch 6703812688 [LLDB][DataFormatter] Add support for std::__map_const_iterator
This patch adds support for formatting `std::map::const_iterator`.
It's just a matter of adding `const_` to the existing regex.

**Testing**

* Added test case to existing API tests

Differential Revision: https://reviews.llvm.org/D129962
2022-07-21 14:21:12 +01:00
Zequan Wu b8cf916b89 [LLDB][NativePDB] Add MSInheritanceAttr when creating pointer type that is a pointer to member.
Differential Revision: https://reviews.llvm.org/D129807
2022-07-19 15:36:35 -07:00
Jim Ingham 83fab8cee9 Revert "Make hit point counts reliable for architectures that stop before evaluation."
This reverts commit 5778ada8e5.

The watchpoint tests all stall on aarch64-ubuntu bots.  Reverting till I can
get my hands on an system to test this out.
2022-07-18 17:38:43 -07:00
Jim Ingham e83d47f6b7 When the module path for `command script import` is invalid, echo the path.
We were just emitting "invalid module" w/o saying which module.  That's
not particularly helpful.

Differential Revision: https://reviews.llvm.org/D129338
2022-07-18 14:49:07 -07:00
Jim Ingham 5778ada8e5 Make hit point counts reliable for architectures that stop before evaluation.
Since we want to present the "new & old" values for watchpoint hits, on architectures,
including the ARM family, that stop before the triggering instruction is run, we need
to single step over the instruction before stopping for realz.  This was incorrectly
done directly in the StopInfoWatchpoint::ShouldStop.  That causes problems if more than
one thread stops "for a reason" at the same time as the watchpoint, since the other actions
didn't expect the process to make progress in this part of the execution control machinery.

The correct way to do this is to schedule the step over using ThreadPlans, and then to restore
the stop info after that plan stops, so that the rest of the stop info actions can happen when
all the other threads have handled their immediate actions as well.

Differential Revision: https://reviews.llvm.org/D129814
2022-07-18 14:36:32 -07:00
Michał Górny 09531ede6d [lldb] [llgs] Improve stdio forwarding in multiprocess+nonstop
Enable stdio forwarding when nonstop mode is enabled, and disable it
once it is disabled.  This makes it possible to cleanly handle stdio
forwarding while running multiple processes in non-stop mode.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128932
2022-07-15 21:50:39 +02:00
Michał Górny fc92f11441 [lldb] [test] Skip test_leave_nonstop on Windows 2022-07-15 21:48:03 +02:00
Michał Górny c732afa2c2 [lldb] [llgs] Fix disabling non-stop mode
Stop all processes and clear notification queues when disabling non-stop
mode.  Ensure that no stop notifications are sent for processes stopped
due to the mode switch.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128893
2022-07-15 20:16:49 +02:00
Michał Górny 5d6659739c [lldb] [test] Skip test_stop_reason_while_running on Windows 2022-07-15 20:14:55 +02:00
Michał Górny ab9f1e88fd [lldb] [llgs] Fix `?` packet response for running threads
Fix the response to `?` packet for threads that are running at the time
(in non-stop mode).  The previous code would wrongly send or queue
an empty response for them.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128879
2022-07-15 18:33:58 +02:00
Michał Górny 81e993f08d [lldb] [test] Skip TestNonStop → test_stdio on Windows 2022-07-15 18:33:19 +02:00
Michał Górny 1903f358bc [lldb] [llgs] Send process output asynchronously in non-stop mode
Introduce a new %Stdio notification category and use it to send process
output asynchronously when running in non-stop mode.  This is an LLDB
extension since GDB does not use the 'O' packet for process output,
just for replies to 'qRcmd' packets.

Using the async notification mechanism implies that only the first
output packet is sent immediately to the client.  The client needs
to request subsequent notifications (if any) using the new vStdio packet
(that works pretty much like vStopped for the Stop notification queue).

The packet handler in lldb-server tests is updated to handle the async
stdio packets in addition to the regular O packets.  However, due
to the implications noted above, it can only handle the first output
packet sent by the server.  Subsequent packets need to be explicitly
requested via vStdio.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128849
2022-07-15 17:20:39 +02:00
Michał Górny 5a6f1f3271 [lldb] [test] Skip new NonStop tests on Windows 2022-07-15 16:02:47 +02:00
David Spickett cd2e36eadd [lldb][AArch64] Enable int128 test
Other 128 bit tests run on AArch64 fine, it's
Arm (as in 32 bit Arm) that needs to be skipped.
2022-07-15 13:35:48 +00:00
Michał Górny eb43e43bb5 Reland "[lldb] [llgs] Fix multi-resume bugs with nonstop mode"
Improve handling of multiple successive continue packets in non-stop
mode.  More specifically:

1. Explicitly send error response (instead of crashing on assertion)
   if the user attempts to resume the same process twice.  Since we
   do not support thread-level non-stop mode, one needs to always stop
   the process explicitly before resuming another thread set.

2. Actually stop the process if "vCont;t" is delivered to a running
   process.  Similarly, we only support stopping all the running threads
   simultaneously (via -1) and return an error in any other case.

With this patch, running multiple processes simultaneously is still
unsupported.  The patch also employs a hack to avoid enabling stdio
forwarding on "vCont;t" packet.  Both of these issues are addressed
by followup patches.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128710
2022-07-15 15:24:00 +02:00
Michał Górny 7a2b09b479 Revert "[lldb] [llgs] Fix multi-resume bugs with nonstop mode"
This reverts commit f8605da875.
This is causing buildbot failures and now I see that I have not updated
the tests to use "stop" instead of "trap".
2022-07-15 13:43:34 +02:00
Michał Górny f8605da875 [lldb] [llgs] Fix multi-resume bugs with nonstop mode
Improve handling of multiple successive continue packets in non-stop
mode.  More specifically:

1. Explicitly send error response (instead of crashing on assertion)
   if the user attempts to resume the same process twice.  Since we
   do not support thread-level non-stop mode, one needs to always stop
   the process explicitly before resuming another thread set.

2. Actually stop the process if "vCont;t" is delivered to a running
   process.  Similarly, we only support stopping all the running threads
   simultaneously (via -1) and return an error in any other case.

With this patch, running multiple processes simultaneously is still
unsupported.  The patch also employs a hack to avoid enabling stdio
forwarding on "vCont;t" packet.  Both of these issues are addressed
by followup patches.

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.llvm.org/D128710
2022-07-15 13:01:39 +02:00
Andy Yankovsky 7d297de951 Reland "[lldb] Add support for using integral const static data members in the expression evaluator"
Reland 486787210d which broke tests on Arm and Windows.

* Windows -- on Windows const static data members with no out-of-class
  definition do have valid addresses, in constract to other platforms
  (Linux, macos) where they don't. Adjusted the test to expect success
  on Windows and failure on other platforms.

* Arm -- `int128` is not available on 32-bit ARM, so disable the test
  for this architecture.
2022-07-15 10:52:35 +00:00
Jonas Devlieghere bcae3cdbd0
[lldb] Print the enum values and their description in the help output
Print the enum values and their description in the help output for
argument values. Until now, there was no way to get these values and
their description.

Example output:

(lldb) help <description-verbosity>
  <description-verbosity> -- How verbose the output of 'po' should be.

     compact : Only show the description string
     full    : Show the full output, including persistent variable's
               name and type

Differential revision: https://reviews.llvm.org/D129707
2022-07-14 21:18:08 -07:00
Stella Stamenova c3a28e8a99 Revert "[lldb] Add support for using integral const static data members in the expression evaluator"
This reverts commit 486787210d.

This broke the windows lldb bot: https://lab.llvm.org/buildbot/#/builders/83/builds/21186
2022-07-14 10:47:01 -07:00
Fangrui Song ecfaf4801c [lldb] Remove ELF .zdebug support
clang 14 removed -gz=zlib-gnu support and ld.lld/llvm-objcopy removed zlib-gnu
support recently. Remove lldb support by migrating away from
llvm::object::Decompressor::isCompressedELFSection.
The API has another user llvm-dwp, so it is not removed in this patch.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D129724
2022-07-14 10:12:48 -07:00
Andy Yankovsky 486787210d [lldb] Add support for using integral const static data members in the expression evaluator
This adds support for using const static integral data members as described by C++11 [class.static.data]p3
to LLDB's expression evaluator.

So far LLDB treated these data members are normal static variables. They already work as intended when they are declared in the class definition and then defined in a namespace scope. However, if they are declared and initialised in the class definition but never defined in a namespace scope, all LLDB expressions that use them will fail to link when LLDB can't find the respective symbol for the variable.

The reason for this is that the data members which are only declared in the class are not emitted into any object file so LLDB can never resolve them. Expressions that use these variables are expected to directly use their constant value if possible. Clang can do this for us during codegen, but it requires that we add the constant value to the VarDecl we generate for these data members.

This patch implements this by:
* parsing the constant values from the debug info and adding it to variable declarations we encounter.
* ensuring that LLDB doesn't implicitly try to take the address of expressions that might be an lvalue that points to such a special data member.

The second change is caused by LLDB's way of storing lvalues in the expression parser. When LLDB parses an expression, it tries to keep the result around via two mechanisms:

1. For lvalues, LLDB generates a static pointer variable and stores the address of the last expression in it: `T *$__lldb_expr_result_ptr = &LastExpression`
2. For everything else, LLDB generates a static variable of the same type as the last expression and then direct initialises that variable: `T $__lldb_expr_result(LastExpression)`

If we try to print a special const static data member via something like `expr Class::Member`, then LLDB will try to take the address of this expression as it's an lvalue. This means LLDB will try to take the address of the variable which causes that Clang can't replace the use with the constant value. There isn't any good way to detect this case (as there a lot of different expressions that could yield an lvalue that points to such a data member), so this patch also changes that we only use the first way of capturing the result if the last expression does not have a type that could potentially indicate it's coming from such a special data member.

This change shouldn't break most workflows for users. The only observable side effect I could find is that the implicit persistent result variables for const int's now have their own memory address:

Before this change:
```
(lldb) p i
(const int) $0 = 123
(lldb) p &$0
(const int *) $1 = 0x00007ffeefbff8e8
(lldb) p &i
(const int *) $2 = 0x00007ffeefbff8e8
```

After this change we capture `i` by value so it has its own value.
```
(lldb) p i
(const int) $0 = 123
(lldb) p &$0
(const int *) $1 = 0x0000000100155320
(lldb) p &i
(const int *) $2 = 0x00007ffeefbff8e8
```

Reviewed By: Michael137

Differential Revision: https://reviews.llvm.org/D81471
2022-07-14 15:15:11 +00:00
Jason Molenda ac49e90219 jGetLoadedDynamicLibrariesInfos can inspect machos not yet loaded
jGetLoadedDynamicLibrariesInfos normally checks with dyld to find
the list of binaries loaded in the inferior, and getting the filepath,
before trying to parse the Mach-O binary in inferior memory.
This allows for debugserver to parse a Mach-O binary present in memory,
but not yet registered with dyld.  This patch also adds some simple
sanity checks that we're reading a Mach-O header before we begin
stepping through load commands, because we won't have the sanity check
of consulting dyld for the list of loaded binaries before parsing.
Also adds a testcase.

[This patch was reverted after causing a testsuite failure on a CI bot;
I haven't been able to repro the failure outside the CI, but I have a
theory that my sanity check on cputype which only matched arm64 and
x86_64 - and the CI machine may have a watch simulator that is still
using i386.]

Differential Revision: https://reviews.llvm.org/D128956
rdar://95737734
2022-07-14 00:56:14 -07:00
Dave Lee b5ccfeb6bf [lldb] Add image dump pcm-info command
Add `pcm-info` to the `target module dump` subcommands.

This dump command shows information about clang .pcm files. This command
effectively runs `clang -module-file-info` and produces identical output.

The .pcm file format is tightly coupled to the clang version. The clang
embedded in lldb is not guaranteed to match the version of the clang executable
available on the local system.

There have been times when I've needed to view the details about a .pcm file
produced by lldb's embedded clang, but because the clang executable was a
slightly different version, the `-module-file-info` invocation failed. With
this command, users can inspect .pcm files generated by lldb too.

Differential Revision: https://reviews.llvm.org/D129456
2022-07-13 16:56:53 -07:00
ymeng 0466d1df23 [trace][intel pt] Support dumping the trace info in json
Thanks to ymeng@fb.com for coming up with this change.

`thread trace dump info` can dump some metrics that can be useful for
analyzing the performance and quality of a trace. This diff adds a --json
option for dumping this information in json format that can be easily
understood my machines.

Differential Revision: https://reviews.llvm.org/D129332
2022-07-13 12:26:11 -07:00
Walter Erquinigo 4a843d9282 [trace][intel pt] Create a CPU change event and expose it in the dumper
Thanks to fredzhou@fb.com for coming up with this feature.

When tracing in per-cpu mode, we have information of in which cpu we are execution each instruction, which comes from the context switch trace. This diff makes this information available as a `cpu changed event`, which an additional accessor in the cursor `GetCPU()`. As cpu changes are very infrequent, any consumer should listen to cpu change events instead of querying the actual cpu of a trace item. Once a cpu change event is seen, the consumer can invoke GetCPU() to get that information. Also, it's possible to invoke GetCPU() on an arbitrary instruction item, which will return the last cpu seen. However, this call is O(logn) and should be used sparingly.

Manually tested with a sample program that starts on cpu 52, then goes to 18, and then goes back to 52.

Differential Revision: https://reviews.llvm.org/D129340
2022-07-13 12:26:11 -07:00
Walter Erquinigo b532dd545f [trace] Add an option to save a compact trace bundle
A trace bundle contains many trace files, and, in the case of intel pt, the
largest files are often the context switch traces because they are not
compressed by default. As a way to improve this, I'm adding a --compact option
to the `trace save` command that filters out unwanted processes from the
context switch traces. Eventually we can do the same for intel pt traces as
well.

Differential Revision: https://reviews.llvm.org/D129239
2022-07-13 11:43:28 -07:00
rnofenko db73a52d7b [trace][intel pt] Add a nice parser for the trace size
Thanks to rnofenko@fb.com for coming up with these changes.

This diff adds support for passing units in the trace size inputs. For example,
it's now possible to specify 64KB as the trace size, instead of the
problematic 65536. This makes the user experience a bit friendlier.

Differential Revision: https://reviews.llvm.org/D129613
2022-07-13 10:53:14 -07:00
Muhammad Omair Javaid f827b4b657 [LLDB] Fix TestConvenienceVariables.test AArch64/Windows
This patch fixes TestConvenienceVariables.test for AArch64 Windows.
Clang/LLD was unable to find printf apparently available as a macro
definition in stdio.h.
2022-07-13 16:46:55 +05:00
Muhammad Omair Javaid 7610524af3 [LLDB] Fix TestThreadAPI.py for AArch64/Windows
This patch fixes TestThreadAPI for AArch64 windows by switching over to
PDB debug info instead of DWARF. This is needed to step over library
functions like printf as there is debug info mismatch between DWARF and
PDB. PDB DWARF interworking is not fully supported by LLDB at the
moment.
2022-07-13 16:30:09 +05:00
Muhammad Omair Javaid b82b018712 [LLDB] XFail TestLoadUnload.test_static_init_during_load AArch64/Windows
This patch fixes marks TestLoadUnload.test_static_init_during_load as
xfail for AArch64 windows. It is failing similar to Linux and already
marked xfail for linux.
2022-07-13 16:18:18 +05:00
Muhammad Omair Javaid 891319f654 [LLDB] Fix pointers.test for AArch64/Windows
pointers.test started failing again for AArch64 windows after D125509
This patch fixes the test to make it pass on AArch64 windows again.

LLDB AArch64 Windows buildbot running at:
https://lab.llvm.org/staging/#/builders/207
2022-07-13 15:55:31 +05:00
Jonas Devlieghere 5edfc0b928
[lldb] Fix macOS Ventura version number checks
Unlike Python 2 which reports 10.16 on any recent macOS, Python 3
correctly reports Ventura as macOS 13.
2022-07-12 13:29:46 -07:00
Zequan Wu b74a01a80b Reland "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."
This reland 227dffd0b6 and
562c3467a6 with failed api tests fixed by keeping
function base file addres in DWARFExpressionList.
2022-07-12 10:54:24 -07:00
Muhammad Omair Javaid 7b69843f0b [LLDB] Catagory decorator for watchpoint test in TestCompletion.py
This patch adds watchpoint catagory decorator to watchpoint dependent
tests in TestCompletion.py.
2022-07-12 17:15:33 +05:00
Muhammad Omair Javaid 68cc1eeb1d [LLDB] Fix NativePDB/local-variables.cpp for AArch64/Windows
This patch fixes NativePDB/local-variables.cpp test for AArch64 Windows.
There are two changes:
1) Replace function breakpoint with line breakpoint required due to pr56288
2) Adjust "target modules dump ast" test as the output was slightly different
on AArch64/Windows.
2022-07-12 16:26:47 +05:00
David M. Lary 1e3ee766bb [lldb] add SBSection.alignment to python bindings
This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb.

Reviewed By: clayborg, JDevlieghere, labath

Differential Revision: https://reviews.llvm.org/D128069
2022-07-12 12:18:38 +02:00
Pavel Labath 918b1e7bbd Revert "[lldb] add SBSection.alignment to python bindings"
The patch didn't get proper attribution. Will recommit.

This reverts commit 4135abca89.
2022-07-12 12:17:29 +02:00
Pavel Labath 4135abca89 [lldb] add SBSection.alignment to python bindings
This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb.

Reviewed By: clayborg, JDevlieghere, labath

Differential Revision: https://reviews.llvm.org/D128069
2022-07-12 12:14:54 +02:00
Michael Buch d1e9d0b27f [LLDB][DataFormatter] Add data formatter for libcxx std::unordered_map iterator
This patch adds a formatter for libcxx's `std::unordered_map` iterators.
The implementation follows a similar appraoch to the `std::map` iterator
formatter. I was hesistant about coupling the two into a common
implementation since the libcxx layouts might change for one of the
the containers but not the other.

All `std::unordered_map` iterators are covered with this patch:
1. const/non-const key/value iterators
2. const/non-const bucket iterators

Note that, we currently don't have a formatter for `std::unordered_map`.
This patch doesn't change that, we merely add support for its iterators,
because that's what Xcode users requested. One can still see contents
of `std::unordered_map`, whereas with iterators it's less ergonomic.

**Testing**

* Added API test

Differential Revision: https://reviews.llvm.org/D129364
2022-07-12 10:13:55 +01:00
Jonas Devlieghere ce233e7146
[lldb] Use the just-built libc++ for testing the LLDB data formatters
Make sure we use the libc++ from the build dir. Currently, by passing
-stdlib=libc++, we might pick up the system libc++. This change ensures
that if LLVM_LIBS_DIR is set, we try to use the libc++ from there.

Differential revision: https://reviews.llvm.org/D129166
2022-07-11 14:49:24 -07:00
Martin Storsjö 66cdd6548a [lldb] Reduce the stack alignment requirements for the Windows x86_64 ABI
This fixes https://github.com/llvm/llvm-project/issues/56095.

Differential Revision: https://reviews.llvm.org/D129455
2022-07-11 23:41:35 +03:00