Commit Graph

186 Commits

Author SHA1 Message Date
Jonas Devlieghere
a69f78b080 [lldb] Add syntax color highlighting for disassembly
Add support for syntax color highlighting disassembly in LLDB. This
patch relies on 77d1032516, which introduces support for syntax
highlighting in MC.

Currently only AArch64 and X86 have color support, but other interested
backends can adopt WithColor in their respective MCInstPrinter.

Differential revision: https://reviews.llvm.org/D159164
2023-09-01 14:47:45 -07:00
Jim Ingham
d268ba3808 Test follow-up to 2e7aa2ee34
The TestEvents.py test I added for ShadowListeners fails on Windows.
Since there's no reason to believe the ShadowListeners feature has
different behavior from the other event-based tests here, I copied
the skips & expected_flakey's from the other tests in that file to
this one.
2023-08-16 12:19:07 -07:00
Jim Ingham
2e7aa2ee34 Replace the singleton "ShadowListener" with a primary and N secondary Listeners
Before the addition of the process "Shadow Listener" you could only have one
Listener observing the Process Broadcaster.  That was necessary because fetching the
Process event is what switches the public process state, and for the execution
control logic to be manageable you needed to keep other listeners from causing
this to happen before the main process control engine was ready.

Ismail added the notion of a "ShadowListener" - which allowed you ONE
extra process listener.  This patch inverts that setup by designating the
first listener as primary - and giving it priority in fetching events.

Differential Revision: https://reviews.llvm.org/D157556
2023-08-16 10:35:32 -07:00
Jason Molenda
ebf249066a [lldb] SBTarget::AddModule do all searches by UUID, set Target arch
Make SBTarget::AddModule possibly call out to an external program to
find the binary by UUID if it can't be found more easily, the same
way `target modules add -u ...` works from the commandline.

If the Target does not have an architecture set yet, use the
Module's Arch to initialize it.  Allows an API writer to create
a target with no arch, and inherit it from the first binary they
load with AddModules.

Differential Revision: https://reviews.llvm.org/D157659
rdar://113657555
2023-08-11 14:20:38 -07:00
Jonas Devlieghere
ecbe78c124 [lldb] Fix Python test formatting (NFC)
All Python files in the LLVM repository were reformatted with Black [1].
Files inside the LLDB subproject were reformatted in 2238dcc393. This
patch updates a handful of tests that were added or modified since then
and weren't formatted with Black.

[1] https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257
2023-08-04 14:36:13 -07:00
Jonas Devlieghere
e0053bc04e [lldb] Bump SWIG minimum version to 4
SWIG 4 was released in 2019 and has been the de-facto standard for a
while now. All bots are running SWIG 4.0 or later.

This was motivated by #64279 which discovered that 662548c broke the
LLDB build with SWIG 3 on Windows.

Differential revision: https://reviews.llvm.org/D156804
2023-08-04 14:34:01 -07:00
Med Ismail Bennani
57bd882343 [lldb] Convert script native types to StructuredData counterpart
This patch adds the ability to pass native types from the script
interpreter to methods that use a {SB,}StructuredData argument.

To do so, this patch changes the `ScriptedObject` struture that holds
the pointer to the script object as well as the originating script
interpreter language. It also exposes that to the SB API via a new class
called `SBScriptObject`.

This structure allows the debugger to parse the script object and
convert it to a StructuredData object. If the type is not compatible
with the StructuredData types, we will store its pointer in a
`StructuredData::Generic` object.

This patch also adds some SWIG typemaps that checks the input argument to
ensure it's either an SBStructuredData object, in which case it just
passes it throught, or a python object that is NOT another SB type, to
provide some guardrails for the user.

rdar://111467140

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-07-21 18:47:46 -07:00
Kazuki Sakamoto
43b9d62018 [lldb][Windows] Fix TestLocateModuleCallback
D153735 added the tests but it is failing due to POSIX path vs Windows path.
https://lab.llvm.org/buildbot/#/builders/219/builds/4084

Fix it.
- MODULE_PLATFORM_PATH is POSIX path.
- Normalize self.input_dir, FileSpec and SymbolFileSpec fullpath.

Differential Revision: https://reviews.llvm.org/D155124
2023-07-14 10:36:57 -07:00
Kazuki Sakamoto
f03dbdb70a [lldb][LocateModuleCallback] Implement API, Python interface
RFC https://discourse.llvm.org/t/rfc-python-callback-for-target-get-module/71580

