28510 Commits

Author SHA1 Message Date
Alex Langford
a2ff2921e8 [lldb][NFCI] TypeSystemClang::CreateStructForIdentifier should take a StringRef
This doesn't really use fast comparison or string uniqueness. In fact,
all of the current callers pass an empty string for type_name. The only
reason I don't remove it is because it looks like it is used downstream
for swift.

Differential Revision: https://reviews.llvm.org/D153810
2023-07-03 09:35:24 -07:00
Alex Langford
673f91055a [lldb][NFCI] Remove unneeded use of ConstString in ASTResultSynthesizer
2/3 of the ConstStrings in this class were just to be able to log
something. Putting something in the StringPool just to log it doesn't
make a lot of sense, so let's remove them.

The remaining use is for `RegisterPersistentDecl` which is fine for now.

Differential Revision: https://reviews.llvm.org/D153905
2023-07-03 09:31:10 -07:00
Felipe de Azevedo Piovezan
f292ca1362 [lldb][NFC] Simplify GetLocation_DW_OP_addr function
A very old commit (9422dd64f870dd33) changed the signature of this function in a
number of ways. This patch aims to improve it:

1. Reword the documentation, which still mentions old parameters that no longer
exist, and to elaborate upon the behavior of this function.
2. Remove the unnecessary parameter `op_addr_idx`. This parameter is odd in a
couple of ways: we never use it with a value that is non-zero, and the matching
`Update_DW_OP_addr` function doesn't use a similar parameter. We also document
that this new behavior. If we ever decide to handle multiple "DW_OP_addr", we
can introduce the complexity again.

Differential Revision: https://reviews.llvm.org/D154265
2023-07-03 08:36:57 -04:00
Felipe de Azevedo Piovezan
379b59d1b0 [lldb] Skip apple accelerator table test in DWARF 5 mode
D68678 added a test that ensures an Apple accelerator lookup is done
efficiently. Since these tables are not used for DWARF 5, we should decorate the
test appropriately.

Differential Revision: https://reviews.llvm.org/D154268
2023-07-03 08:35:55 -04:00
Jason Molenda
624813a4f4 Change the dyld notification function that lldb puts a breakpoint in
On Darwin systems, the dynamic linker dyld has an empty function
it calls when binaries are added/removed from the process.  lldb puts
a breakpoint on this dyld function to catch the notifications.  The
function arguments are used by lldb to tell what is happening.

The linker has a natural representation when the addresses of
binaries being added/removed are in the pointer size of the process.
There is then a second function where the addresses of the binaries
are in a uint64_t array, which the debugger has been using before -
dyld allocates memory for the array, copies the values in to it,
and calls it for lldb's benefit.

This changes to using the native notifier function, with pointer-sized
addresses.

Differential Revision: https://reviews.llvm.org/D139453
2023-06-30 18:29:46 -07:00
Dave Lee
b43375bb81 [lldb] Add log indicating which kind of data formatter
The `formatter` logs include a function name, but these functions are mostly templates
and the template type parameter is not printed, which is useful context.

This change adds a new log which is printed upon entry of `FormatManager::Get`, which
shows the formatter context as either `format`, `summary`, or `synthetic`.

Differential Revision: https://reviews.llvm.org/D154128
2023-06-30 16:51:14 -07:00
Dave Lee
2c37cbef58 [lldb] Delete RewriteObjCClassReferences (NFC)
The `RewriteObjCClassReferences` pass was applicable only to the code generated for the
fragile ObjC ABI (v1). That ABI is no longer active (last used for i386 macOS), which
means this pass has no effect.

Sources: `OBJC_CLASS_REFERENCES_` is emitted only by `CGObjCMac`, and not by
`CGObjCNonFragileABIMac`.

Differential Revision: https://reviews.llvm.org/D153802
2023-06-30 14:39:20 -07:00
David Spickett
dfbe3a79e2 [lldb] Check that qLaunchGDBServer packet does not return an error
While looking at https://github.com/llvm/llvm-project/issues/61955
I noticed that when we send qLaunchGDBServer we check that we got a response
but not what kind of response it was.

I think this was why the bug reporter saw:
(lldb) run
error: invalid host:port specification: '[192.168.64.2]'

The missing port is because we went down a path we only should have
chosen if the operation succeeded. Since we didn't check, we went ahead
with an empty port number.

To test this I've done the following:
* Make a temporary copy of lldb-server.
* Run that as a platform.
* Remove the copy.
* Attempt to create and run a target.

This fails because the running lldb-server will try to invoke itself
and it no longer exists.

Reviewed By: jasonmolenda

