Commit Graph

1932 Commits

Author SHA1 Message Date
Walter Erquinigo 34885bffdf [lldb-vscode] Handle request_evaluate's context attribute
Summary:
The request "evaluate" supports a "context" attribute, which is sent by VSCode. The attribute is defined here https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate

The "clipboard" context is not yet supported by lldb-vscode, so we can forget about it for now. The 'repl' (i.e. Debug Console) and 'watch' (i.e. Watch Expression) contexts must use the expression parser in case the frame's variable path is not enough, as the user expects these expressions to never fail. On the other hand, the 'hover' expression is invoked whenever the user hovers on any keyword on the UI and the user is fine with the expression not being fully resolved, as they know that the 'repl' case is the fallback they can rely on.

Given that the 'hover' expression is invoked many many times without the user noticing it due to it being triggered by the mouse, I'm making it use only the frame's variable path functionality and not the expression parser. This should speed up tremendously the responsiveness of a debug session when the user only sets source breakpoints and inspect local variables, as the entire debug info is not needed to be parsed.

Regarding tests, I've tried to be as comprehensive as possible considering a multi-file project. Fortunately, the results from the "hover" case are enough most of the times.

Differential Revision: https://reviews.llvm.org/D98656
2021-03-15 15:09:23 -07:00
Jonas Devlieghere 3dcbfa27d4 [debugserver] Fix more compiler warnings on arm64
This fixes the following two warnings in code that's only compiled on
arm64:

 - warning: cast from 'const void *' to 'unsigned char *' drops const
   qualifier [-Wcast-qual]
 - warning: embedding a directive within macro arguments has undefined
   behavior [-Wembedded-directive]
2021-03-03 23:12:12 -08:00
Jonas Devlieghere 011a8e218e [debugserver] Fix logic to extract app bundle from file path
Fix the logic to find the app bundle in a path by correctly accounting
for paths containing multiple occurrences of `.app`. The new logic will
correctly extract `com.app.Foo.app` from `com.app.Foo.app/com.app.Foo`.

rdar://74666208

Differential revision: https://reviews.llvm.org/D97441
2021-02-24 23:08:42 -08:00
António Afonso 878d82c4f2 Revert "[lldb-vscode] Emit the breakpoint changed event on location resolved"
This reverts commit 1f21d488bd.
2021-02-21 13:08:06 -08:00
António Afonso 1f21d488bd [lldb-vscode] Emit the breakpoint changed event on location resolved
VSCode was not being informed whenever a location had been resolved (after being initated as non-resolved), so even though it was actually resolved, the IDE would show a hollow dot (instead of a red dot) because it didn't know about the change.

Differential Revision: https://reviews.llvm.org/D96680
2021-02-21 09:46:29 -08:00
Pavel Labath 004a264f8c [lldb] Fix shared library directory computation on windows
Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.

When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.

On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.

To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.

To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.

I also strenghten the existing path test to ensure the returned path is
the right one.

Differential Revision: https://reviews.llvm.org/D96779
2021-02-18 15:37:52 +01:00
Jonas Devlieghere 71811048c0 [debugserver] Correctly pass argv[0] to execl
The execl function takes both the executable and argv[0].
2021-02-15 18:42:21 -08:00
Michał Górny bee4d6efe1 [lldb] Rename FreeBSDRemote to FreeBSD (NFC)
Differential Revision: https://reviews.llvm.org/D96557
2021-02-15 13:04:11 +01:00
Michał Górny cd44339856 [lldb] Remove the legacy FreeBSD plugin
The new FreeBSDRemote plugin has reached feature parity with the legacy
plugin, so we can finally remove the latter.  The new plugin will
be renamed to FreeBSD in a separate commit to avoid confusion.

Differential Revision: https://reviews.llvm.org/D96555
2021-02-15 13:04:11 +01:00
Jonas Devlieghere ac1242bce3 [debugserver] Fix more warnings in DNBArchImplARM64 2021-02-05 15:21:24 -08:00
Walter Erquinigo 36496cc299 [lldb-vscode] correctly use Windows macros
@mstorsjo found a mistake that I made when trying to fix some Windows
compilation errors encountered by @stella.stamenova.

I was incorrectly using the LLVM_ON_UNIX macro. In any case, proper use
of

  #if defined(_WIN32)

