Commit Graph

782 Commits

Author SHA1 Message Date
Jason Molenda 2b8b783b1a Quote error string from qLaunchSuccess
If the error message from qLaunchSucess included a gdb RSP
metacharacter, it could crash lldb.  Apply the binary
escaping to the string before sending it to lldb; lldb
promiscuously applies the binary escaping protocol on
packets it receives.

Also fix a small bug in cstring_to_asciihex_string where
a high bit character (eg utf-8 chars) would not be
quoted correctly due to signed char fun.

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

rdar://problem/62873581
2020-05-11 20:05:57 -07:00
Fred Riss c9537b9cc8 [lldb/debugserver] Include TargetConditionals.h where needed
MachProcess.mm uses a TARGET_OS_ macro without directly including
TargetConditionals.h. This currently works as we get the header
as an indirect dependency, but might not in the future.

I just spent some time investigating an internal regression
caused by a similar issue, so I audited the codebase for such
cases.
2020-05-09 10:12:17 -07:00
Jason Molenda 2ea7187ab9 Add a new lockdownd plist for launching posix processes
Similar to
com.apple.debugserver.plist & com.apple.debugserver.internal.plist
com.apple.debugserver.applist.plist & com.apple.debugserver.applist.internal.plist
add a variant of the posix plist.

<rdar://problem/62995567>
2020-05-07 18:53:51 -07:00
Jason Molenda 5034102b24 Log the NSError str and object description on app launch fail
Update CallBoardSystemServiceOpenApplication to unconditionally log
the NSError's localizedDescription to Console on app launch failure
(as it was already doing), and also to log the NSError object's
full description to the console, which may contain additional nested
error messages.  I'm experimenting to find cases where we will get
more detailed information from app launch failures and will start
by logging both to the console.

<rdar://problem/62709160>
2020-05-05 15:51:50 -07:00
Raphael Isemann ff5264f0c6 [lldb][cmake] Move the remove_module_flags call to the right place in debugserver's CMakeLists
This code should always be executed, not just when building the debugserver
on its own. Fixes the modules build when building LLVM+LLDB together.
2020-04-27 16:04:19 +02:00
Jason Molenda 7fa342bd2a Remove attach-failed-due-to-SIP checks which were not working
The SIP debugserver was calling in attach_failed_due_to_sip
haven't worked for a while; remove them.  To check this
properly we'd need debugsever to call out to codesign(1) to
inspect the entitlements, or the equivalant API,
and I'm not interested in adding that at this point.  SIP
is has been the default on macOS for a couple of releases
and it's expected behavior now.

<rdar://problem/59198052>
2020-04-16 15:22:14 -07:00
Davide Italiano 6f9ea26002 [debugserver] Get rid of `else` after `return`. NFC. 2020-04-06 13:35:48 -07:00
Kazuaki Ishizaki e9264b746b [lldb] NFC: Fix trivial typo in comments, documents, and messages
Differential Revision: https://reviews.llvm.org/D77460
2020-04-07 01:06:16 +09:00
Davide Italiano 64799fbebd [debugserver/ARM64] Make sure watchpoints hit are attributed correctly.
This didn't happen for arm64 if you have watches for variables
that are contigous in memory.

<rdar://problem/55135006>
2020-03-31 15:56:20 -07:00
Jonas Devlieghere 90308a4da1 [debugserver] Implement hardware breakpoints for ARM64
Add support for hardware breakpoints on ARM64.

Differential revision: https://reviews.llvm.org/D76411
2020-03-19 11:55:48 -07:00
Jason Molenda 5d881dd8a8 Update so debugserver can be built on macos again with xcodebuild. 2020-03-18 21:46:20 -07:00
Jason Molenda 8aa07f81b8 Remove the old SecTaskAccess entry from debugserver's plist
<rdar://problem/60230324>
2020-03-16 21:54:32 -07:00
Raphael Isemann 4e7c686e46 [lldb] Never compile the debugserver with Clang module flags
Summary:
Compiling ObjC++ with Clang modules is usually not working well and compiling
the small debugserver with modules is not worth the trouble.

Reviewers: JDevlieghere

Reviewed By: JDevlieghere

Subscribers: mgorny, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D74891
2020-03-06 17:26:39 -08:00
Adrian Prantl 000847f8be Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

(Patch re-applied with bugfix this time).

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 10:16:47 -08:00
Adrian Prantl 4ebe9b498d Revert "Correctly identify iOS simulator processes in debugserver."
This reverts commit 59d816d884.

It broke TestGDBRemoteClient.
2020-03-06 10:16:47 -08:00
Adrian Prantl 58c506d8e8 Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