Differential Revision: https://reviews.llvm.org/D153513
2023-06-30 09:12:30 +00:00
Jason Molenda
37d11e94a4 "fp" -> "flags" typeo in description of generic registers
the list of generic registers is meant to include
LLDB_REGNUM_GENERIC_FLAGS but it copy & pasted the
name "fp".

rdar://100857252
2023-06-29 18:22:58 -07:00
Jason Molenda
623e845591 Recognize BSS-only DATA segments as sections that need to be slid
ObjectFileMachO::SetLoadAddress() should allow for a DATA segment
that has no file content to be slid in the vmaddr, it is valid
to have such a section.

Differential Revision: https://reviews.llvm.org/D154037
rdar://99744343
2023-06-29 17:51:41 -07:00
Jason Molenda
ad451146e8 Add 'target dump section-load-list' for lldb debugging
A command to dump the Target's SectionLoadList, to debug
possible issues with the table.

Differential Revision: https://reviews.llvm.org/D154169
2023-06-29 17:02:54 -07:00
John Harrison
b9b0ab32f9 [lldb-vscode] Adjusting CreateSource to detect compiler generated frames.
Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D154026
2023-06-29 15:31:08 -04:00
John Harrison
fc52f8dc6c [lldb-vscode] Prior to running the launchCommands during a launch request set the launch info so the configured launch information is accessible by the launch commands.
Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D154028
2023-06-29 14:50:19 -04:00
John Harrison
227b2180eb Creating a startDebugging reverse DAP request handler in lldb-vscode.
Adds support for a reverse DAP request to startDebugging. The new request can be used to launch child processes from lldb scripts, for example it would be start forward to configure a debug configuration for a server and a client allowing you to launch both processes with a single debug configuraiton.

Reviewed By: wallace, ivanhernandez13

Differential Revision: https://reviews.llvm.org/D153447
2023-06-29 14:45:57 -04:00
David Spickett
728101f972 Reland "[LLDB] Fix the use of "platform process launch" with no extra arguments"
This reverts commit 3254623d73fb7252385817d8057640c9d5d5ffd1.

One test has been updated to add the "-s" flag which along with
86fd957af981f146a306831608d7ad2de65b9560 should fix the tests on MacOS.

An assert on hijack listener added in that patch was removed, it seems
to be correct on MacOS but not on Linux.
2023-06-29 08:21:42 +00:00
Caroline Tice
ee476996be [LLDB] Fix buffer overflow problem in DWARFExpression::Evaluate.
In two calls to ReadMemory in DWARFExpression.cpp, the buffer size
passed to ReadMemory is not actually the size of the buffer (I suspect
a copy/paste error where the variable name was not properly
updated). This caused a buffer overflow bug, which we found throuth
Address Sanitizer.  This patch fixes the problem by passing the
correct buffer size to the calls to ReadMemory (and to the
DataExtractor).

Differential Revision: https://reviews.llvm.org/D153840
2023-06-28 11:46:55 -07:00
Felipe de Azevedo Piovezan
8e71d14972 [lldb] Use LLVM's implementation of AppleTables for apple_objc
This concludes the migration of accelerator tables from LLDB code to LLVM code.

Differential Revision: https://reviews.llvm.org/D153868
2023-06-28 10:05:36 -04:00
Felipe de Azevedo Piovezan
e12c701ff0 [lldb] Use LLVM's implementation of AppleTables for apple_debug_types
This commit is replacing really old LLDB code, and we've found some odd
behavior while doing this replacement. While the changes here are largely NFC,
there are some subtle changes that fix such odd behavior.

The most curious example of this is the method `FindCompleteObjCClassName`,
which has a flag `must_be_implementation`. This flag was _only_ being respected
for accelerator tables containing the atom `type_flags`, which seems
counter-intuitive. The implementation for DWARF 5 tables does not do that and
neither does the code introduced in this patch.

There were other weird cases, for example, we found boolean logic that was
always true in a code path: look for a `if  !has_qualified_name...` deleted
line; that condition was true by simple if/else analysis.

Differential Revision: https://reviews.llvm.org/D153867
2023-06-28 09:19:14 -04:00
Felipe de Azevedo Piovezan
4d5c9ad9c3 [lldb] Use LLVM's implementation of AppleTables for apple_{names,namespaces}
All the new code should match the behavior of the old exactly.

Of note, the custom queries used to be implemented inside `HashedNameToDIE.cpp`
(which is the LLDB implementation of the tables). However, when porting to LLVM,
we believe they don't belong inside the LLVM table implementation:

1. They don't require any knowledge about the table itself
2. They are not relevant for other users of these classes.
3. They use LLDB data structures.

