301 Commits

Author SHA1 Message Date
Jonas Devlieghere
a1b14dbc47
[lldb] Remove progress report coalescing (#130329)
Remove support for coalescing progress reports in LLDB. This
functionality was motivated by Xcode, which wanted to listen for less
frequent, aggregated progress events at the cost of losing some detail.
See the original RFC [1] for more details. Since then, they've
reevaluated this trade-off and opted to listen for the regular, full
fidelity progress events and do any post processing on their end.

rdar://146425487
2025-03-08 09:10:46 -08:00
Jacob Lalonde
3ff6fb68d7
[LLDB][SBProgress] Add a finalize method (#128966)
This patch adds a finalize method which destroys the underlying RAII
SBProgress. My primary motivation for this is so I can write better
tests that are non-flaky, but after discussing with @clayborg in my DAP
message improvement patch (#124648) this is probably an essential API
despite that I originally argued it wasn't.
2025-03-03 14:01:29 -08:00
Eisuke Kawashima
24abf2c728
[lldb] fix(lldb/**.py): fix invalid escape sequences (#94034)
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2025-02-28 14:59:35 +00:00
Jacob Lalonde
10a9dcab0a
[LLDB][SBProgress] Fix bad optional in sbprogress (#128971)
This fixes the obvious, but untested case of sending None/Null to
SBProgress.
2025-02-27 11:08:20 -08:00
oltolm
ccbb8882ac
[lldb] do not show misleading error when there is no frame (#119103)
I am using VSCode with the official vscode-lldb extension. When I try to
list the breakpoints in the debug console get the message:

```
br list
can't evaluate expressions when the process is running.
```

I know that this is wrong and you need to use
```
`br list
(lldb) br list
No breakpoints currently set.
```
but the error message is misleading. I cleaned up the code and now the
error message is

```
br list
sbframe object is not valid.
```
which is still not perfect, but at least it's not misleading.
2025-02-24 17:52:09 -06:00
Jonas Devlieghere
4722200773
[lldb] Merge TestSBCommandReturnObject tests
In #125132, Michael pointed out that there are now two tests with the
same name:

./lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py
./lldb/test/API/python_api/commandreturnobject/TestSBCommandReturnObject.py
2025-02-09 11:16:59 -08:00
Ben Jackson
e8d437f827
[lldb] WatchAddress ignores modify option (#124847)
The WatchAddress API includes a flag to indicate if watchpoint should be
for read, modify or both. This API uses 2 booleans, but the 'modify'
flag was ignored and WatchAddress unconditionally watched write
(actually modify).

We now only watch for modify when the modify flag is true.

---

The included test fails prior to this patch and succeeds after. That is
previously specifying `False` for `modify` would still stop on _write_,
but after the patch correctly only stops on _read_
2025-02-04 16:03:13 -08:00
Jonas Devlieghere
53d6e59b59
[lldb] Check the command string in TestCommandInterepterPrintCallback
Now that we store the command in the CommandReturnObject (#125132) we
can check the command in the print callback.
2025-02-04 10:42:08 -08:00
Jonas Devlieghere
97f6e53386
[lldb] Support CommandInterpreter print callbacks (#125006)
Xcode uses a pseudoterminal for the debugger console.

- The upside of this apporach is that it means that it can rely on
LLDB's IOHandlers for multiline and script input.
- The downside of this approach is that the command output is printed to
the PTY and you don't get a SBCommandReturnObject. Adrian added support
for inline diagnostics (#110901) and we'd like to access those from the
IDE.

This patch adds support for registering a callback in the command
interpreter that gives access to the `(SB)CommandReturnObject` right
before it will be printed. The callback implementation can choose
whether it likes to handle printing the result or defer to lldb. If the
callback indicated it handled the result, the command interpreter will
skip printing the result.

We considered a few other alternatives to solve this problem:

- The most obvious one is using `HandleCommand`, which returns a
`SBCommandReturnObject`. The problem with this approach is the multiline
input mentioned above. We would need a way to tell the IDE that it
should expect multiline input, which isn't known until LLDB starts
handling the command.
- To address the multiline issue,we considered exposing (some of the)
IOHandler machinery through the SB API. To solve this particular issue,
that would require reimplementing a ton of logic that already exists
today in the CommandInterpeter. Furthermore that seems like overkill
compared to the proposed solution.

rdar://141254310
2025-02-04 09:01:08 -08:00
Jonas Devlieghere
906eeeda83
[lldb] Store the command in the CommandReturnObject (#125132)
As suggested in #125006. Depending on which PR lands first, I'll update
`TestCommandInterepterPrintCallback.py` to check that the
`CommandReturnObject` passed to the callback has the correct command.
2025-02-04 08:55:30 -08:00
Jacob Lalonde
6b048aeaf8
[LLDB] Add SBProgress so Python scripts can also report progress (#119052)
Recently I've been working on a lot of internal Python tooling, and in
certain cases I want to report async to the script over DAP. Progress.h
already handles this, so I've exposed Progress via the SB API so Python
scripts can also update progress objects.

I actually have no idea how to test this, so I just wrote a [toy command
to test
it](https://gist.github.com/Jlalond/48d85e75a91f7a137e3142e6a13d0947)


![image](https://github.com/user-attachments/assets/7317cbb8-9145-4fdb-bacf-9864bf50c467)

I also copied the first section of the extensive Progress.h class
documentation to the docstrings.
2025-01-17 12:00:31 -08:00
Jacob Lalonde
06edefac10
[LLDB] Make the thread list for SBSaveCoreOptions iterable (#122541)
This patch adds the ability to get a thread at a give index, based on
insertion order, for SBSaveCore Options. This is primarily to benefit
scripts using SBSaveCore, and remove the need to have both options and a
second collection if your script is tracking what threads need to be
saved. Such as if you want to collect the source of all the threads to
be saved after the Core is generated.
2025-01-16 11:49:02 -08:00
Dave Lee
53fd724b25
[lldb] Add lookup by name to SBValue through new member property (#118814)
Introduces a `member` property to `SBValue`. This property provides pythonic access to a
value's members, by name. The expression `value.member["name"]` will be an alternate
form form of writing `value.GetChildMemberWithName("name")`.
2024-12-09 10:48:28 -08:00
Luke Riddle
2a1a02461a
Make SBMemoryRegionInfoList iterable with Python SWIG (#117358)
This PR fixes a simple SWIG issue with SBMemoryRegionInfoList not being
iterable out-of-the-box. This is mostly because of limitations to the
`lldb_iter` function, which doesn't allow for specifying arguments to
the size / iter functions passed.

Before:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> for region in lldb.process.GetMemoryRegions():
...   print(region)
...
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/llvm/stable/Toolchains/llvm-sand.xctoolchain/usr/lib/python3.10/site-packages/lldb/__init__.py", line 114, in lldb_iter
    yield elem(i)
TypeError: SBMemoryRegionInfoList.GetMemoryRegionAtIndex() missing 1 required positional argument: 'region_info'
```

After:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> for region in lldb.process.GetMemoryRegions():
...   print(region)
... 
[0x0000000000200000-0x00000000002cf000 R--]
[0x00000000002cf000-0x0000000000597000 R-X]
[0x0000000000597000-0x00000000005ad000 R--]
[0x00000000005ad000-0x00000000005b1000 RW-]
[0x00000000005b1000-0x0000000000b68000 RW-]
[0x000000007fff7000-0x000000008fff7000 RW-]
[0x000002008fff7000-0x000010007fff8000 RW-]
[0x0000503000000000-0x0000503000010000 RW-]
[0x0000503e00000000-0x0000503e00010000 RW-]
[0x0000504000000000-0x0000504000010000 RW-]
[0x0000504e00000000-0x0000504e00010000 RW-]
[0x000050d000000000-0x000050d000010000 RW-]
[0x000050de00000000-0x000050de00010000 RW-]
[0x000050e000000000-0x000050e000010000 RW-]
[0x000050ee00000000-0x000050ee00010000 RW-]
[0x0000511000000000-0x0000511000010000 RW-]
[0x0000511e00000000-0x0000511e00010000 RW-]
[0x0000513000000000-0x0000513000010000 RW-]
...
```
2024-12-03 10:29:12 -08:00
Jonas Devlieghere
4714215efb
[lldb] Support true/false in ValueObject::SetValueFromCString (#115780)
Support "true" and "false" (and "YES" and "NO" in Objective-C) in
ValueObject::SetValueFromCString.

Fixes #112597
2024-11-12 21:18:22 -08:00
Dmitry Vasilyev
1277bea431
[lldb] Disable TestCancelAttach for Windows host (#115619)
See #115618 for details.
2024-11-11 12:40:01 +04:00
Wanyi
f7c36d2f88
[lldb] Fix API test for file redirection to existing files (#114119)
API test failed for remote platform in
[#112657](https://github.com/llvm/llvm-project/pull/112657)

Previously when putting files onto remote platform, I used `platform
file write -d <data>` which actually required a `platform file open
<path>` first in order to obtain a file descriptor.
eg. in file
[TestGDBRemotePlatformFile.py](94e7d9c0bf/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py (L24-L32))
To fix this, use the `platform put-file` method, which is used in the
`redirect_stdin` from this test already.
2024-10-30 17:00:40 -04:00
jimingham
a575e6e5ca
Fix a couple of tests that were incorrectly using configuration.dwarf_version (#114161)
The tests were using the variable directly to get the dwarf version used
for the test. That's only the overridden value, and won't be set if
we're using the compiler default. I also put a comment by the variable
to make sure people don't make the same mistake in the future.
2024-10-30 09:25:47 -07:00
Wanyi
efc6d33be9
[lldb] Fix write only file action to truncate the file (#112657)
When `FileAction` opens file with write access, it doesn't clear the
file nor append to the end of the file if it already exists. Instead, it
writes from cursor index 0.

For example, by using the settings `target.output-path` and
`target.error-path`, lldb will redirect process stdout/stderr to files.
It then calls this function to write to the files which the above
symptoms appear.

## Test
- Added unit test checking the file flags
- Added 2 api tests checking
  - File content overwritten if the file path already exists
- Stdout and stderr redirection to the same file doesn't change its
behavior
2024-10-29 14:22:51 -04:00
Igor Kudrin
b88d94caba
[lldb] Speed up FindInMemory tests (#111951)
A memory region can be relatively large. Searching for a value in the
entire region is time-consuming, especially when running tests against a
remote target, because the memory data is transferred in small chunks
over a relatively slow GDB Remote Protocol. The patch limits the address
range to be searched to 2K, which seems sufficient for these tests. In
my setup, for local runs, these tests now take half the time they did
before the patch. For a remote target, the improvement is even more
significant.
2024-10-18 14:13:27 -07:00
Luke Drummond
b55c52c047 Revert "Renormalize line endings whitespace only after dccebddb3b80"
This reverts commit 9d98acb196a40fee5229afeb08f95fd36d41c10a.
2024-10-18 21:16:50 +01:00
Luke Drummond
9d98acb196 Renormalize line endings whitespace only after dccebddb3b80
Line ending policies were changed in the parent, dccebddb3b80. To make
it easier to resolve downstream merge conflicts after line-ending
policies are adjusted this is a separate whitespace-only commit. If you
have merge conflicts as a result, you can simply `git add --renormalize
-u && git merge --continue` or `git add --renormalize -u && git rebase
--continue` - depending on your workflow.
2024-10-17 14:49:26 +01:00
Igor Kudrin
68a5f5db7c
[lldb] Fix TestGlobalModuleCache.py for remote debugging (#111483)
`SBDebugger().Create()` returns a debugger with only the host platform
in its platform list. If the test suite is running for a remote
platform, it should be explicitly added and selected in the new debugger
created within the test, otherwise, the test will fail because the host
platform may not be able to launch the built binary.
2024-10-09 18:11:05 -07:00
Pavel Labath
df6822f4eb
[lldb] Fix error reporting in SBTarget::ReadMemory (#109764)
The function should use the by-ref SBError argument instead of creating
a new one. This code has been here since ~forever, and was probably
copied from methods which return an SBError result (where one needs to
create a local variable).
2024-09-25 08:31:42 +02:00
Vladislav Dzhidzhoev
44fc987ed1
[lldb][test] Toolchain detection rewrite in Python (#102185)
This fix is based on a problem with cxx_compiler and cxx_linker macros
on Windows.
There was an issue with compiler detection in paths containing "icc". In
such case, Makefile.rules thought it was provided with icc compiler.

To solve that, utilities detection has been rewritten in Python.
The last element of compiler's path is separated, taking into account
the platform path delimiter, and compiler type is extracted, with regard
of possible cross-toolchain prefix.

---------

Co-authored-by: Pavel Labath <pavel@labath.sk>
2024-09-11 16:04:01 +03:00
Jacob Lalonde
572943e790
[LLDB] Reapply #100443 SBSaveCore Thread list (#104497)
Reapply #100443 and #101770. These were originally reverted due to a
test failure and an MSAN failure. I changed the test attribute to
restrict to x86 (following the other existing tests). I could not
reproduce the test or the MSAN failure and no repo steps were provided.
2024-08-15 16:29:59 -07:00
Med Ismail Bennani
585523750e
[lldb/API] Fix SBStructuredData support any JSON type (#101929)
This patch loosen the parsing requirement to allow parsing not only
JSON dictionaries but also valid JSON type (integer, float, string,
bool, array, null).

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-08-07 11:21:27 -07:00
Jacob Lalonde
accf5c9bb3
Revert "[LLDB][SBSaveCore] Implement a selectable threadlist for Core… (#102018)
… Options.  (#100443)"

This reverts commit 3e4af616334eae532f308605b89ff158dd195180.

@adrian-prantl FYI

Reverts #100443
2024-08-05 10:17:25 -07:00
Jacob Lalonde
3e4af61633
[LLDB][SBSaveCore] Implement a selectable threadlist for Core Options. (#100443)
In #98403 I enabled the SBSaveCoreOptions object, which allows users via
the scripting API to define what they want saved into their core file.
As the first option I've added a threadlist, so users can scan and
identify which threads and corresponding stacks they want to save.

In order to support this, I had to add a new method to `Process.h` on
how we identify which threads are to be saved, and I had to change the
book keeping in minidump to ensure we don't double save the stacks.

Important to @jasonmolenda I also changed the MachO coredump to accept
these new APIs.
2024-08-02 13:35:05 -07:00
Jacob Lalonde
4120570dc4
[LLDB][SaveCore] Add SBSaveCoreOptions Object, and SBProcess::SaveCore() overload (#98403)
This PR adds `SBSaveCoreOptions`, which is a container class for options
when LLDB is taking coredumps. For this first iteration this container
just keeps parity with the extant API of `file, style, plugin`. In the
future this options object can be extended to allow users to take a
subset of their core dumps.
2024-07-18 17:10:15 -07:00
Jim Ingham
a7816c8e00 git add a test file from a previous commit.
A new file was added to the python_api/events test, but I forgot to
git add it before making the PR.  The commit was:

44d9692e6a657ec46e98e4912ac56417da67cfee
2024-07-15 16:02:10 -07:00
jimingham
44d9692e6a
Private process events were being delivered to the secondary listener (#98571)
This fixes a bug where Process events were being delivered to secondary
listeners when the Private state thread listener was processing the
event. That meant the secondary listener could get an event before the
Primary listener did. That in turn meant the state when the secondary
listener got the event wasn't right yet. Plus it meant that the
secondary listener saw more events than the primary (not all events get
forwarded from the private to the public Process listener.)

This bug became much more evident when we had a stop hook that did some
work, since that delays the Primary listener event delivery. So I also
added a stop-hook to the test, and put a little delay in as well.
2024-07-15 15:07:01 -07:00
Vincent Belliard
82af55983d
[API] add GetSyntheticValue (#95959)
Adds GetSyntheticValue to the API on top of GetNonSyntheticValue.

---------

Co-authored-by: Vincent Belliard <v-bulle@github.com>
2024-07-15 17:28:56 +02:00
David Spickett
3e06392c7d [lldb][test] Fix instruction test step on Windows
On Windows the function name is the full prototype including
the calling convention, all we care about is that the last part
is correct.

This also reverts the xfail added by 07b3e2c0c68b93a3d4d89426dc7fd14cc31ca6be.
2024-07-10 11:22:07 +00:00
Pavel Labath
58e750bfd6
[lldb] Put the new debugger in synchronous mode in TestGlobalModuleCache (#98041)
In async mode, the test terminates sooner than it should
(`run_to_source_breakpoint` does not work in this mode), and then the
test crashes due to #76057. Most of the time, the test does not fail
because its already XFAILed, but the crash still registers as a failure.
2024-07-09 09:59:49 +02:00
Muhammad Omair Javaid
07b3e2c0c6 [LLDB] XFail on Windows TestThreadAPI.py test_StepInstruction
TestThreadAPI.py test_StepInstruction started failing after #97493

Following assertion fails but I am not sure if test will pass after
changing the test.

AssertionError: 'void __cdecl call_me(bool)' != 'call_me(bool)'

I have marked it as xfail I ll run it on a Windows machine to find
an appropriate fix.

https://lab.llvm.org/buildbot/#/builders/141/builds/476
2024-07-04 15:59:05 +05:00
jimingham
845dee36ba
SBThread::StepInstruction shouldn't discard other plans (#97493)
This was just a typo, none of the external execution control functions
should discard other plans. In particular, it means if you stop in a
hand-called function and step an instruction, the function call thread
plan gets unshipped, popping all the function call frames.

I also added a test that asserts the correct behavior. I tested all the
stepping operations even though only StepInstruction was wrong.
2024-07-03 10:45:20 -07:00
Eisuke Kawashima
586114510c
[lldb] fix(lldb/**.py): fix comparison to None (#94017)
from PEP8
(https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
is not, never the equality operators.

Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2024-06-26 15:59:07 +01:00
Miro Bucko
0d4da0df16
[lldb][API] Add Find(Ranges)InMemory() to Process SB API (#96569)
This is a second attempt to land #95007

Test Plan:
llvm-lit
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
2024-06-24 18:51:12 -04:00
Chelsea Cassanova
a32b7199f0
Revert commits that add TestFind(Ranges)InMemory.py (#96560)
Reverting to unblock macOS buildbots which are currently failing on
these tests.
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/6377/
2024-06-24 15:12:49 -07:00
Miro Bucko
33a9c57b89
[lldb] Fix failing TestFind(Ranges)InMemory.py tests. (#96511)
This is to unblock #95007. Will investigate why the assertion is failing
on some arch.
2024-06-24 11:38:05 -07:00
Miro Bucko
10bd5ad0a1
[lldb][API] Add Find(Ranges)InMemory() to Process SB API (#95007)
Test Plan:
llvm-lit
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py

llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
2024-06-24 11:06:20 -04:00
Miro Bucko
a083e50f53
[lldb] Fix SBAddressRange validation checks. (#95997) 2024-06-21 11:24:48 -04:00
Chelsea Cassanova
3d86eebdf8
Reland "[lldb][api-test] Add API test for SBCommandInterpreter::Comm… (#95181)
…andOverrideCallback (#94518)"

This reverts commit 7cff05ada05e87408966d56b4c1675033187ff5c. The API
test that was added erroneously imports a module that isn't needed and
wouldn't be found which causes a test failures. This reversion removes
that import.
2024-06-11 16:41:31 -07:00
Chelsea Cassanova
7cff05ada0 Revert "[lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (#94518)"
This reverts commit 6fb6eba9304b63e86ebf039edcb9a0b32e4b39e7.
This test breaks due to an incorrect import in the test.
2024-06-11 15:27:10 -07:00
Chelsea Cassanova
6fb6eba930
[lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (#94518)
`SBCommandInterpreter::CommandOverrideCallback` was not being exposed to
the Python API and has no coverage in the
API test suite, so this commits exposes and adds a test for it. Doing
this involves also adding a typemap for the callback used for this
function so that it matches the functionality of other callback
functions that are exposed to Python.
2024-06-11 15:20:35 -07:00
jimingham
435dd97461
Add AllowRepeats to SBCommandInterpreterRunOptions. (#94786)
This is useful if you have a transcript of a user session and want to
rerun those commands with RunCommandInterpreter. The same functionality
is also useful in testing.

I'm adding it primarily for the second reason. In a subsequent patch,
I'm adding the ability to Python based commands to provide their
"auto-repeat" command. Among other things, that will allow potentially
state destroying user commands to prevent auto-repeat. Testing this with
Shell or pexpect tests is not nearly as accurate or convenient as using
RunCommandInterpreter, but to use that I need to allow auto-repeat.

I think for consistency's sake, having interactive sessions always do
auto-repeats is the right choice, though that's a lightly held
opinion...
2024-06-07 17:05:29 -07:00
royitaqi
c2d061da7e
Re-merge A few updates around "transcript" (#92843) (#94067)
Problematic PR: https://github.com/llvm/llvm-project/pull/92843
Reverted by: https://github.com/llvm/llvm-project/pull/94088

The first PR added a test which fails in Linux builds (see the last few
comments there).
This PR contains all the changes in the first PR, plus the fix to the
said test.

---------

Co-authored-by: Roy Shi <royshi@meta.com>
2024-06-03 13:52:03 -07:00
gulfemsavrun
85fd1688b2
Revert "A few updates around "transcript"" (#94088)
Reverts llvm/llvm-project#92843 because it broke some lldb tests:

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8746385730949743489/overview
2024-05-31 20:06:18 -07:00
royitaqi
ad884d9728
A few updates around "transcript" (#92843)
# Changes

1. Changes to the structured transcript.
1. Add fields `commandName` and `commandArguments`. They will hold the
name and the arguments string of the expanded/executed command (e.g.
`breakpoint set` and `-f main.cpp -l 4`). This is not to be confused
with the `command` field, which holds the user input (e.g. `br s -f
main.cpp -l 4`).
2. Add field `timestampInEpochSeconds`. It will hold the timestamp when
the command is executed.
3. Rename field `seconds` to `durationInSeconds`, to improve
readability, especially since `timestampInEpochSeconds` is added.
2. When transcript is available and the newly added option
`--transcript` is present, add the transcript to the output of
`statistics dump`, as a JSON array under a new field `transcript`.
3. A few test name and comment changes.
2024-05-31 14:42:00 -07:00