Use SWIG for the locate module callback the same as other Python callbacks.
TestLocateModuleCallback.py verifies the functionalities.

Differential Revision: https://reviews.llvm.org/D153735
2023-07-12 11:33:51 -07:00
Kazuki Sakamoto
c4fa6fafc4 [lldb][LocateModuleCallback] Update SBFileSpec/SBModuleSpec
RFC https://discourse.llvm.org/t/rfc-python-callback-for-target-get-module/71580

SBFileSpec and SBModuleSpec will be used for locate module callback as Python
function arguments. This diff allows these things.
- Can be instantiated from SBPlatform.
- Can be passed to/from Python.
- Can be accessed for object offset and size.

Differential Revision: https://reviews.llvm.org/D153733
2023-07-12 11:11:18 -07:00
Jim Ingham
f05e2fb013 Don't allow SBValue::Cast to cast from a smaller type to a larger,
as we don't in general know where the extra data should come from.

Differential Revision: https://reviews.llvm.org/D153657
2023-06-26 16:02:01 -07:00
Jonas Devlieghere
ab855530f7 [lldb] Fix Python test formatting (NFC)
All Python files in the LLVM repository were reformatted with Black [1].
Files inside the LLDB subproject were reformatted in 2238dcc393. This
patch updates a handful of tests that were added or modified since then
and weren't formatted with Black.

[1] https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257
2023-06-16 14:51:14 -07:00
Jim Ingham
14186773e7 Fix SBValue::FindValue for file static variables
This was just a thinko. The API StackFrame::GetVariableList takes a
bool for "get_file_globals" which if true will also find file statics
and file globals. But we only were passing that as true if the
ValueType was eValueTypeVariableGlobal, which meant that we never find
file statics. It's okay if we cast too wide a net when we do
GetVariableList as later on we check against the ValueType to filter
globals from statics.

There was a test that had a whole bunch of globals and tested
FindValue on all of them, but had no statics. So I just made one of
the globals a file static, which verifies the fix.

Differential Revision: https://reviews.llvm.org/D151392
2023-05-30 17:12:35 -07:00
tcwg
ab05d9134d Revert "[LLDB] Add/Remove xfail for some API tests on Windows"
This reverts commit 6ea1a0d4fc.