should be the actual fix.

Differential Revision: https://reviews.llvm.org/D96060
2021-02-04 11:03:33 -08:00
Jonas Devlieghere 5580fa10db [lldb] Fix debugserver-entitlements.plist path 2021-02-03 10:42:36 -08:00
Jonas Devlieghere 39047f6c2e [debugserver] Fix -Wmissing-field-initializers warnings on arm64 2021-02-02 10:29:09 -08:00
Jonas Devlieghere ec6815a72d [debugserver] Fix -Wsign-compare warnings on arm64 2021-02-02 10:23:57 -08:00
Jonas Devlieghere 9a62b7242a [debugserver] Fix -Wunused-function warnings on arm64 2021-02-02 10:20:11 -08:00
Jonas Devlieghere 870a58a758 [debugserver] Fix -Winconsistent-missing-override warnings on arm64 2021-02-02 09:41:18 -08:00
Martin Storsjö 11e74e512d [lldb] Remove a stray semicolon, fixing GCC warnings. NFC. 2021-02-01 13:45:07 +02:00
serge-sans-paille 27f2fe9163 Adapt lldb-instr to d47ee525f9 APi change 2021-01-29 10:58:40 +01:00
Walter Erquinigo 0bca9a7ce2 Fix lldb-vscode builds on Windows targeting POSIX
@stella.stamenova found out that lldb-vscode's Win32 macros were failing
when building on windows targetings POSIX platforms.

I'm changing these macros for LLVM_ON_UNIX, which should be more
accurate.
2021-01-28 09:36:13 -08:00
Walter Erquinigo ab5591e1d8 Fix runInTerminal failures on Windows
stella.stemenova mentioned in https://reviews.llvm.org/D93951 failures on Windows for this test.

I'm fixing the macro definitions and disabling the tests for python
versions lower than 3.7. I'll figure out that actual issue with
python3.6 after the buildbots are fine again.
2021-01-27 13:17:23 -08:00
Walter Erquinigo 1ac36b34db Fix 0f0462cacf
This fails on Windows because std::future<llvm::Error> fail to compile.
Now switching to SBError as a workaround.

Failed buildbot: http://lab.llvm.org:8011/#/builders/83/builds/3021
2021-01-25 14:06:10 -08:00
Walter Erquinigo 0f0462cacf [vscode] Improve runInTerminal and support linux
Depends on D93874.

runInTerminal was using --wait-for, but it was some problems because it uses process polling looking for a single instance of the debuggee:

- it gets to know of the target late, which renders breakpoints in the main function almost impossible
- polling might fail if there are already other processes with the same name
- polling might also fail on some linux machine, as it's implemented with the ps command, and the ps command's args and output are not standard everywhere

As a better way to implement this so that it works well on Darwin and Linux, I'm using now the following process:

- lldb-vscode notices the runInTerminal, so it spawns lldb-vscode with a special flag --launch-target <target>. This flags tells lldb-vscode to wait to be attached and then it execs the target program. I'm using lldb-vscode itself to do this, because it makes finding the launcher program easier. Also no CMAKE INSTALL scripts are needed.
- Besides this, the debugger creates a temporary FIFO file where the launcher program will write its pid to. That way the debugger will be sure of which program to attach.
- Once attach happend, the debugger creates a second temporary file to notify the launcher program that it has been attached, so that it can then exec. I'm using this instead of using a signal or a similar mechanism because I don't want the launcher program to wait indefinitely to be attached in case the debugger crashed. That would pollute the process list with a lot of hanging processes. Instead, I'm setting a 20 seconds timeout (that's an overkill) and the launcher program seeks in intervals the second tepmorary file.

Some notes:
- I preferred not to use sockets because it requires a lot of code and I only need a pid. It would also require a lot of code when windows support is implemented.
- I didn't add Windows support, as I don't have a windows machine, but adding support for it should be easy, as the FIFO file can be implemented with a named pipe, which is standard on Windows and works pretty much the same way.

The existing test which didn't pass on Linux, now passes.

