290 Commits

Author SHA1 Message Date
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
jimingham
1e81b67925
[lldb] FormatManager::GetPossibleMatches assumes all ValueObjects have targets. (#93880)
But one made in a situation where that's impossible might only have an
error, and no symbol context, so that's not necessarily true. Check for
the target's validity before using it.

Fixes issue #93313
2024-05-31 10:43:05 -07:00
Miro Bucko
493eefc93f
[lldb][test] Fix failing test TestAddressRange.py (#93871)
Test llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py is failing on Windows due adding a carriage return character at the end of line. Original PR is #93836.
2024-05-30 13:44:51 -07:00
Miro Bucko
48175a5d9f
[lldb] Add SBAddressRange and SBAddressRangeList to SB API (#93836)
This adds new SB API calls and classes to allow a user of the SB API to obtain an address range from SBFunction and SBBlock. This is a second attempt to land the reverted PR #92014.
2024-05-30 10:38:21 -07:00
Dmitry Vasilyev
59e2a6b08f
[lldb] Fixed the TestDebuggerAPI test running on a remote target (#93829)
Recently we have disabled this test for Windows host and Linux target.
Now we faced the same issue #92419 in case of Linux x86_64 host and
Linux Aarch64 target.
2024-05-30 19:56:46 +04:00
Michael Buch
8b600a3732 Revert "Add SBAddressRange and SBAddressRangeList to SB API (#92014)"
This reverts commit 42944e4600827738fae868f0df831fb2678be8b4.
2024-05-30 12:40:05 +01:00
David Spickett
971f1aaad3 [lldb][Test][Windows] Fix flaky address range API tests
The new tests added in #92014 have been flaky on Linaro's
Windows on Arm bot. They appear to be hitting a deadlock trying
to clean up the test process.

This only happens in async mode and I don't see why this test
case needs async mode, so the simple workaround is to stick to
sync mode.
2024-05-29 10:07:47 +00:00
Miro Bucko
42944e4600
Add SBAddressRange and SBAddressRangeList to SB API (#92014)
This adds new SB API calls and classes to allow a user of the SB API to obtain an address ranges from SBFunction and SBBlock.
2024-05-28 09:29:10 -07:00
Dmitry Vasilyev
77369a7f1a
[lldb] Fixed the TestDebuggerAPI test on x86_64 Windows host (#90580)
Disable the TestDebuggerAPI test in case of the remote target and
Windows host.
2024-05-24 23:19:51 +04:00
royitaqi
9f62775038
SBDebugger: Add new APIs AddDestroyCallback and RemoveDestroyCallback (#89868)
# Motivation

Individual callers of `SBDebugger::SetDestroyCallback()` might think
that they have registered their callback and expect it to be called when
the debugger is destroyed. In reality, only the last caller survives,
and all previous callers are forgotten, which might be a surprise to
them. Worse, if this is called in a race condition, which callback
survives is less predictable, which may case confusing behavior
elsewhere.

# This PR

Allows multiple destroy callbacks to be registered and all called when
the debugger is destroyed.

**EDIT**: Adds two new APIs: `AddDestroyCallback()` and
`ClearDestroyCallback()`. `SetDestroyCallback()` will first clear then
add the given callback. Tests are added for the new APIs.

## Tests

```
bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
```

## (out-dated, see comments below) Semantic change to
`SetDestroyCallback()`

~~Currently, the method overwrites the old callback with the new one.
With this PR, it will NOT overwrite. Instead, it will hold on to both.
Both callbacks get called during destroy.~~

~~**Risk**: Although the documentation of `SetDestroyCallback()` (see
[C++](https://lldb.llvm.org/cpp_reference/classlldb_1_1SBDebugger.html#afa1649d9453a376b5c95888b5a0cb4ec)
and
[python](https://lldb.llvm.org/python_api/lldb.SBDebugger.html#lldb.SBDebugger.SetDestroyCallback))
doesn't really specify the behavior, there is a risk: if existing call
sites rely on the "overwrite" behavior, they will be surprised because
now the old callback will get called. But as the above said, the current
behavior of "overwrite" itself might be unintended, so I don't
anticipate users to rely on this behavior. In short, this risk might be
less of a problem if we correct it sooner rather than later (which is
what this PR is trying to do).~~

## (out-dated, see comments below) Implementation

~~The implementation holds a `std::vector<std::pair<callback, baton>>`.
When `SetDestroyCallback()` is called, callbacks and batons are appended
to the `std::vector`. When destroy event happen, the `(callback, baton)`
pairs are invoked FIFO. Finally, the `std::vector` is cleared.~~

# (out-dated, see comments below) Alternatives considered

~~Instead of changing `SetDestroyCallback()`, a new method
`AddDestroyCallback()` can be added, which use the same
`std::vector<std::pair<>>` implementation. Together with
`ClearDestroyCallback()` (see below), they will replace and deprecate
`SetDestroyCallback()`. Meanwhile, in order to be backward compatible,
`SetDestroyCallback()` need to be updated to clear the `std::vector` and
then add the new callback. Pros: The end state is semantically more
correct. Cons: More steps to take; potentially maintaining an
"incorrect" behavior (of "overwrite").~~

~~A new method `ClearDestroyCallback()` can be added. Might be
unnecessary at this point, because workflows which need to set then
clear callbacks may exist but shouldn't be too common at least for now.
Such method can be added later when needed.~~

~~The `std::vector` may bring slight performance drawback if its
implementation doesn't handle small size efficiently. However, even if
that's the case, this path should be very cold (only used during init
and destroy). Such performance drawback should be negligible.~~

~~A different implementation was also considered. Instead of using
`std::vector`, the current `m_destroy_callback` field can be kept
unchanged. When `SetDestroyCallback()` is called, a lambda function can
be stored into `m_destroy_callback`. This lambda function will first
call the old callback, then the new one. This way, `std::vector` is
avoided. However, this implementation is more complex, thus less
readable, with not much perf to gain.~~

---------

Co-authored-by: Roy Shi <royshi@meta.com>
2024-05-20 15:51:42 -07:00
royitaqi
e8dc8d614a
Add new Python API SBCommandInterpreter::GetTranscript() (#90703)
# Motivation

Currently, the user can already get the "transcript" (for "what is the
transcript", see `CommandInterpreter::SaveTranscript`). However, the
only way to obtain the transcript data as a user is to first destroy the
debugger, then read the save directory. Note that destroy-callbacks
cannot be used, because 1\ transcript data is private to the command
interpreter (see `CommandInterpreter.h`), and 2\ the writing of the
transcript is *after* the invocation of destory-callbacks (see
`Debugger::Destroy`).

So basically, there is no way to obtain the transcript:
* during the lifetime of a debugger (including the destroy-callbacks,
which often performs logging tasks, where the transcript can be useful)
* without relying on external storage

In theory, there are other ways for user to obtain transcript data
during a debugger's life cycle:
* Use Python API and intercept commands and results.
* Use CLI and record console input/output.

However, such ways rely on the client's setup and are not supported
natively by LLDB.


# Proposal

Add a new Python API `SBCommandInterpreter::GetTranscript()`.

Goals:
* It can be called at any time during the debugger's life cycle,
including in destroy-callbacks.
* It returns data in-memory.

Structured data:
* To make data processing easier, the return type is `SBStructuredData`.
See comments in code for how the data is organized.
* In the future, `SaveTranscript` can be updated to write different
formats using such data (e.g. JSON). This is probably accompanied by a
new setting (e.g. `interpreter.save-session-format`).

# Alternatives

The return type can also be `std::vector<std::pair<std::string,
SBCommandReturnObject>>`. This will make implementation easier, without
having to translate it to `SBStructuredData`. On the other hand,
`SBStructuredData` can convert to JSON easily, so it's more convenient
for user to process.

# Privacy

Both user commands and output/error in the transcript can contain
privacy data. However, as mentioned, the transcript is already available
to the user. The addition of the new API doesn't increase the level of
risk. In fact, it _lowers_ the risk of privacy data being leaked later
on, by avoiding writing such data to external storage.

Once the user (or their code) gets the transcript, it will be their
responsibility to make sure that any required privacy policies are
guaranteed.

# Tests

```
bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py
```

```
bin/llvm-lit -sv ../external/llvm-project/lldb/test/API/commands/session/save/TestSessionSave.py
```

---------

Co-authored-by: Roy Shi <royshi@meta.com>
Co-authored-by: Med Ismail Bennani <ismail@bennani.ma>
2024-05-20 15:49:46 -07:00
Pavel Labath
5bde2aa108
[lldb] Improve type name parsing (#91586)
Parsing of '::' scopes in TypeQuery was very naive and failed for names
with '::''s in template arguments. Interestingly, one of the functions
it was calling (Type::GetTypeScopeAndBasename) was already doing the
same thing, and getting it (mostly (*)) right. This refactors the
function so that it can return the scope results, fixing the parsing of
names like std::vector<int, std::allocator<int>>::iterator.

Two callers of GetTypeScopeAndBasename are deleted as the functions are
not used (I presume they stopped being used once we started pruning type
search results more eagerly).

(*) This implementation is still not correct when one takes c++
operators into account -- e.g., something like `X<&A::operator<>::T` is
a legitimate type name. We do have an implementation that is able to
handle names like these (CPlusPlusLanguage::MethodName), but using it is
not trivial, because it is hidden in a language plugin and specific to
method name parsing.

---------

Co-authored-by: Michael Buch <michaelbuch12@gmail.com>
2024-05-10 08:34:42 +02:00