(Patch re-applied without modifications, the bot failure was unrelated).

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 09:59:30 -08:00
Adrian Prantl 66a6fa631e Revert "Correctly identify iOS simulator processes in debugserver."
This reverts commit 59d816d884.

It broke TestGDBRemoteClient.
2020-03-06 09:52:20 -08:00
Adrian Prantl 59d816d884 Correctly identify iOS simulator processes in debugserver.
Starting with iOS 13 simulator binaries are identified with an
explicit platform in the new LC_BUILD_VERSION load command.

On older deployment targets using the LC_VERSION_MIN load commands,
this patch detects when an ios process runs on a macOS host and
updates the target triple with the "simulator" environment
accordingly.

This is part of https://bugs.swift.org/browse/SR-11971

rdar://problem/58438125

Differential Revision: https://reviews.llvm.org/D75696
2020-03-06 09:42:05 -08:00
Jim Ingham 3cd13c4624 Fix a race between lldb's packet timeout and the profile thread's usleep.
The debugserver profile thread used to suspend itself between samples with
a usleep.  When you detach or kill, MachProcess::Clear would delay replying
to the incoming packet until pthread_join of the profile thread returned.
If you are unlucky or the suspend delay is long, it could take longer than
the packet timeout for pthread_join to return.  Then you would get an error
about detach not succeeding from lldb - even though in fact the detach was
successful...

I replaced the usleep with PThreadEvents entity.  Then we just call a timed
WaitForEventBits, and when debugserver wants to stop the profile thread, it
can set the event bit, and the sleep will exit immediately.

Differential Revision: https://reviews.llvm.org/D75004
2020-02-25 11:17:08 -08:00
Jonas Devlieghere cdc514e4c6 [lldb] Update header guards to be consistent and compliant with LLVM (NFC)
LLDB has a few different styles of header guards and they're not very
consistent because things get moved around or copy/pasted. This patch
unifies the header guards across LLDB and converts everything to match
LLVM's style.

Differential revision: https://reviews.llvm.org/D74743
2020-02-17 23:15:40 -08:00
Jason Molenda f9fdd1172c Rewrite default "could not attach" msg to point to hints
about where more information can be found about why it
may have failed.
<rdar://problem/59277928>
2020-02-11 16:18:49 -08:00
Jason Molenda 9ed9742ec0 Only perform the login_session_has_gui_access on macOS 2020-02-10 18:16:31 -08:00
Vedant Kumar eaeb5610ce debugserver: Rely on mig architectures being specified externally
Look up the -arch flags to pass to the mig invocation from an
optionally-defined MIG_ARCHS variable. We can't use CMAKE_OSX_ARCHS
because the {i,tv,watch}OS builds don't use this mechanism to achieve
fat builds (they build each slice separately & then lipo them together).

This supercedes the mig -arch/-isysroot fix from
510758dae2.
2020-02-10 10:13:05 -08:00
Jason Molenda f60de4cdf7 Except, get the TARGET_OS_OSX check correct. 2020-02-06 20:28:40 -08:00
Jason Molenda e2fa760cdd Fix my use of the TARGET_OS_OSX TargetConditional. 2020-02-06 20:28:28 -08:00
Jason Molenda 8eb9b67bda Add final description of why attach failed with poss error string. 2020-02-06 17:28:49 -08:00
Jason Molenda f5cdfb34cd Detect attach fail in debugserver due to non-interactive
debug session.
2020-02-06 16:16:01 -08:00
Jason Molenda ccf900fc93 Two more small fixes for debugserver attach failure messaging.
The developer mode check is now working.

Add another check for user id mismatch, e.g. a regular user
trying to attach to something running as root, and describe
the problem for the user.
2020-02-05 19:24:38 -08:00
Jonas Devlieghere fefff97032 [lldb/debugserver] Link against Security 2020-02-05 14:52:08 -08:00
Jason Molenda 843a0f9771 Enhance debugserver's err reporting on attach fails
Explicitly check for a request to attach to a pid that doesn't
exist, to attach to a pid that is already being debugged, unify the
SIP process check, and an attempt at checking if developer mode is
enabled on the system (which isn't working in debugserver, for some
reason; I can't get the authorization record which should be an
unprivileged operation and works in a standalone program I wrote).

I'll debug the developer mode check later, but I wanted to land it
along with everything else; right now it will claim that developer
mode is always enabled so it's harmless to include as-is.
2020-02-04 19:46:55 -08:00
Jonas Devlieghere 96f3ea0d21 [lldb/debugserver] Implement hardware breakpoints for x86_64 and i386
This implements hardware breakpoints for x86_64 and i386 in debugserver.
It's based on Pedro's patch sent to lldb-commits [1] although most of it
is the same as the existing hardware watchpoint implementation.