Differential Revision: https://reviews.llvm.org/D93951
2021-01-25 12:30:05 -08:00
Jason Molenda ad25bdcb8e Change static buffer to be BSS instead of DATA in HandlePacket_qSpeedTest
Having this 4MB buffer with a compile-time initialized string forced it
into the DATA section and it took up 4MB of space in the binary, which
accounts for like 80% of debugserver's footprint on disk.  Change it to
BSS and strcpy in the initial value at runtime instead.

<rdar://problem/73503892>
2021-01-22 16:14:24 -08:00
Walter Erquinigo 39239f9b56 [lldb-vscode] improve modules request
lldb-vsdode was communicating the list of modules to the IDE with events, which in practice ended up having some drawbacks
- when debugging large targets, the number of these events were easily 10k, which polluted the messages being transmitted, which caused the following: a harder time debugging the messages, a lag after terminated the process because of these messages being processes (this could easily take several seconds). The latter was specially bad, as users were complaining about it even when they didn't check the modules view.
- these events were rarely used, as users only check the modules view when something is wrong and they try to debug things.

After getting some feedback from users, we realized that it's better to not used events but make this simply a request and is triggered by users whenever they needed.

This diff achieves that and does some small clean up in the existing code.

Differential Revision: https://reviews.llvm.org/D94033
2021-01-21 13:18:50 -08:00
Jonas Devlieghere 999f5da6b3 [debugserver] Fix inverted if block that resulted in us using the private entitlements 2021-01-15 17:41:07 -08:00
Jason Molenda edde2eb1d2 Add unconditional logging to debugserver for launch/attach processes
Debugging app launch/attach failures can be difficult because of
all of the messages logged to the console on a darwin system;
emitting specific messages around critical API calls can make it
easier to narrow the search for the console messages related to
the failure.

<rdar://problem/67220442>

Differential revision: https://reviews.llvm.org/D94357
2021-01-11 22:17:10 -08:00
Jonas Devlieghere 272355128f [debugserver] Various plist changes
- Remove unused plists that were referenced (but unused) by Xcode.
 - Move all debugserver plists unders tools/debugserver/resources.
 - Add the ability to distinguish between com.apple.security.cs.debugger
   and com.apple.private.cs.debugger.

rdar://66082043

Differential revision: https://reviews.llvm.org/D94320
2021-01-08 18:53:08 -08:00
Michał Górny b9bfe8a753 [lldb] [debugserver] Add stN aliases for stmmN for compatibility
Add stN aliases for the FPU (stmmN) registers on MacOSX.  This should
improve compatibility between MacOSX and other platforms, and partially
fix x86*-fp-write tests without having to duplicate them.  Note that
the tests are currently still broken due to ftag incompatibility.

Differential Revision: https://reviews.llvm.org/D91847
2021-01-07 02:10:38 +01:00
Pavel Labath aca4488847 [lldb] Surpress "ingoring result" warning in reproducer_handler 2020-12-27 13:58:05 +01:00
Jonas Devlieghere 5c1c8443eb [lldb] Abstract scoped timer logic behind LLDB_SCOPED_TIMER (NFC)
This patch introduces a LLDB_SCOPED_TIMER macro to hide the needlessly
repetitive creation of scoped timers in LLDB. It's similar to the
LLDB_LOG(F) macro.

Differential revision: https://reviews.llvm.org/D93663
2020-12-22 09:10:27 -08:00
Jordan Rupprecht 869f8363c4 [lldb][NFC] Apply performance-faster-string-find (`str.find("X")` -> `str.find('x')`) 2020-12-16 10:53:18 -08:00
Jonas Devlieghere d6f5e08199 [lldb] Kill the inferior instead of detaching during test suite runs
Kill (rather than detach) form the inferior if debugserver loses its
connection to lldb to prevent zombie processes.

Differential revision: https://reviews.llvm.org/D92908
2020-12-09 18:40:06 -08:00
Jonas Devlieghere ee607ed5c3 [debugserver] Call posix_spawnattr_setarchpref_np throught the fn ptr.
Fourth time is the charm? Of course all of these issues don't show up
when the function is available...
2020-12-05 17:38:42 -08:00
Jonas Devlieghere 13ee00d0c9 [debugserver] Use dlsym for posix_spawnattr_setarchpref_np
The @available check did not work as I thought it did. Use good old
dlsym instead.
2020-12-05 14:06:45 -08:00
Jonas Devlieghere c722096b39 [debugserver] Remove bridgeos availability
I didn't realize that the 'bridgeos' is not part of the public SDK.
2020-12-05 10:18:45 -08:00
Jonas Devlieghere 0db37576c1 [debugserver] Honor the cpu sub type if specified
Use the newly added spawnattr API, posix_spawnattr_setarchpref_np, to
select a slice preferences per cpu and subcpu types, instead of just cpu
with posix_spawnattr_setarchpref_np.