As such, we implement these custom queries inside AppleDWARFIndex.cpp.

Types and Objective-C tables are done separately, as they have slightly
different functionality that require rewriting more code.

Differential Revision: https://reviews.llvm.org/D153866
2023-06-28 08:31:02 -04:00
Hau Hsu
28722dcc25 Summary: [lldb] Fix libncurses, libpanel library link order
libpanel depends on libcurses, so when linking static libraries, libpanel
should be places prior to libcurses.

This patch resolves error like:
```
.../x86_64-centos6-linux-gnu/bin/ld:
.../lib/libpanelw.a(p_show.o):
in function `show_panel':
p_show.c:(.text+0x39): undefined reference to `_nc_panelhook_sp'
.../x86_64-centos6-linux-gnu/bin/ld:
.../lib/libpanelw.a(p_show.o):
in function `update_panels_sp':
p_update.c:(.text+0x1f): undefined reference to `_nc_panelhook_sp'
collect2: error: ld returned 1 exit status
```

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D153844
2023-06-28 15:00:22 +08:00
Dave Lee
8ce2d90f1e [lldb] Fix search & replace mistake in IRForTarget comment (NFC)
See 1b95a6ff95a279de27d5f63de8d67a731f280b44
2023-06-27 18:38:01 -07:00
Dave Lee
6feb35bac5 [lldb] Improve log message (NFC)
Remove the unmatched closing paren )
2023-06-27 18:32:05 -07:00
Jonas Devlieghere
7d04c886f9
[lldb] Assert index is valid in DWARFDeclContext
Replace the comment with an assert to enforce the correct index is used.

Differential revision: https://reviews.llvm.org/D153921
2023-06-27 18:23:35 -07:00
Jason Molenda
7075f9d926 Have GetKernelsAndKextsInDirectoryHelper request follow symlinks
While working on the broken-symlinks issue, I noticed this one place
where I was setting `find_other` to false unintentionally in the
darwin kernel platform kext/kernel scan.  Small fix while I'm here.
2023-06-27 16:18:08 -07:00
Dave Lee
86fd957af9 [lldb] Duplicate Target::Launch resuming logic into CommandObjectPlatformProcessLaunch
Fix `platform process launch` on macOS where it fails for lack of auto-resuming support.

This change reproduces the resuming logic found in `Target::Launch`.

This issue was identified by @DavidSpickett in D153636. This change relies on the tests
added in that PR. Thanks David.

Differential Revision: https://reviews.llvm.org/D153922
2023-06-27 15:29:52 -07:00
Felipe de Azevedo Piovezan
ab674234c4 [lldb][NFC] Prevent slicing when converting DataExtractors
LLDB's implementation of DWARFDataExtractor has a method that returns a
llvm::DWARFDataExtractor. In some cases, like DebugNamesDWARFIndex::Create, we
were passing an LLVM::DWARFDataExtractor to a function that expects a
LLVM:DataExtractor by value. This is causing slicing of the derived class.

While slicing is not inherently bad, it can be dangerous if the constructor of
the derived class mutates the base class in a way that leaves it in an invalid
state after slicing.

Differential Revision: https://reviews.llvm.org/D153913
2023-06-27 18:09:40 -04:00
Jonas Devlieghere
ca7914564e
[lldb] Avoid FileSystem::Resolve for cached files in the SourceManager
Currently, source files are cached by their resolved path. This means
that before we can query the cache, we potentially have to resolve the
path, which can be slow. This patch avoids the call to FileSystem::Resolve
by caching both the resolved and unresolved path. We now only resolve
the path once when we create and cache a new file.

rdar://110787562

Differential revision: https://reviews.llvm.org/D153726
2023-06-27 14:19:02 -07:00
Alex Langford
1bd69ae0c5 [lldb][NFCI] Apply LLDB_DEPRECATED to things that have deprecated comments
Now that we have a proper way to deprecate things in the SB API, we
should apply it where we have manually done so with comments.

Differential Revision: https://reviews.llvm.org/D153824
2023-06-27 10:46:34 -07:00
Alex Langford
7ec083107f [lldb][NFCI] Remove use of ConstString from PluginManager
The underlying structures no longer use ConstString so we can remove it
wholesale from PluginManager now.

Differential Revision: https://reviews.llvm.org/D153818
2023-06-27 10:43:35 -07:00
David Spickett
3254623d73 Revert "[LLDB] Fix the use of "platform process launch" with no extra arguments"
This reverts commit cc0fc358540517a3d205243c27bd543afeae2b02 due to a failure
reported on MacOS.
2023-06-27 14:04:41 +00:00
David Spickett
956f5c5f6d [lldb] Use SmallVector for handling register data
Previously lldb was using arrays of size kMaxRegisterByteSize to handle
registers. This was set to 256 because the largest possible register
we support is Arm's scalable vectors (SVE) which can be up to 256 bytes long.