[1] http://lists.llvm.org/pipermail/lldb-commits/Week-of-Mon-20200113/060327.html

Differential revision: https://reviews.llvm.org/D72985
2020-01-24 15:07:31 -08:00
Jonas Devlieghere 9902c8e3c6 [lldb/debugserver] Unify the breakpoint/watchpoint interface (NFCI)
Unify the interface for enabling and disabling breakpoints with their
watchpoint counterpart. This allows both to go through
DoHardwareBreakpointAction.

Differential revision: https://reviews.llvm.org/D72981
2020-01-24 15:07:31 -08:00
Jason Molenda 83a131b276 Fix an over-suspend bug with LaunchInNewTerminalWithAppleScript sessions
When launching an inferior in a new terminal window via AppleScript
and the darwin-debug helper program, we could often end up with the
inferior process having a too-high suspend count, and it would never
resume execution.

lldb tries to wait until darwin-debug has finished its work and has
launched the inferior (WaitForProcessToSIGSTOP) but this wasn't
working correctly - and cannot be made to work.

This patch removes WaitForProcessToSIGSTOP, adds a special tiny
segment to the darwin-debug executable so it can be identified as
that binary (ExecExtraSuspend), and adds code to debugserver to
detect this segment.  When debugserver sees this segment, it notes
that the next exec will be done with a launch-suspended flag.  When
the next exec happens, debugserver forces an extra task_resume when
we resume the inferior.

An alternative approach would be if lldb could detect when the
inferior has been launched by darwin-debug unambiguously; monitoring
when the unix socket between darwin-debug and lldb was closed would
have been a reasonable way to do this too.

<rdar://problem/29760580>

Differential Revision: https://reviews.llvm.org/D72963
2020-01-21 14:55:46 -08:00
Vedant Kumar 441aebc523 [debugserver] Delete stale code referencing ppc 2020-01-21 11:04:04 -08:00
Vedant Kumar 9aba2ced34 [debugserver] Delete macOS/PPC debug server implementation
macOS/PPC support was dropped in 10.6 (Snow Leopard).

Differential Revision: https://reviews.llvm.org/D69524
2020-01-21 10:59:38 -08:00
Jonas Devlieghere 2981eceec3 [debugserver] Share code between Enable/DisableHardwareWatchpoint (NFC)
This extract the common functionality of enabling and disabling hardware
watchpoints into a single function.

Differential revision: https://reviews.llvm.org/D72971
2020-01-18 11:36:56 -08:00
Vedant Kumar 510758dae2 debugserver: Pass -arch flags to mig invocation as needed
Specify -isysroot and any necessary -arch flags in the `mig` invocation
when CMAKE_OSX_ARCHITECTURES is set (needed for the bridgeOS build).
2020-01-17 13:11:54 -08:00
Vedant Kumar 1e89fb947e debugserver: Cut dependency on intrinsics_gen
debugserver does not depend on intrinsics_gen or on llvm.
2020-01-15 17:20:10 -08:00
Jason Molenda d44a074317 Save more descriptive error msg from FBS/BKS, relay it up to lldb.
When lldb requests an app launch through FrontBoard/BackBoard,
we get back an NSError object if there was a problem with an
integer error code and a descriptive text string.  debugserver
would log the descriptive text string to the console, but it
would only save the error code value, ask for the
much-less-specific name of that error code, and send that very
generic error word back to lldb.

This patch saves the longer description of the failure when
available, and sends that to lldb.  If unavailable, it falls
back to sending up the generic description of the error code
as it was doing before.

This only impacts the iOS on-device debugserver.

<rdar://problem/49953304>
2020-01-08 18:47:35 -08:00
Jason Molenda 5e2f4dc37b Rewrite comment about what watchpoints Aarch64 supports. 2020-01-07 16:13:23 -08:00
Raphael Isemann 65fdb34219 [lldb][NFC] Use static_cast instead of reinterpret_cast where possible
Summary: There are a few places in LLDB where we do a `reinterpret_cast` for conversions that we could also do with `static_cast`. This patch moves all this code to `static_cast`.

Reviewers: shafik, JDevlieghere, labath

Reviewed By: labath

