Commit Graph

57 Commits

Author SHA1 Message Date
Ebuka Ezike
5c552c5cff [lldb] Fix GetExpressionPath for vector registers (#169210)
Vector registers have synthetic values for display purposes. This causes
SBValue::GetExpressionPath to dispatch
to ValueObjectSynthetic instead of ValueObjectRegister, producing
incorrect results.

Fixes #147144
2025-12-02 17:10:08 +00:00
cmtice
728cada359 [LLDB] Add type casting to DIL, part 1 of 3. (#165199)
This is an alternative to
https://github.com/llvm/llvm-project/pull/159500, breaking that PR down
into three separate PRs, to make it easier to review.

This first PR of the three adds the basic framework for doing type
casing to the DIL code, but it does not actually do any casting: In this
PR the DIL parser only recognizes builtin type names, and the DIL
interpreter does not do anything except return the original operand (no
casting). The second and third PRs will add most of the type parsing,
and do the actual type casting, respectively.
2025-12-01 20:08:19 -08:00
Ilia Kuklin
d5927a6172 [LLDB] Add unary plus and minus to DIL (#155617)
This patch adds unary nodes plus and minus, introduces unary type
conversions, and adds integral promotion to the type system.
2025-11-24 19:08:53 +05:00
Charles Zablit
0c7d826129 [NFC][lldb] move DiagnosticsRendering to Host (#168696)
NFC patch which moves `DiagnosticsRendering` from `Utility` to `Host`.

This refactoring is needed for
https://github.com/llvm/llvm-project/pull/168603. It adds a method to
check whether the current terminal supports Unicode or not. This will be
OS dependent and a better fit for `Host`. Since `Utility` cannot depend
on `Host`, `DiagnosticsRendering` must live in `Host` instead.
2025-11-19 18:52:59 +01:00
Alex Langford
3a08e423f1 Re-land [lldb][NFC] Mark ValueObject library with NO_PLUGIN_DEPENDENCIES (#167933)
This is a fixed version of #167886.

The build previously failed with `BUILD_SHARED_LIBS=ON`. After trying
that locally, I uncovered a few other instances of lldb non-plugin
libraries depending on clang transitively through lldbValueObject, so I
added the correct clang libraries to their dependencies.
2025-11-14 11:17:04 -08:00
Krzysztof Parzyszek
7129d76fe5 Revert "[lldb][NFC] Mark ValueObject library with NO_PLUGIN_DEPENDENCIES" (#167886)
Reverts llvm/llvm-project#167794

This breaks a build with BUILD_SHARED_LIBS=ON:

/usr/bin/ld: lib/liblldbCommands.a(CommandObjectTarget.cpp.o): undefined
reference to symbol '_ZN5clang22PCHContainerOperationsC1Ev

Fixing that issue leads to similar failures due to different symbols.
2025-11-13 09:06:13 -06:00
Alex Langford
45d5e7baba [lldb][NFC] Mark ValueObject library with NO_PLUGIN_DEPENDENCIES (#167794)
The ValueObject library doesn't actually depend on any plugins
currently, but it links against the C++ and ObjC language plugins. I
removed those and added NO_PLUGIN_DEPENDENCIES.

However, the build failed initally because the Commands library depends
on clangFrontend and it was previously getting it transitively through
ValueObject -> C++/ObjC Language -> clangFrontend. This makes the
dependency more explicit.
2025-11-12 16:19:31 -08:00
Michael Buch
a6eac9e729 [lldb][TypeSystem] Remove count parameter from TypeSystem::GetEncoding (#165702)
There were a couple of quirks with this parameter:
1. It wasn't being set consistently. E.g., vector types would be of
count `1` but complex types would be `2`. Hence, it wasn't clear what
count was referring to.
2. `count` was not being set if the input type was invalid, possibly
leaving the input reference uninitialized.
3. Only one callsite actually made use of `count`, and that in itself
seems like it could be improved (added a FIXME).

If we ever need a "how many elements does this type represent", we can
implement one with a new `TypeSystem` API that does exactly that.
2025-10-31 09:08:12 +00:00
cmtice
9855d546a4 [LLDB] Add boolean literals to DIL. (#157992)
This adds the ability to recognize (and create ValueObjects for) boolean
literals ("true", "false") to DIL. This is a preliminary step to adding
type casting (and also for the ternary op).
2025-09-16 16:04:42 -07:00
Ilia Kuklin
bae177241c Reapply "[LLDB] Add ScalarLiteralNode and literal parsing in DIL" (#155610)
This patch introduces `ScalarLiteralNode` without any uses by other
nodes yet. It also includes lexing and parsing for integer and floating
point numbers.
Reapplies #152308 with a fix.
2025-08-27 17:49:55 +05:00
Ilia Kuklin
241d1601b4 Revert "[LLDB] Add ScalarLiteralNode and literal parsing in DIL" (#155605)
Reverts llvm/llvm-project#152308
2025-08-27 17:14:44 +05:00
Ilia Kuklin
51230d9e1e [LLDB] Add ScalarLiteralNode and literal parsing in DIL (#152308)
This patch introduces `ScalarLiteralNode` without any uses by other
nodes yet. It also includes lexing and parsing for integer and floating
point numbers.
2025-08-27 16:28:11 +05:00
cmtice
d85069c3d0 [LLDB] Re-land 'Update DIL handling of array subscripting' (#154269)
This attempts to fix the issues with the original PR (#151605), updating
the DIL code for handling array subscripting to more closely match and
handle all the casees from the original 'frame var' implementation. The
first PR did not include special-case code for objc pointers, which
apparently caused a test failure on the green-dragon buildbot. Hopefully
this PR, which includes the objc pointer special code, fixes that issue.
2025-08-26 07:40:35 -07:00
Shubham Sandeep Rastogi
cd0bf2735b Revert "[LLDB] Update DIL handling of array subscripting. (#151605)"
This reverts commit 6d3ad9d9fd.

This was reverted because it broke the LLDB greendragon bot.
2025-08-15 09:17:33 -07:00
cmtice
6d3ad9d9fd [LLDB] Update DIL handling of array subscripting. (#151605)
This updates the DIL code for handling array subscripting to more
closely match and handle all the cases from the original 'frame var'
implementation. Also updates the DIL array subscripting test. This
particularly fixes some issues with handling synthetic children, objc
pointers, and accessing specific bits within scalar data types.
2025-08-15 08:26:45 -07:00
Ilia Kuklin
dace67e941 [lldb] Add ValueObject::CreateValueObjectFromScalar and fix Scalar::GetData (#151350)
Add `ValueObject::CreateValueObjectFromScalar` function and adjust
`Scalar::GetData` to be able to both extend and truncate the data bytes
in Scalar to the specified size.
2025-08-06 14:32:19 +05:00
beetrees
e15b3ef704 [lldb] Add support for displaying __float128 variables (#98369) 2025-07-31 18:04:48 -07:00
Michael Buch
b7889a65a8 [lldb][SBType] GetBasicType to unwrap canonical type (#149112)
`SBType::GetBasicType` fails on typedefs to primitive types. The docs
for `GetBasicType` state:
```
Returns the BasicType value that is most appropriate to this type
```
But, e.g., for `uint64_t` this would currently return
`eBasicTypeInvalid`.

`TypeSystemClang::GetBasicTypeEnumeration` (which is what
`SBType::GetBasicType` uses) doesn't see through typedefs. Inside LLDB
we almost always call `GetBasicTypeEnumeration` on the canonical type.
In the cases we don't I suspect those were just subtle bugs. This patch
gets the canonical type inside of `GetBasicTypeEnumeration` instead.

rdar://155829208
2025-07-23 08:52:49 +01:00
cmtice
f5c676d6d9 [LLDB] Switch to using DIL as default implementation for 'frame var'. (#147887) 2025-07-15 08:19:10 -07:00
Ilia Kuklin
09fb20ec7d [LLDB] Check comp_unit before accessing it in DIL (#147955)
Check `symbol_context.comp_unit` before accessing it to avoid `nullptr`
dereferencing.
2025-07-10 20:34:23 +05:00
Dave Lee
4fed7c22fb [lldb] Rename files ValueObjectSyntheticFilter to ValueObjectSynthetic (NFC) (#146784)
Change the name of `ValueObjectSyntheticFilter.{h,cpp}` to match the main type they
declare and define: `ValueObjectSynthetic`.
2025-07-07 10:14:05 -07:00
Ilia Kuklin
03aa5c0a9e [LLDB] Optimize identifier lookup in DIL (#146094)
Remove unused code and unnecessary function calls, optimize global
variable search.
Add more test cases.
2025-07-03 19:15:16 +05:00
cmtice
11ecd4742b [LLDB] Update DIL to pass current 'frame var' tests. (#145055)
As a preliminary to making DIL the default implementation for
 'frame var', ran check-lldb forcing 'frame var' to always use DIL, 
and discovered a few failing tests. This fixes most of them. The only
remaining failing test is TestDAP_evaluate.py, which now passes
a test case that the test says should fail (still investigating this).

Changes in this PR:
- Sets correct VariableSP, as well as returning ValueObjectSP (needed
for several watchpoint tests).
- Updates error messages, when looking up members, to match what the
rest of LLDB expects. Also update appropriate DIL tests to expect the
updated error messages.
- Updates DIL parser to look for and accept "(anonymous namespace)::" at
the front of a variable name.
2025-07-01 07:30:47 -07:00
cmtice
da2969b105 [LLDB] Update DIL to handle smart pointers; add more tests. (#143786)
This updates the DIL implementation to handle smart pointers (accessing
field members and dereferencing) in the same way the current 'frame
variable' implementation does. It also adds tests for handling smart
pointers, as well as some additional DIL tests.
2025-06-27 07:30:14 -07:00
Ilia Kuklin
83381ba832 [LLDB] Add negative number parsing to DIL (#144557) 2025-06-19 18:10:56 +05:00
Ilia Kuklin
4236423ee8 [LLDB] Add bit extraction to DIL (#141422) 2025-06-13 16:31:25 +05:00
Pavel Labath
7e471c1fd0 [lldb/cmake] Use ADDITIONAL_HEADER(_DIR)?S (#142587)
Replace (questionable) header globs with an explicit argument supported
by llvm_add_library.
2025-06-10 11:58:39 +02:00
Pavel Labath
2c4f67794b [lldb/cmake] Implicitly pass arguments to llvm_add_library (#142583)
If we're not touching them, we don't need to do anything special to pass
them along -- with one important caveat: due to how cmake arguments
work, the implicitly passed arguments need to be specified before
arguments that we handle.

This isn't particularly nice, but the alternative is enumerating all
arguments that can be used by llvm_add_library and the macros it calls
(it also relies on implicit passing of some arguments to
llvm_process_sources).
2025-06-04 11:33:37 +02:00
Pavel Labath
e9fad0e91c [lldb] Refactor away UB in SBValue::GetLoadAddress (#141799)
The problem was in calling GetLoadAddress on a value in the error state,
where `ValueObject::GetLoadAddress` could end up accessing the
uninitialized "address type" by-ref return value from `GetAddressOf`.
This probably happened because each function expected the other to
initialize it.

We can guarantee initialization by turning this into a proper return
value.

I've added a test, but it only (reliably) crashes if lldb is built with
ubsan.
2025-06-02 09:39:56 +02:00
Akash Agrawal
e4ed71818e [LLDB] [NFC] - Remove duplicate #include headers from the files of lldb dir & few other files (#141478)
A few files of lldb dir & few other files had duplicate headers
included. This patch removes those redundancies.

---------

Co-authored-by: Akash Agrawal <akashag@qti.qualcomm.com>
2025-05-29 23:13:30 -07:00
Ilia Kuklin
fe51d8ae57 [LLDB] Add array subscription and integer parsing to DIL (#141102)
Reapply #138551 with an xfailed test on Windows
2025-05-25 21:09:33 +05:00
cmtice
53d7b1d9e0 [LLDB] Add field member operators to DIL (#138093)
Add the arrow and period operators, allowing DIL to find and access
member fields.
2025-05-23 07:30:10 -07:00
Ilia Kuklin
5df819ffb3 Revert "[LLDB] Add array subscription and integer parsing to DIL" (#141059)
Reverts llvm/llvm-project#138551
2025-05-22 17:33:01 +05:00
Ilia Kuklin
491619a250 [LLDB] Add array subscription and integer parsing to DIL (#138551) 2025-05-22 16:15:11 +05:00
Igor Kudrin
3f196e0293 [lldb][core] Fix getting summary of a variable pointing to r/o memory (#139196)
Motivation example:

```
> lldb -c altmain2.core
...
(lldb) var F
(const char *) F = 0x0804a000 ""
```

The variable `F` points to a read-only memory page not dumped to the
core file, so `Process::ReadMemory()` cannot read the data. The patch
switches to `Target::ReadMemory()`, which can read data both from the
process memory and the application binary.
2025-05-20 13:50:24 -07:00
Ilia Kuklin
c8a0513a1a [lldb] Restore ObjC incomplete type dereferencing fix (#139567)
Attempt an ObjC incomplete type fix even if `GetDereferencedType`
returns an error.
2025-05-12 22:59:40 +05:00
Ilia Kuklin
3aacd74594 [lldb][TypeSystemClang] Allow arrays to be dereferenced in C/C++. (#135843)
Add a function `GetDereferencedType` to `CompilerType` and allow
`TypeSystemClang` to dereference arrays.
2025-05-12 16:46:58 +05:00
Ilia Kuklin
0eff4108cb [LLDB] Fix ValueObject::AddressOf() return value (#137688)
`ValueObject::AddressOf()` used to return address as a value which has
it's own address, allowing to do `value.AddressOf().AddressOf()`.
This patch makes the return address a simple const value.
2025-05-05 20:53:04 +05:00
Charles Zablit
b3d130279f [lldb] Upgrade GetIndexOfChildWithName to use llvm::Expected (#136693)
This patch replaces the use of `UINT32_MAX` as the error return value of
`GetIndexOfChildWithName` with `llvm::Expected`.


# Tasks to do in another PR

1. Replace `CalculateNumChildrenIgnoringErrors` with
`CalculateNumChildren`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358).
2. Update `lldb_private::formatters::ExtractIndexFromString` to use
`llvm::Expected`. See [this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536).
3. Create a new class which carries both user and internal errors. See
[this
comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
2025-04-30 11:44:19 +01:00
Ilia Kuklin
d637038429 [LLDB] Add unary operators Dereference and AddressOf to DIL (#134428) 2025-04-29 21:29:52 +05:00
Pavel Labath
15cd71afd2 [lldb] Make ValueObject::Dereference less aggressive (#137311)
The function was always trying to dereference both the synthetic and
non-synthetic view of the object. This is wrong as the caller should be
able to determine which view of the object it wants to access, as is
done e.g. for child member access.

This patch removes the nonsynthetic->synthetic fallback, which is the
more surprising path, and fixes the callers to try both versions of the
object (when appropriate). I also snuck in simplification of the member
access code path because it was possible to use the same helper function
for that, and I wanted to be sure I understand the logic correctly.

I've left the synthetic->nonsynthetic fallback in place. I think we may
want to keep that one as we often have synthetic child providers for
pointer types. They usually don't provide an explicit dereference
operation but I think users would expect that a dereference operation on
those objects would work. What we may want to do is to try the
*synthetic* operation first in this case, so that the nonsynthetic case
is really a fallback.

---------

Co-authored-by: Ilia Kuklin <kuklin.iy@mail.ru>
2025-04-29 08:27:18 +02:00
Michael Buch
419fa1b06a [lldb][DataFormatter] Surface CalculateNumChildren errors in std::vector summary (#135944)
When the data-formatters happen to break (e.g., due to layout changes in
libc++), there's no clear indicator of them failing from a user's
perspective. E.g., for `std::vector`s we would just show:
```
(std::vector<int>) v = size=0 {}
```
which is highly misleading, especially if `v.size()` returns a non-zero
size.

This patch surfaces the various errors that could occur when calculating
the number of children of a vector.

rdar://146964266
2025-04-16 17:57:51 +02:00
cmtice
c4c0ff6865 [LLDB] Fix warnings in DIL. (#134778)
This fixes 3 warnings from compiling the DILParser:

DILParser.h:53:12: warning: returning address of local temporary object
[-Wreturn-stack-address]

DILParser.h:119:8: warning: private field 'm_fragile_ivar' is not used
[-Wunused-private-field]

DILParser.h:120:8: warning: private field 'm_check_ptr_vs_member' is not
used [-Wunused-private-field]
2025-04-08 11:37:54 -07:00
cmtice
46e2c07fa2 [LLDB] Add DIL code for handling plain variable names. (#120971)
Add the Data Inspection Language (DIL) implementation pieces for
handling plain local and global variable names.

See https://discourse.llvm.org/t/rfc-data-inspection-language/69893 for
information about DIL.

This change includes the basic AST, Lexer, Parser and Evaluator pieces,
as well as some tests.
2025-04-03 21:39:30 -07:00
Dave Lee
8705e489dc [lldb] Remove use of comma operator (NFC) (#131233)
No reason for the comma operator, make this more conventional with two statements.
2025-03-16 08:41:55 -07:00
Adrian Prantl
2317a72489 [lldb] Add missing converstion to optional 2025-03-09 12:04:22 -07:00
Adrian Prantl
878a64f94a [lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)
This patch pushes the error handling boundary for the GetBitSize()
methods from Runtime into the Type and CompilerType APIs. This makes it
easier to diagnose problems thanks to more meaningful error messages
being available. GetBitSize() is often the first thing LLDB asks about a
type, so this method is particularly important for a better user
experience.

rdar://145667239
2025-03-05 10:21:19 -08:00
foxtran
506deb0cce [lldb] Fix GCC's -Wreturn-type warnings (#127974)
This patch fixes `-Wreturn-type` warnings which happens if LLVM is built
with GCC compiler (14.1 is used for detecting)

Warnings:
```
llvm-project/lldb/source/ValueObject/DILLexer.cpp: In static member function ‘static llvm::StringRef lldb_private::dil::Token::GetTokenName(Kind)’:
llvm-project/lldb/source/ValueObject/DILLexer.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
```
and:
```
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp: In member function ‘virtual std::string lldb_private::TypeSummaryImpl::GetSummaryKindName()’:
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
```

Technically, it is a bug in Clang (see #115345), however, UBSan with
Clang should detect these places, therefore it would be nice to provide
a return statement for all possible inputs (even invalid).
2025-02-21 11:02:19 -06:00
Jonas Devlieghere
f62f13d5db [lldb] Store the return SBValueList in the CommandReturnObject (#127566)
There are a lot of lldb commands whose result is really one or more
ValueObjects that we then print with the ValueObjectPrinter. Now that we
have the ability to access the SBCommandReturnObject through a callback
(#125006), we can store the resultant ValueObjects in the return object,
allowing an IDE to access the SBValues and do its own rich formatting.

rdar://143965453
2025-02-19 15:17:35 -08:00
Augusto Noronha
9d5edc9a0d [lldb][NFC] Replace GetLocalBufferSize() with GetLocalBuffer() (#126333) 2025-02-07 19:12:35 -08:00