This means for most operations aside from SVE, we're wasting 192 bytes
of it. Which is ok given that we don't have to pay the cost of a heap
alocation and 256 bytes isn't all that much overall.

With the introduction of the Arm Scalable Matrix extension there is a new
array storage register, ZA. This register is essentially a square made up of
SVE vectors. Therefore ZA could be up to 64kb in size.

https://developer.arm.com/documentation/ddi0616/latest/

"The Effective Streaming SVE vector length, SVL, is a power of two in the range 128 to 2048 bits inclusive."

"The ZA storage is architectural register state consisting of a two-dimensional ZA array of [SVLB × SVLB] bytes."

99% of operations will never touch ZA and making every stack frame 64kb+ just
for that slim chance is a bad idea.

Instead I'm switching register handling to use SmallVector with a stack allocation
size of kTypicalRegisterByteSize. kMaxRegisterByteSize will be used in places
where we can't predict the size of register we're reading (in the GDB remote client).

The result is that the 99% of small register operations can use the stack
as before and the actual ZA operations will move to the heap as needed.

I tested this by first working out -wframe-larger-than values for all the
libraries using the arrays previously. With this change I was able to increase
kMaxRegisterByteSize to 256*256 without hitting those limits. With the
exception of the GDB server which needs to use a max size buffer.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D153626
2023-06-27 09:15:12 +00:00
David Spickett
cc0fc35854 [LLDB] Fix the use of "platform process launch" with no extra arguments
This fixes #62068.

After 8d1de7b34af46a089eb5433c700419ad9b2923ee the following issue appeared:
```
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) platform process launch -s
error: Cannot launch '': Nothing to launch
```

Previously would call target->GetRunArguments when there were no extra
arguments, so we could find out what target.run-args might be.

Once that change started relying on the first arg being the exe,
the fact that that call clears the existing argument list caused the bug.

Instead, have it set a local arg list and append that to the existing
one. Which in this case will just contain the exe name.

Since there's no existing tests for this command I've added a new file
that covers enough to check this issue.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D153636
2023-06-27 07:41:18 +00:00
Jason Molenda
2c1108f443 FileSystem::EnumerateDirectory should skip entries w/o Status, not halt
EnumerateDirectory gets the vfs::Status of each directory entry to
decide how to process it.  If it is unable to get the Status for
a directory entry, it will currently halt the directory iteration
entirely.  It should only skip this entry.

Differential Revision: https://reviews.llvm.org/D153822
rdar://110861210
2023-06-26 17:46:53 -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
Alex Langford
7ed3c2edf0 [lldb] Increase the maximum number of classes we can read from shared cache
The shared cache has grown past the previously hardcoded limit. As a
temporary measure, I am increasing the hardcoded number of classes we
can expect to read from the shared cache. This is not a good long-term
solution.

Differential Revision: https://reviews.llvm.org/D153817
2023-06-26 14:59:55 -07:00
walter erquinigo
fec7c313ab [LLDB] Fix 582582fb474b8cd4103e65c3e5a705b3aff61794
This issue has been seen in

- https://lab.llvm.org/buildbot/#/builders/17/builds/39525
- https://lab.llvm.org/buildbot/#/builders/68/builds/55140

The reason is that a new language tag has been added for Mojo, but other recent languages need to be added to the language array so that a name lookup array doesn't have gaps.

`ninja check-lldb-shell-process` now passes.
2023-06-26 13:16:57 -05:00
Alex Langford
9442e81f02 [lldb][NFCI] Remove ConstString from Process::ConfigureStructuredData
This is a follow-up to b4827a3c0a7ef121ca376713e115b04eff0f5194.

Differential Revision: https://reviews.llvm.org/D153675
2023-06-26 11:09:09 -07:00
Alex Langford
2014572d9a [lldb][NFCI] Remove unneeded ConstString constructions for OptionValueProperties::AppendProperty
I removed ConstString from OptionValueProperties in 643ba926c1f6, but
there are a few call sites that still create a ConstString as an
argument. I did not catch these initially because ConstString has an
implicit conversion method to StringRef.

Differential Revision: https://reviews.llvm.org/D153673
2023-06-26 11:06:29 -07:00
Jonas Devlieghere
d49caf4afc
[lldb] Add source cache dump and source cache clear subcommand
Add two new source subcommands: source cache dump and source cache
clear. As the name implies the first one dumps the source cache while
the later clears the cache.