Subscribers: arphaman, usaxena95, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D72161
2020-01-07 13:03:56 +01:00
Jason Molenda e11df58580 Upstream debugserver arm64e support.
The changes are minor; primarily debugserver needs to go through
accessor functions/macros when changing pc/fp/sp/lr, and debugserver
needs to clear any existing pointer auth bits from values in two
cases.  debugserver can fetch the number of bits used for addressing
from a sysctl, and will include that in the qHostInfo reply.  Update
qHostInfo documentation to document it.
2019-12-04 15:20:56 -08:00
Vedant Kumar af331cbe14 [debugserver] Set arch based on TARGET_TRIPLE
Use TARGET_TRIPLE instead of LLVM_DEFAULT_TARGET_TRIPLE, as the latter
isn't exported by LLVMConfig.cmake, which means arch detection fails if
lldb is built separately from llvm.
2019-11-20 12:12:47 -08:00
Alex Cameron 10b8514343 [lldb] Fix JSON parser to allow empty arrays
Summary:
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=39405
```
alexc@kitty:~/work/wiredtiger/build_posix$ cat breakpoint.json
[{"Breakpoint" : {"BKPTOptions" : {"AutoContinue" : false,"ConditionText" : "","EnabledState" : true,"IgnoreCount" : 0,"OneShotState" : false},"BKPTResolver" : {"Options" : {"NameMask" : [56],"Offset" : 0,"SkipPrologue" : true,"SymbolNames" : ["__wt_btcur_search"]},"Type" : "SymbolName"},"Hardware" : false,"SearchFilter" : {"Options" : {},"Type" : "Unconstrained","Foo" : []}}}]
```
**Before**
```
(lldb) breakpoint read --file breakpoint.json
error: Invalid JSON from input file: /home/alexc/work/wiredtiger/build_posix/breakpoint.json.
```
**After**
```
(lldb) breakpoint read --file breakpoint.json
New breakpoints:
Breakpoint 1: where = libwiredtiger-3.2.2.so`__wt_btcur_search + 15 at bt_cursor.c:522:5, address = 0x00007ffff576ab2f
```

Reviewers: xbolva00, davide, labath

Reviewed By: davide, labath

Subscribers: mgorny, jingham, labath, davide, JDevlieghere, lldb-commits

Tags: #llvm, #lldb

Differential Revision: https://reviews.llvm.org/D68179
2019-11-18 15:12:55 +01:00
Haibo Huang 77a60f0df6 [lldb] Record framework build path and use it everywhere
This avoids config time dependencies on liblldb. And enables other refactoring.
2019-11-06 14:05:35 -08:00
Saleem Abdulrasool 5e029c4cfd DebugServer: be more lenient about the target triple
When building standalone, `LLVM_DEFAULT_TARGET_TRIPLE` may be undefined.
Matching against an empty string does not work as desired in CMake, so,
fallback to the old behaviour, defaulting `LLDB_DEBUGSERVER_ARCH` to
`CMAKE_OSX_ARCHITECTURES`.
2019-10-30 12:08:29 -07:00
Saleem Abdulrasool 55eec2ba96 build: workaround stale caches (NFC)
`LLVM_DEFAULT_TARGET_TRIPLE` is a cached variable, which means that it
may actually be unset.  Furthermore, in standalone builds, the variable
may be fully undefined.  Apply the regular expression over the empty
string in such a case.  This should improve the state of the green
dragon bot.
2019-10-29 08:20:58 -07:00
Vedant Kumar 82d3ba87d0 [debugserver] Detect arch from LLVM_DEFAULT_TARGET_TRIPLE
The debugserver build needs to conditionally include files depending on the
target architecture.

Switch on the architecture specified by LLVM_DEFAULT_TARGET_TRIPLE, as
the llvm and swift build systems use this variable to identify the
target (the latter, indirectly, through LLVM_HOST_TRIPLE).

It would be possible to switch on CMAKE_OSX_ARCHITECTURES, but the swift
build does not provide it, preferring instead to pass arch-specific
CFLAGS etc explicitly. Switching on LLVM_HOST_TRIPLE is also an option,
but it breaks down when cross-compiling.

Differential Revision: https://reviews.llvm.org/D69523
2019-10-28 15:34:39 -07:00
Jason Molenda 7dd7a36075 Add arm64_32 support to lldb, an ILP32 codegen
that runs on arm64 ISA targets, specifically 
Apple watches.


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

llvm-svn: 375032
2019-10-16 19:14:49 +00:00
Jason Molenda d6e9e99cec Change debugserver to use the brk #0 for breakpoints.
debugserver had been using an instruction that would work
for armv7 or aarch64 processes, but we don't have armv7 code
running on arm64 devices any more so this is unnecessary.

<rdar://problem/56133118>

llvm-svn: 374264
2019-10-10 00:12:05 +00:00