It again marks XFAIL LLDB tests failing after
c384fcd3ea
2023-05-29 17:39:36 +04:00
Jonas Devlieghere
2238dcc393 [NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python
code. Reformatting is done with `black` (23.1.0).

If you end up having problems merging this commit because you have made
changes to a python file, the best way to handle that is to run `git
checkout --ours <yourfile>` and then reformat it with black.

RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Differential revision: https://reviews.llvm.org/D151460
2023-05-25 12:54:09 -07:00
Med Ismail Bennani
1370a1cb5b [lldb] Add support for negative integer to {SB,}StructuredData
This patch refactors the `StructuredData::Integer` class to make it
templated, makes it private and adds 2 public specialization for both
`int64_t` & `uint64_t` with a public type aliases, respectively
`SignedInteger` & `UnsignedInteger`.

It adds new getter for signed and unsigned interger values to the
`StructuredData::Object` base class and changes the implementation of
`StructuredData::Array::GetItemAtIndexAsInteger` and
`StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed
and unsigned integers.

This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the
`SBStructuredData` class and marks `GetIntegerValue` as deprecated.

Finally, this patch audits all the caller of `StructuredData::Integer`
or `StructuredData::GetIntegerValue` to use the proper type as well the
various tests that uses `SBStructuredData.GetIntegerValue`.

rdar://105575764

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-05-22 16:14:00 -07:00
Jason Molenda
2e16e41b28 Add AArch64 MASK watchpoint support in debugserver
Add suport for MASK style watchpoints on AArch64 in debugserver
on Darwin systems, for watching power-of-2 sized memory ranges.
More work needed in lldb before this can be exposed to the user
(because they will often try watching memory ranges that are not
exactly power-of-2 in size/alignment) but this is the first part
of adding that capability.

Differential Revision: https://reviews.llvm.org/D149792
rdar://108233371
2023-05-04 13:23:51 -07:00
Muhammad Omair Javaid
6ea1a0d4fc [LLDB] Add/Remove xfail for some API tests on Windows
This patch add or removes XFAIL decorator from various tests which were marked
xfail for windows.

since 44363f2 various tests have started passing but introduced a couple of new failures.
Weight is in favor of new XPasses and I have removed XFail decorator from them. Also
some new tests have started failing for which we need to file separate bugs. I have
marked them xfail for now and will add the bug id after investigating the issue.

Differential Revision: https://reviews.llvm.org/D149235
2023-05-03 04:45:55 +05:00
Jorge Gorbe Moya
984354fbbe [lldb] Update some uses of Python2 API in typemaps.
Python 3 doesn't have a distinction between PyInt and PyLong, it's all
PyLong now.

This also fixes a bug in SetNumberFromObject. This used to crash LLDB:
```
lldb -o "script data=lldb.SBData(); data.SetDataFromUInt64Array([2**63])"
```

The problem happened in the PyInt path:
```
  if (PyInt_Check(obj))
      number = static_cast<T>(PyInt_AsLong(obj));
```
when obj doesn't fit in a signed long, `PyInt_AsLong` would fail with
"OverflowError: Python int too large to convert to C long".

The existing long path does the right thing, as it will call
`PyLong_AsUnsignedLongLong` for uint64_t.

Differential Revision: https://reviews.llvm.org/D146590
2023-03-22 11:28:52 -07:00
Jim Ingham
fe61b38258 Add a Debugger interruption mechanism in conjunction with the
Command Interpreter mechanism.

Differential Revision: https://reviews.llvm.org/D145136
2023-03-15 16:45:14 -07:00
Jim Ingham
e1462d14b1 Don't produce a dynamic value if there was an error creating it.
We used to make a dynamic value that "pretended to be its parent"
but that's hard for some of the more complex ValueObject types, and
it's better in this case just to return no dynamic value.

Differential Revision: https://reviews.llvm.org/D145629
2023-03-10 10:21:50 -08:00
Jeffrey Tan
b461398f1c Add a new SBDebugger::SetDestroyCallback() API
Adding a new SBDebugger::SetDestroyCallback() API.
This API can be used by any client to query for statistics/metrics before
exiting debug sessions.

Differential Revision: https://reviews.llvm.org/D143520
2023-03-07 14:48:15 -08:00
Med Ismail Bennani
e6cac17b56 [lldb] Extend SWIG SBProcess interface with WriteMemoryAsCString method
This patch tries to address an interoperability issue when writing
python string into the process memory.

Since the python string is not null-terminated, it would still be
written to memory however, when trying to read it again with
`SBProcess::ReadCStringFromMemory`, the memory read would fail, since
the read string doens't contain a null-terminator, and therefore is not
a valid C string.

To address that, this patch extends the `SBProcess` SWIG interface to
expose a new `WriteMemoryAsCString` method that is only exposed to the
SWIG target language. That method checks that the buffer to write is
null-terminated and otherwise, it appends a null byte at the end of it.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-03-03 19:33:01 -08:00
Muhammad Omair Javaid
e85e5abdce [LLDB] XFAIL TestRunLocker.py for windows
TestRunLocker.py is failing on windows x64 and AArch64 buildbots.
Buildbot log suggests that test needs some minor modification for
windows which I will do later.

https://lab.llvm.org/buildbot/#/builders/83/builds/29680
https://lab.llvm.org/buildbot/#/builders/219/builds/942
2023-03-02 11:51:35 +04:00
Muhammad Omair Javaid
588da01621 Revert "[LLDB] XFAIL TestRunLocker.py on Windows"
This reverts commit 9d28e00e74.
2023-03-02 11:22:25 +04:00
Muhammad Omair Javaid
9d28e00e74 [LLDB] XFAIL TestRunLocker.py on Windows 2023-03-02 11:05:23 +04:00
Dan Liew
55a363fea1 [LLDB] Expose several methods in SBWatchpoint
This patch adds the following methods:

* `GetType()`
* `GetWatchValueKind()`
* `GetWatchSpec()`
* `IsWatchingReads()`
* `IsWatchingWrites()`

These mostly expose methods that `lldb_private::Watchpoint` already
had. Tests are included that exercise these new methods.

The motivation for exposing these are as follows:

* `GetType()` - With this information and the address from a watchpoint
  it is now possible to construct an SBValue from an SBWatchpoint.
  Previously this wasn't possible. The included test case illustrates
  doing this.
* `GetWatchValueKind()` - This allows the caller to determine whether the
  watchpoint is a variable watchpoint or an expression watchpoint. A new
  enum (`WatchpointValueKind`) has been introduced to represent the
  return values. Unfortunately the name `WatchpointKind` was already
  taken.
* `GetWatchSpec()` - This allows (at least for variable watchpoints)
  to use a sensible name for SBValues created from an SBWatchpoint.
* `IsWatchingReads()` - This allow checking if a watchpoint is
  monitoring read accesses.
* `IsWatchingWRites()` - This allow checking if a watchpoint is
  monitoring write accesses.

rdar://105606978

Reviewers: jingham, mib, bulbazord, jasonmolenda, JDevlieghere

Differential Revision: https://reviews.llvm.org/D144937
2023-03-01 11:15:05 -08:00
Jim Ingham
a92f7832f3 Fix the run locker setting for async launches that don't stop at the
initial stop.  The code was using PrivateResume when it should have
used Resume.

This was allowing expression evaluation while the target was running,
and though that was caught a litle later on, we should never have gotten
that far.  To make sure that this is caught immediately I made an error
SBValue when this happens, and test that we get this error.

Differential Revision: https://reviews.llvm.org/D144665
2023-02-28 17:34:49 -08:00
Alex Langford
2f88c07cf8 [lldb] StructuredData should not truncate uint64_t values
In json::Value, getAsInteger returns an optional<int64_t> and getAsNumber
returns an optional<double>. If a value is larger than what an int64_t
can hold but smaller than what a uint64_t can hold, the getAsInteger
function will fail but the getAsNumber will succeed. However, the value
shouldn't be interpreted as a double.

rdar://105556974

Differential Revision: https://reviews.llvm.org/D144238
2023-02-17 12:39:49 -08:00
Jason Molenda
49470f1eac Remove test case that tries to allocate impossible amounts
The sanitizer bots are failing with this test; they
impose a maximum 0x10000000000 size on allocations, and
malloc on darwin will let me malloc that much.  The
alternative to keep this would be to break it out into a
seperate test in TestProcessAIP and skip that if it's on
the sanitizer, but this is seeming too fragile IMO so I'm
punting it entirely.
2023-02-09 10:44:40 -08:00
Dave Lee
3ff636729d [lldb] Accept negative indexes in __getitem__
To the Python bindings, add support for Python-like negative indexes.

While was using `script`, I tried to access a thread's bottom frame with
`thread.frame[-1]`, but that failed. This change updates the `__getitem__`
implementations to support negative indexes as one would expect in Python.

Differential Revision: https://reviews.llvm.org/D143282
2023-02-08 10:46:26 -08:00
Jason Molenda
b1d8f40484 Only run the weird new try-to-read-too-much test on Darwin
I'm still getting linux CI bot failures for this test.  It's not
critical, and it depends on a failure mode that is true on Darwin
but I was always gambling that it might fail in the same way on
other systems.
2023-02-07 16:05:24 -08:00
Jason Molenda
4a8cc285e9 Fix TestProcessAPI.py to only allocate sys.maxsize buffer
I hardcoded nearly a UINT64_MAX number in this test case,
and python is not able to convert it to a long on some
platforms.  Use sys.maxsize instead; this also would have
failed if the testsuite was run on a 32-bit system.
2023-02-07 16:05:24 -08:00
Jason Molenda
62c747517c Check if null buffer handed to SBProcess::ReadMemory
Add a check for a null destination buffer in SBProcess::ReadMemory,
and return an error if that happens.  If a Python SB API script
tries to allocate a huge amount of memory, the malloc done by the
intermediate layers will fail and will hand a null pointer to
ReadMemory.  lldb will eventually crash trying to write in to that
buffer.

Also add a test that tries to allocate an impossibly large amount
of memory, and hopefully should result in a failed malloc and hitting
this error codepath.

Differential Revision: https://reviews.llvm.org/D143012
rdar://104846609
2023-02-07 14:16:04 -08:00
Med Ismail Bennani
c192803304 [lldb] Add a way to get a scripted process implementation from the SBAPI
This patch introduces a new `GetScriptedImplementation` method to the
SBProcess class in the SBAPI. It will allow users of Scripted Processes to
fetch the scripted implementation object from to script interpreter to be
able to interact with it directly (without having to go through lldb).

This allows to user to perform action that are not specified in the
scripted process interface, like calling un-specified methods, but also
to enrich the implementation, by passing it complex objects.

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

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2023-02-03 12:29:01 -08:00
Muhammad Omair Javaid
bde5d31e96 Revert "Revert "[lldb] Make SBSection::GetSectionData call Section::GetSectionData.""
This reverts commit e1bbe50f5a.

Differential Revision: https://reviews.llvm.org/D142672
2023-01-30 16:49:15 +05:00
Muhammad Omair Javaid
e1bbe50f5a Revert "[lldb] Make SBSection::GetSectionData call Section::GetSectionData."
This reverts commit 805600c7d5.

LLDB windows buildbots were broken by the TestSectionAPI.py test. I dont
have full context of the commit to fix it. Reverting it temporarily.

https://lab.llvm.org/buildbot/#/builders/83/builds/28617
https://lab.llvm.org/buildbot/#/builders/219/builds/180

Differential Revision: https://reviews.llvm.org/D142672
2023-01-30 12:34:37 +05:00
Jorge Gorbe Moya
805600c7d5 [lldb] Make SBSection::GetSectionData call Section::GetSectionData.
`SBSection::GetSectionData` and `Section::GetSectionData` are
implemented differently, and the `SBSection` method doesn't handle
compressed sections correctly.

Differential Revision: https://reviews.llvm.org/D142672
2023-01-27 10:15:35 -08:00
Jordan Rupprecht
d5c0b1f73b [test] Remove unused unittest2 import 2023-01-26 18:02:16 -08:00
Dave Lee
4076664228 [lldb][test] Replace use of p with expression (NFC)
In API tests, replace use of the `p` alias with the `expression` command.

To avoid conflating tests of the alias with tests of the expression command,
this patch canonicalizes to the use `expression`.

Differential Revision: https://reviews.llvm.org/D141539
2023-01-25 11:03:58 -08:00
Pavel Kosov
4ae221f5a4 [NFC][LLDB] Rename test file
Commit 92f0e4cca introduced test file with name TestChangeValue.py,
which leads to test failure because there already is a test files with the same name
In this commit a newly added file is renamed to fix this failure
2023-01-25 12:03:11 +03:00
Pavel Kosov
92f0e4ccaf [LLDB] Fixes summary formatter for libc++ map allowing modification of contained value
Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D140624
2023-01-25 10:48:04 +03:00
Pavel Kosov
ff9c31b23b [LLDB] Fix for libc++ atomic allowing modification of contained value
Reviewed By: clayborg

Differential Revision: https://reviews.llvm.org/D140623
2023-01-25 10:39:50 +03:00
Jordan Rupprecht
82a46cd247 [test] Remove named function arguments from TestSBEnvironment
This is not available in all versions of swig 3.
2022-11-21 10:05:41 -08:00
Raphael Isemann
a8bec61179 [lldb] Fix that empty target.run-args are not actually used when launching process
`GetPropertyAtIndexAsArgs` returns true on success and false on failure. Right
now it returns the converted `size_t` returned from `GetArgs` which describes
the number of arguments in the argument list. So for empty argument lists
(`(size_t)0` -> `(bool)false`) this function always fails.

The only observable effect of this seems to be that empty arguments are never
propagated to the internal LaunchInfo for a process. This causes that once any
argument has been added to `target.run-args`, clearing `target.run-args` doesn't
have any effect.

Fixes issue #55568

Reviewed By: JDevlieghere, jingham

Differential Revision: https://reviews.llvm.org/D126057
2022-11-18 16:48:56 +01:00
Dave Lee
01f924d0e3 [lldb] Revert SBFileSpec.fullpath path separator fix
Primarily reverts 5223366416.
2022-11-12 14:17:28 -08:00
Dave Lee
1fb5c7a2f1 [lldb] Rewrite to assertEqual/assertNotEqual (NFC)
Using the more specific assert* methods results in more useful error message.
2022-11-11 17:03:02 -08:00
Dave Lee
5223366416 [lldb] Fix SBFileSpec.fullpath for Windows
Fix `fullpath` to not assume a `/` path separator. This was discovered when
D133130 failed on Windows. Use `os.path.join()` to fix the issue.

Reviewed By: mib

Differential Revision: https://reviews.llvm.org/D133366
2022-11-11 16:07:38 -08:00
Dave Lee
995d556f42 [lldb][test] Remove empty setUp/tearDown methods (NFC) 2022-10-27 08:41:00 -07:00
Jonas Devlieghere
8c7a1f8761 Revert "[lldb] Fix member access in GetExpressionPath"
This reverts commit 0205aa4a02 because it
breaks TestArray.py:

  a->c = <parent failed to evaluate: parent is NULL>

I decided to revert instead of disable the test because it looks like a
legitimate issue with the patch.
2022-10-20 15:21:59 -07:00