Commit Graph

17212 Commits

Author SHA1 Message Date
Pete Lawrence
92d8a28cc6 [lldb] Part 2 of 2 - Refactor CommandObject::DoExecute(...) return void (not bool) (#69991)
[lldb] Part 2 of 2 - Refactor `CommandObject::DoExecute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 1 refactors the `CommandObject::Execute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69989](https://github.com/llvm/llvm-project/pull/69989)

rdar://117378957
2023-10-30 13:21:00 -07:00
Adrian Prantl
c42b640208 Fix the DEVELOPER_DIR computation (#70528)
The code was incorrectly going into the wrong direction by removing one
component instead of appendeing /Developer to it. Due to fallback
mechanisms in xcrun this never seemed to have caused any issues.
2023-10-30 10:00:40 -07:00
David Spickett
bb9dced2d3 [lldb][AArch64][Linux] Rename Is<ext>Enabled to Is<ext>Present (#70303)
For most register sets, if it was enabled this meant you could use it,
it was present in the process. There was no present but turned off
state. So "enabled" made sense.

Then ZA came along (and soon to be ZT0) where ZA can be present in the
hardware when you have SME, but ZA itself can be made inactive. This
means that "IsZAEnabled()" doesn't mean is it active, it means do you
have SME. Which is very confusing when we actually want to know if ZA is
active.

So instead say "IsZAPresent", to make these checks more specific. For
things that can't be made inactive, present will imply "active" as
they're never inactive.
2023-10-30 15:45:40 +00:00
Tulio Magno Quites Machado Filho
b2929bebb6 [lldb] Adapt code to Python 3.13 (#70445)
1. Remove usage of PyEval_ThreadsInitialized and PyEval_InitThreads

Both of these functions were removed in Python 3.13 [1] after being
deprecated since Python 3.9.

According to "What's new in Python 3.13" document [1]:

    Since Python 3.7, Py_Initialize() always creates the GIL: calling
    PyEval_InitThreads() did nothing and PyEval_ThreadsInitialized()
    always returned non-zero.

2. Replace _Py_IsFinalizing() with Py_IsFinalizing().

[1] https://docs.python.org/3.13/whatsnew/3.13.html
2023-10-30 08:55:34 -03:00
Sergei Barannikov
4e4433f629 [lldb] Remove some declarations without definitions (#70514)
The corresponding definitions were removed in 7dcbe3d3 and 2a8fa2a8.
Also remove a couple of variables made dead by those changes.
2023-10-28 02:33:50 +03:00
Jonas Devlieghere
d3cbf9fb64 [lldb] Add logging to ObjectFileMachO::ParseSymtab (#70490)
I have a crash when parsing the dyld trie data and I want to ask the
originator to send me the (possibly corrupted) binary that's causing
this. This patch adds some logging to help pinpoint that file.
2023-10-27 14:50:21 -07:00
Med Ismail Bennani
7a1e878358 [lldb] Introduce OperatingSystem{,Python}Interface and make use it
This patch aims to consolidate the OperatingSystem scripting affordance
by introducing a stable interface that conforms to the
Scripted{,Python}Interface.

This unify the way we call into python methods from lldb while
also improving its capabilities by allowing us to pass lldb_private
objects are arguments.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-26 15:12:22 -07:00
David Spickett
d1556e5efb [lldb][lldb-server] Enable sending RegisterFlags as XML (#69951)
This adds ToXML methods to encode RegisterFlags and its fields into XML
according to GDB's target XML format:

https://sourceware.org/gdb/onlinedocs/gdb/Target-Description-Format.html#Target-Description-Format

lldb-server does not use libXML to build XML, so this follows the
existing code that uses strings. Indentation is used so the result is
still human readable.

```
<flags id=\"Foo\" size=\"4\">
  <field name=\"abc\" start=\"0\" end=\"0\"/>
</flags>
```

This is used by lldb-server when building target XML, though no one sets
any fields yet. That'll come in a later commit.
2023-10-26 08:33:30 +01:00
Med Ismail Bennani
2abf997f82 [lldb] Fix assertions caused by un-checked errors in ScriptedProcess
This patch should fix some assertion that started getting hit after f22d82c.

That commit changed the scripted object plugin creation to use
`llvm::Expected<T>` as a return type to enforce error handling, however
I forgot to handle the error which caused the assert.

The interesting  part about this, is that since that assert was triggered
in the ScriptedProcess constructor (where the `llvm::Error` wasn't
handled), that impacted every test that launched any kind of process,
since the process plugin manager would eventually also iterate over the
`ScriptedProcess::Create` factory method.

This patch should fix the assertions by handling the errors.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-25 17:31:02 -07:00
Adrian Prantl
b82c629786 Fix log format strings 2023-10-25 16:42:37 -07:00
Pete Lawrence
463a02bc22 [lldb] Part 1 of 2 - Refactor CommandObject::Execute(...) return void (not bool) (#69989)
[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` to return
`void` instead of ~~`bool`~~

Justifications:
- The code doesn't ultimately apply the `true`/`false` return values.
- The methods already pass around a `CommandReturnObject`, typically
with a `result` parameter.
- Each command return object already contains:
	- A more precise status
	- The error code(s) that apply to that status

Part 2 refactors the `CommandObject::DoExecute(...)` method.
- See
[https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991)

rdar://117378957
2023-10-25 15:55:27 -07:00
Walter Erquinigo
10508b6db7 [LLDB][NFC] Remove DWARFASTParserClang as friend from SymbolFileDWARF (#70157)
This effectively moves a few functions from protected to public. In any
case, for the sake of having a cleaner SymbolFileDWARF API, it's better
if it's not a friend of a one of its consumers, DWARFASTParserClang.
Another effect of this change is that I can use SymbolFileDWARF for the
out-of-tree mojo dwarf parser, which relies on pretty much the same
functions that DWARFASTParserClang needs from SymbolFileDWARF.
2023-10-25 18:04:25 -04:00
Usama Hameed
77edd9b773 [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin (#69388)
[lldb] Refactor InstrumentationRuntimeAsan and add a new plugin
InstrumentationRuntimeLibsanitizers.

This commit refactors InstrumentationRuntimeASan by pulling out reusable
code into a separate ReportRetriever class. The purpose of the
refactoring is to allow reuse of the ReportRetriever class in another
plugin.

The commit also adds InstrumentationRuntimeASanLibsanitizers, a new runtime
plugin for ASan. The plugin provides the same
functionality as InstrumentationRuntimeASan, but provides a different
set of symbols/library names to search for while activating the plugin.

rdar://112491689
2023-10-25 12:52:52 -07:00
jeffreytan81
d4e6e40337 Improve debug names index fetching global variables performance (#70231)
While using dwarf5 `.debug_names` in internal large targets, we noticed
a performance issue (around 10 seconds delay) while `lldb-vscode` tries
to show `scopes` for a compile unit. Profiling shows the bottleneck is
inside `DebugNamesDWARFIndex::GetGlobalVariables` which linearly search
all index entries belongs to a compile unit.

This patch improves the performance by using the compile units list to
filter first before checking index entries. This significantly improves
the performance (drops from 10 seconds => under 1 second) in the split
dwarf situation because each compile unit has its own named index.

---------

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-10-25 11:46:11 -07:00
Mark de Wever
0e4264ab1e [lldb][libc++] Adds chrono data formatters.
This adds the data formatters for chrono duration typedefs.

Reviewed By: Michael137

Differential Revision: https://reviews.llvm.org/D159127
2023-10-25 19:36:47 +02:00
Med Ismail Bennani
7b8e686115 [lldb] Fix build failure introduced by f22d82c
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-25 10:31:43 -07:00
Med Ismail Bennani
f22d82cef2 [lldb/Interpreter] Make ScriptedInterface Object creation more generic (#68052)
This patch changes the way plugin objects used with Scripted Interfaces
are created.

Instead of implementing a different SWIG method to create the object for
every scripted interface, this patch makes the creation more generic by
re-using some of the ScriptedPythonInterface templated Dispatch code.

This patch also improves error handling of the object creation by
returning an `llvm::Expected`.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-25 10:05:54 -07:00
David Spickett
ff67b68e43 [lldb] On POSIX, check for duplicate interpreter modules without loading them (#69932)
Fixes #68987

Early on we load the interpreter (most commonly ld-linux) in
LoadInterpreterModule. Then later when we get the first DYLD rendezvous
we get a list of libraries that commonly includes ld-linux again.

Previously we would load this duplicate, see that it was a duplicate,
and unload it.

Problem was that this unloaded the section information of the first copy
of ld-linux. On platforms where you can place a breakpoint using only an
address, this wasn't an issue.

On ARM you have ARM and Thumb modes. We must know which one the section
we're breaking in is, otherwise we'll go there in the wrong mode and
SIGILL. This happened on ARM when lldb tried to call mmap during
expression evaluation.

To fix this, I am making the assumption that the base address we see in
the module prior to loading can be compared with what we know the
interpreter base address is. Then we don't have to load the module to
know we can ignore it.

This fixes the lldb test suite on Ubuntu versions where
https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/1927192 has been
fixed. Which was recently done on Jammy.
2023-10-25 10:12:45 +01:00
David Spickett
d8abce1181 [lldb][AArch64] Read mte_ctrl register from core files (#69689)
This register reports the configuration of the AArch64 Linux tagged
address ABI, part of which is the memory tagging (MTE) settings.

It will always be present in core files because even without MTE, there
are parts of the tagged address ABI that can be configured (these parts
use the Top Byte Ignore feature).

I missed adding this when I previously worked on MTE support. Until now
you could read memory tags from a core file but not this register.
2023-10-25 09:54:34 +01:00
David Spickett
1d10369f53 Reland "[lldb][AArch64] Invalidate SVG prior to reconfiguring ZA regdef (#66768)""
This reverts commit 8d80a452b8.

The pointer to the invalidates lists needs to be non-const. Though in this case
I don't think it's ever modified.

Also I realised that the invalidate list was being set on svg not vg.
Should be the other way around.
2023-10-25 08:40:17 +00:00
David Spickett
8d80a452b8 Revert "[lldb][AArch64] Invalidate SVG prior to reconfiguring ZA regdef (#66768)"
This reverts commit f2c09e5e16, due to compilation
failures on buildbots.
2023-10-25 08:27:27 +00:00
David Spickett
f2c09e5e16 [lldb][AArch64] Invalidate SVG prior to reconfiguring ZA regdef (#66768)
This fixes a bug where writing vg during streaming mode
could prevent you reading za directly afterwards.

vg is invalidated just prior to us reading it in AArch64Reconfigure,
but svg was not. This lead to some situations where vg would be
updated or cleared and re-read, but svg would not be.

This meant it had some undefined value which lead to errors
that prevented us reading ZA. Likely we received a lot more
data than we were expecting.

There are at least 2 ways to get into this situation:
* Explicit write by the user to vg.
* We have just stopped and need to get the potentially new svg and vg.

The first is handled by invalidating svg client side before fetching the
new one. This also
covers some but not all of the second scenario. For the second, I've
made writes to vg
invalidate svg by noting this in the register information.

Whichever one of those kicks in, we'll get the latest value of svg.

The bug may depend on timing, I could not find a consistent way
to trigger it. I originally found it when checking whether za
is disabled after a vg change, so I've added checks for that
to TestZAThreadedDynamic.

The SVE VG version of the bug did show up on the buildbot,
but not consistently. So it's possible that TestZAThreadedDynamic
does in fact cover this, but I haven't run it enough times to know.
2023-10-25 09:16:58 +01:00
David Spickett
a770098557 [lldb][AArch64] Correct type of 32 bit GPR RegisterValues when using core files (#70054)
As ReadRegister always read into a uint64_t, when it called operator=
with uint64_t it was setting the RegisterValue's type to eTypeUInt64
regardless of its size.

This mostly works because most registers are 64 bit, and very few bits
of code rely on the type being correct. However, cpsr, fpsr and fpcr are
in fact 32 bit, and my upcoming register fields code relies on this type
being correct.

Which is how I found this bug and unfortunately is the only way to test
it. As RegisterValue::Type never makes it out via the API anywhere. So
this change will be tested once I start adding register field
information.
2023-10-25 09:08:01 +01:00
Adrian Prantl
49504674db Expose DWARFDIE::GetDeclContext() in lldb_private::Function. (#69981)
I need this API in the Swift plugin, but it seems generally useful
enough to expose it in the main branch.
2023-10-24 10:55:23 -07:00
Augusto Noronha
e3476f68af [lldb][gardening] Remove full name of "DWARFDIE" type in GetTypeForDIE (#70062)
When moving the GetTypeForDIE function from DWARFASTParserClang to
DWARFASTParser, I kept the signature as-is. To match the rest of the
function signatures in DWARFASTParser, remove the full name
(lldb_private::plugin::dwarf::DWARFDIE -> DWARFDIE) in the signature of
DWARFASTParser::GetTypeForDIE.
2023-10-24 09:49:08 -07:00
Augusto Noronha
3b89794304 Reintroduce accidentally deleted "protected" keyword in SymbolFileDWARF (#69990)
The "protected" was accidentally removed during refactoring of
SymbolFileDWARF. Reintroduce it and also make DWARFASTParser a friend
class since 040c4f4d98f3306e068521e3c218bdbc170f81f3 was merged and
won't build without it, as it dependeds on a method which was made
public by accident.
2023-10-24 09:27:08 -07:00
jeffreytan81
00d3ed6dea [Reland] Detect against invalid variant index for LibStdC++ std::variant data formatters (#69614)
This is relanding of https://github.com/llvm/llvm-project/pull/69253.
`TestTemplatePackArgs.py` is passing now.

https://github.com/llvm/llvm-project/pull/68012/files added new data
formatters for LibStdC++ std::variant.

However, this formatter can crash if std::variant's index field has
invalid value (exceeds the number of template arguments).
This can happen if the current IP stops at a place std::variant is not
initialized yet.

This patch fixes the crash by ensuring the index is a valid value and
fix GetNthTemplateArgument() to make sure it is not crashing.

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-10-24 08:44:34 -07:00
David Spickett
febc4ff74a [lldb][AArch64][NFC] Fix typo in get trap handler function 2023-10-24 10:36:20 +00:00
Augusto Noronha
e6b3a2753b [lldb][NFC] Move DWARFASTParserClang::GetTypeForDIE to DWARFASTParser (#69764) 2023-10-23 17:22:16 -07:00
Augusto Noronha
e45356910f [lldb][NFC] Remote reference to Swift in DWARFASTParser::Kind enum (#69984) 2023-10-23 16:37:45 -07:00
Augusto Noronha
61c4ee9449 [lldb][NFC] Implement llvm-style RTTI for DWARFASTParser (#69762) 2023-10-23 16:25:18 -07:00
Med Ismail Bennani
77374d3b53 [lldb] Move ScriptInterpreter Interfaces to subdirectory (NFC)
As we're consolidating and  streamlining the various scripting
affordances of lldb, we keep creating new interface files.

This patch groups all the current interface files into a separate sub
directory called `Interfaces` both in the core `Interpreter` directory
and the `ScriptInterpreter` plugin directory.

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

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2023-10-23 09:51:01 -07:00
Kazu Hirata
66a797102d [lldb] Use llvm::is_contained (NFC) 2023-10-22 21:18:25 -07:00
Tom Yang
74ca07295f [lldb] improve dwo path in missing dwo error when relative (#69783)
When the debug info refers to a dwo with relative `DW_AT_comp_dir` and
`DW_AT_dwo_name`, we only print the `DW_AT_comp_dir` in our error
message if we can't find it. This often isn't very helpful, especially
when the `DW_AT_comp_dir` is ".":
```
(lldb) fr v
error: unable to locate .dwo debug file "." for skeleton DIE 0x000000000000003c
```

I'm updating the error message to include both `DW_AT_comp_dir` (if it
exists) and `DW_AT_dwo_name` when the `DW_AT_dwo_name` is relative. The
behavior when `DW_AT_dwo_name` is absolute should be the same.
2023-10-21 16:59:44 -07:00
Kazu Hirata
6e3572ccd8 [lldb] Use llvm::erase_if (NFC) 2023-10-20 00:20:30 -07:00
Jonas Devlieghere
969ba9ff14 [lldb] Remove FileSpecList::GetFilesMatchingPartialPath (NFC)
This function is unused and unimplemented.
2023-10-19 15:17:36 -07:00
Felipe de Azevedo Piovezan
ea9e116e5a [lldb][NFCI] Remove duplicated code in DWARFParser (#69531)
The method DWARFDebugInfoEntry::Extract needs to skip over all the data
in the debug_info / debug_types section for each DIE. It had the logic
to do so hardcoded inside a loop, when it already exists in a neatly
isolated function.
2023-10-19 14:10:31 -07:00
Jonas Devlieghere
f9632cee30 [lldb] Remove FileSpecList::GetFileSpecPointerAtIndex (NFC)
There's only one use and it eventually converts the pointer into a
reference. Simplify things and always use references.
2023-10-19 13:13:31 -07:00
Jonas Devlieghere
5bae3a0b0c [lldb] Remove CompileUnit::SetSupportFiles overload (NFC)
CompileUnit::SetSupportFiles had two overloads, one that took and lvalue
reference and one that takes an rvalue reference. This removes both and
replaces it with an overload that takes the FileSpecList by value and
moves it into the member variable.

Because we're storing the value as a member, this covers both cases. If
the new FileSpecList was passed by lvalue reference, we'd copy it into
the member anyway. If it was passed as an rvalue reference, we'll have
created a new instance using its move and then immediately move it again
into our member. In either case the number of copies remains unchanged.
2023-10-19 11:14:25 -07:00
Jonas Devlieghere
bd21efe24c [lldb] Fix ASCII art in CommandObjectSource.h (NFC) 2023-10-19 10:30:38 -07:00
Harmen Stoppels
0a9bdc276d [lldb] Fix linking to libtinfo (#69458)
LLVM detects when ncurses has a separate terminfo library, but linking to it
was broken in lldb since b66339575a (LLVM14)
due to a change of variables. This commit fixes that oversight.
2023-10-18 16:06:50 +01:00
David Spickett
0dca56603b Revert "Detect against invalid variant index for LibStdC++ std::variant data formatters (#69253)"
This reverts commit 659a48f25a.

This caused another test to fail on Windows AArch64 and x86_64, and AArch64 Linux.
2023-10-18 10:25:41 +00:00
jeffreytan81
659a48f25a Detect against invalid variant index for LibStdC++ std::variant data formatters (#69253)
https://github.com/llvm/llvm-project/pull/68012/files added new data
formatters for LibStdC++ std::variant.

However, this formatter can crash if std::variant's index field has
invalid value (exceeds the number of template arguments).
This can happen if the current IP stops at a place std::variant is not
initialized yet.

This patch fixes the crash by ensuring the index is a valid value.

---------

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-10-17 17:26:05 -07:00
walter erquinigo
7d1bf1c5cf [LLDB][NFC] Move some constructors to their cpp file
CompilerType constructors rely on the NDEBUG macro, so it's better to move them to their cpp file so that the header doesn't get confused when this macro is used differently for other compilation units.
2023-10-17 18:50:18 -04:00
Alex Langford
170b552136 [lldb] Scalar::GetValue() should take a Stream by reference (#69231)
This function always expects the pointer to be valid, a reference seems
more appropriate.
2023-10-17 15:40:51 -07:00
walter erquinigo
59908504cd [LLDB][NFC] Add a missing namespace
This adds back a namespace to the value of a #define statement. This is needed to prevent collision with other types with the same name.
2023-10-17 18:15:29 -04:00
David Spickett
17fce28683 [lldb][DYLD][NFC] Dedupe calls to CreateBreakpoint
These only differ in the modules passed to them. Also I've
swapped the if order so we have the "positive" check first.
2023-10-16 10:15:46 +00:00
Vlad Serebrennikov
93229c7bfd [lldb] Add SBType::FindDirectNestedType() function (#68705)
This patch adds a `SBType::FindDirectNestedType(name)` function which performs a non-recursive search in given class for a type with specified name. The intent is to perform a fast search in debug info, so that it can be used in formatters, and let them remain responsive.

This is driven by my work on formatters for Clang and LLVM types. In particular, by [`PointerIntPairInfo::MaskAndShiftConstants`](cde9f9df79/llvm/include/llvm/ADT/PointerIntPair.h (L174C16-L174C16)), which is required to extract pointer and integer from `PointerIntPair`.

Related Discourse thread: https://discourse.llvm.org/t/traversing-member-types-of-a-type/72452
2023-10-14 10:52:34 +04:00
Walter Erquinigo
1673a1ba5d [LLDB][NFC] Create a namespace for the DWARF plugin (#68150)
As a followup of https://github.com/llvm/llvm-project/pull/67851, I'm
defining a new namespace `lldb_plugin::dwarf` for the classes in this
Plugins/SymbolFile/DWARF folder. This change is very NFC and helped me
with exporting the necessary symbols for my out-of-tree language plugin.
The only class that I didn't change is ClangDWARFASTParser, because that
shouldn't be in the same namespace as the generic language-agnostic
dwarf parser.
It would be a good idea if other plugins follow the same namespace
scheme.
2023-10-13 16:51:24 -04:00
Michael Buch
0dfcfb53d7 [lldb][DataFormatter] VectorType: fix format for arrays with size not a power-of-2 (#68907)
To get the number of children for a VectorType (i.e.,
a type declared with a `vector_size`/`ext_vector_type` attribute)
LLDB previously did following calculation:
1. Get byte-size of the vector container from Clang (`getTypeInfo`).
2. Get byte-size of the element type we want to interpret the array as.
   (e.g., sometimes we want to interpret an `unsigned char vec[16]`
   as a `float32[]`).
3. `numChildren = containerSize / reinterpretedElementSize`

However, for step 1, clang will return us the *aligned* container
byte-size.
So for a type such as `float __attribute__((ext_vector_type(3)))`
(which is an array of 3 4-byte floats), clang will round up the
byte-width of the array to `16`.
(see
[here](ab6a66dbec/clang/lib/AST/ASTContext.cpp (L1987-L1992)))

This means that for vectors where the size isn't a power-of-2, LLDB
will miscalculate the number of elements.

**Solution**

This patch changes step 1 such that we calculate the container size
as `numElementsInSource * byteSizeOfElement`.
2023-10-13 20:07:41 +01:00