rdar://16094957

Differential revision: https://reviews.llvm.org/D92712
2020-12-04 20:37:41 -08:00
David Spickett a7f8d96b16 [lldb] Use llvm::Optional for port in LaunchGDBServer
Previously we used UINT16_MAX to mean no port/no specifc
port. This leads to confusion because 65535 is a valid
port number.

Instead use an optional. If you want a specific port call
LaunchGDBServer as normal, otherwise pass an empty optional
and it will be set to the port that gets chosen.
(or left empty in the case where we fail to find a port)

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D92035
2020-11-30 11:20:39 +00:00
David Spickett 98e87f76d0 [lldb] Error when there are no ports to launch a gdbserver on
Previously if you did:
$ lldb-server platform --server <...> --min-gdbserver-port 12346
--max-gdbserver-port 12347
(meaning only use port 12346 for gdbservers)

Then tried to launch two gdbservers on the same connection,
the second one would return port 65535. Which is a real port
number but it actually means lldb-server didn't find one it was
allowed to use.

send packet: $qLaunchGDBServer;<...>
read packet: $pid:1919;port:12346;#c0
<...>
send packet: $qLaunchGDBServer;<...>
read packet: $pid:1927;port:65535;#c7

This situation should be an error even if port 65535 does happen
to be available on the current machine.

To fix this make PortMap it's own class within
GDBRemoteCommunicationServerPlatform.

This almost the same as the old typedef but for
GetNextAvailablePort() returning an llvm::Expected.
This means we have to handle not finding a port,
by returning an error packet.

Also add unit tests for this new PortMap class.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D91634
2020-11-30 10:19:14 +00:00
Alessandro Arzilli 27012c0f75 [debugserver] Add option to propagate SIGSEGV to target process
Adds a command line option that makes debugserver propagate the SIGSEGV
signal to the target process.

Motivation: I'm one of the maintainers of Delve [1] a debugger for Go.
We use debugserver as our backend on macOS and one of the most often
reported bugs is that, on macOS, we don't propagate SIGSEGV back to the
target process [2]. Sometimes some programs will actually cause a
SIGSEGV, by design, and then handle it. Those programs can not be
debugged at all.

Since catching signals isn't very important for a Go debugger I'd much
rather have a command line option in debugserver that causes it to let
SIGSEGV go directly to the target process.

[1] https://github.com/go-delve/delve/
[2] https://github.com/go-delve/delve/issues/852

Differential revision: https://reviews.llvm.org/D89315
2020-11-17 09:27:52 -08:00
Jason Molenda 92b036dea2 debugserver should advance pc past builtin_debugtrap insn
On x86_64, when you hit a __builtin_debugtrap instruction, you
can continue past this in the debugger.  This patch has debugserver
recognize the specific instruction used for __builtin_debugtrap
and advance the pc past it, so that the user can continue execution
once they've hit one of these.

In the patch discussion, we were in agreement that it would be better
to have this knowledge up in lldb instead of depending on each
stub rewriting the pc behind the debugger's back, but that's a
larger scale change for another day.

<rdar://problem/65521634>
Differential revision: https://reviews.llvm.org/D91238
2020-11-12 23:31:14 -08:00
Jonas Devlieghere 0ca90eb335 [lldb] Don't use ::exit but instead return from the driver loop (NFC)
This fixes a reproducer test failure that was caused by the undefined
order in which global destructors run. More concretely, the static
instance of the RealFileSystem had been destroyed before we finalized
the reproducer, which uses it to copy files into the reproducer. By
exiting normally, we call SBDebugger::Terminate and finalize the
reproducer before any static dtors are run.
2020-11-09 16:47:30 -08:00
Jonas Devlieghere 6ac12b5b6c [lldb] Destory the debugger in the Driver dtor (NFC) 2020-11-09 16:47:30 -08:00
Jonas Devlieghere 73811d32c7 [lldb] Move copying of files into reproducer out of process
For performance reasons the reproducers don't copy the files captured by
the file collector eagerly, but wait until the reproducer needs to be
generated.