This patch was motivated by a handful of (internal) bug reports related
to sources not being available. Right now those issues can be hard to
diagnose. The new commands give users, as well as us as developers, more
insight into and control over the source cache.

Differential revision: https://reviews.llvm.org/D153685
2023-06-26 10:40:08 -07:00
Alex Langford
5f69e6682b [lldb][NFCI] Timer::DumpCategoryTimes should take a reference instead of a pointer
We are assuming that the pointer is always valid, might as well take a
reference instead.

Differential Revision: https://reviews.llvm.org/D153711
2023-06-26 10:36:41 -07:00
Alex Langford
718e0cd6e7 [lldb][NFCI] UUID::Dump should take a reference instead of a pointer
We always assume the Stream pointer is valid, might as well be taking a
reference instead.

Differential Revision: https://reviews.llvm.org/D153710
2023-06-26 10:33:18 -07:00
walter erquinigo
582582fb47 [LLDB] Add DWARF definitions for the new Mojo language
The new language Mojo recently received a proper DWARF code, which can be seen in https://dwarfstd.org/languages.html, and this patch adds the basic definitions for using this language in DWARF.

Differential Revision: https://reviews.llvm.org/D153073
2023-06-26 11:31:48 -05:00
Dave Lee
080fa1ee38 [lldb] Use LLDB_LOGF for printf format strings in AppleObjCDeclVendor.cpp 2023-06-24 15:02:01 -07:00
Jonas Devlieghere
c0045a8e8e
[lldb] Use format specific for unprintabe char in DumpDataExtractor
Addresses Jason's post-commit feedback in D153644.
2023-06-23 11:56:41 -07:00
Jonas Devlieghere
85f40fc676
[lldb] Print unprintable characters as unsigned
When specifying the C-string format for dumping memory, we treat
unprintable characters as signed. Whether a character is signed or not
is implementation defined, but all printable characters are signed.
Therefore it's fair to assume that unprintable characters are unsigned.

Before this patch, "\xcf\xfa\xed\xfe\f" would be printed as
"\xffffffcf\xfffffffa\xffffffed\xfffffffe\f". Now we correctly print the
original string.

rdar://111126134

Differential revision: https://reviews.llvm.org/D153644
2023-06-23 11:00:21 -07:00
Alex Langford
1a397ecffd [lldb][NFCI] Remove use of ConstString from StructuredDataPlugin
The use of ConstString in StructuredDataPlugin is unneccessary as fast
comparisons are not neeeded for StructuredDataPlugins.

Differential Revision: https://reviews.llvm.org/D153482
2023-06-23 10:29:52 -07:00
Alex Langford
28fb39f16a [lldb] Adjust for changes in objc runtime
The Objective-C runtime and the shared cache has changed slightly.
Given a class_ro_t, the baseMethods ivar is now a pointer union and may
either be a method_list_t pointer or a pointer to a relative list of
lists. The entries of this relative list of lists are indexes that refer
to a specific image in the shared cache in addition to a pointer offset
to find the accompanying method_list_t. We have to go over each of these
entries, parse it, and then if the relevant image is loaded in the
process, we add those methods to the relevant clang Decl.

In order to determine if an image is loaded, the Objective-C runtime
exposes a symbol that lets us determine if a particular image is loaded.
We maintain a data structure SharedCacheImageHeaders to keep track of
that information.

There is a known issue where if an image is loaded after we create a
Decl for a class, the Decl will not have the relevant methods from that
image (i.e. for Categories).

rdar://107957209

Differential Revision: https://reviews.llvm.org/D153597
2023-06-22 16:42:22 -07:00
Jonas Devlieghere
f9f279dc64
[lldb] Fix variable name mismatch between signature and docs (NFC)
The variable is named `bundle_dir` but the documentation referenced
`directory` which generated a warning.
2023-06-22 13:50:54 -07:00
Kazuki Sakamoto
5c4071d225 [lldb][Windows] Fix ZipFileResolver tests
D152759 introduced the Android .zip so file support, but it only considered
POSIX path. The code also runs on Windows, so the path could be Windows path.
Support both patterns on Windows.

Differential Revision: https://reviews.llvm.org/D153390
2023-06-22 10:42:40 -07:00
Jason Molenda
3858e9d6c5 Add two new entitlements when debugserver is built by Apple
Two new entitlements, com.apple.private.thread-set-state and
com.apple.private.set-exception-port should be included in the
debugserver entitlement plist when built internally at Apple.
The desktop builds of debugserver don't need these entitlements;
don't add them to debugserver-macosx-entitlements.plist.

rdar://108912676
rdar://103032208
2023-06-21 14:56:11 -07:00