This is a problematic when LLDB crashes and we have to do all this
signal-unsafe work in the signal handler. This patch uses a similar
trick to clang, which has the driver invoke a new cc1 instance to do all
this work out-of-process.

This patch moves the writing of the mapping file as well as copying over
the reproducers into a separate process spawned when lldb crashes.

Differential revision: https://reviews.llvm.org/D89600
2020-10-23 12:33:54 -07:00
Pavel Labath d900b755ed [lldb] Fix windows build for fa5fa63fd1 2020-10-21 17:51:11 +02:00
Pavel Labath fa5fa63fd1 [lldb] Port lldb gdb-server to libOption
The existing help text was very terse and was missing several important
options. In the new version, I add a short description of each option
and a slightly longer description of the tool as a whole.

The new option list does not include undocumented no-op options:
--debug and --verbose. It also does not include undocumented short
aliases for long options, with two exceptions: -h, because it's
well-known; and -S (--setsid), as it's used in one test. Using these
options will now produce an error. I believe that is acceptable as users
aren't generally invoking lldb-server directly, and the only way to
learn about the short aliases was by looking at the source.

Differential Revision: https://reviews.llvm.org/D89477
2020-10-21 16:16:18 +02:00
Jason Molenda b19856881c Fix typeo in attach failed error message.
<rdar://problem/70296751>
2020-10-14 23:31:24 -07:00
Jason Molenda 7d67c06391 Remove unused build configurations from debugserver xcode project
the xcode project file for debugserver exists only to make my
life easier when I'm working only on debugserver and don't need
to build the rest of llvm/lldb.  It had many build configurations
to reflect our old lldb xcode project file, which is long gone.
Removing them to simplify the configurations.

Specifically dropping CustomSwift-Debug, DebugClang, DebugPresubmission,
CustomSwift-Release, BuildAndIntegration.  Keeping Debug & Release.
2020-10-13 16:39:30 -07:00
Jason Molenda e763709d14 Add a new launch flag option for watchos, WatchComplicationLaunch.
Link against CarouselServices on watchos, recognize the
WatchComplicationLaunch launch flag option when that framework
is available.

<rdar://problem/62473967>, <rdar://problem/61230088>
2020-10-13 16:28:16 -07:00
Michał Górny 1a600266c3 [lldb] Initial version of FreeBSD remote process plugin
Add a new FreeBSD Process plugin using client/server model.  This plugin
is based on the one used by NetBSD.  It currently supports a subset
of functionality for amd64.  It is automatically used when spawning
lldb-server.  It can also be used by lldb client by setting
FREEBSD_REMOTE_PLUGIN environment variable (to any value).

The code is capable of debugging simple single-threaded programs.  It
supports general purpose, debug and FPU registers (up to XMM) of amd64,
basic signalling, software breakpoints.

Adding the support for the plugin involves removing some dead code
from FreeBSDPlatform plugin (that was not ever used because
CanDebugProcess() returned false), and replacing it with appropriate
code from NetBSD platform support.

Differential Revision: https://reviews.llvm.org/D88796
2020-10-08 16:03:00 +02:00
Jordan Rupprecht ad865d9d10 [lldb-vscode] Allow an empty 'breakpoints' field to clear breakpoints.
Per the DAP spec for SetBreakpoints [1], the way to clear breakpoints is: `To clear all breakpoint for a source, specify an empty array.`

However, leaving the breakpoints field unset is also a well formed request (note the `breakpoints?:` in the `SetBreakpointsArguments` definition). If it's unset, we have a couple choices:

1. Crash (current behavior)
2. Clear breakpoints
3. Return an error response that the breakpoints field is missing.

I propose we do (2) instead of (1), and treat an unset breakpoints field the same as an empty breakpoints field.

[1] https://microsoft.github.io/debug-adapter-protocol/specification#Requests_SetBreakpoints

Reviewed By: wallace, labath

Differential Revision: https://reviews.llvm.org/D88513
2020-09-30 11:32:06 -07:00