summaryrefslogtreecommitdiff
path: root/lldb/tools/debugserver/source/MacOSX/MachException.cpp
AgeCommit message (Collapse)Author
2025-04-28[debugserver] Remove PThreadMutex (NFC) (#137555)Jonas Devlieghere
Now that all uses of PThreadMutex have been migrated to their C++ equivalent, this PR removes PThreadMutex itself.
2025-03-21[lldb][debugserver][MacOSX] Work around sanitizer misaligned address errors ↵Michael Buch
when reading exception data (#132193) We've been dealing with UBSAN issues around this code for some time now (see `9c36859b33b386fbfa9599646de1e2ae01158180` and `1a2122e9e9d1d495fdf337a4a9445b61ca56df6f`). On recent macOS versions, a UBSAN-enabled debugserver will crash when performing a `memcpy` of the input `mach_exception_data_t`. The pointer to the beginning of the exception data may not be aligned on a doubleword boundary, leading to UBSAN failures such as: ``` $ ./bin/debugserver 0.0.0.0:5555 /Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/build-sanitized-release/tools/lldb/test/Shell/Recognizer/Output/verbose_trap.test.tmp.out /Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/lldb/tools/debugserver/source/MacOSX/MachException.cpp:35:12: runtime error: store to misaligned address 0x00016ddfa634 for type 'mach_exception_data_type_t *' (aka 'long long *'), which requires 8 byte alignment 0x00016ddfa634: note: pointer points here 02 00 00 00 03 00 01 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/lldb/tools/debugserver/source/MacOSX/MachException.cpp:35:12 ``` Work around these failures by pretending the input data is a `char*` buffer. Drive-by changes: * I factored out some duplicated code into a static `AppendExceptionData` and made the types consistent --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2024-05-04Add clarifying parenthesis around non-trivial conditions in ternary ↵luolent
expressions. (#90391) Fixes [#85868](https://github.com/llvm/llvm-project/issues/85868) Parenthesis are added as requested on ternary operators with non trivial conditions. I used this [precedence table](https://en.cppreference.com/w/cpp/language/operator_precedence) for reference, to make sure we get the expected behavior on each change.
2023-08-18Align mach exception data before accessing itJason Molenda
The mach exception data may not be doubleword aligned when we receive it. We use memcpy to align it later in this method when we save the data, but for printing the value at the top, we need to do the same or ubsan can trigger when LOG_EXCEPTIONS is enabled in debugserver. Differential Revision: https://reviews.llvm.org/D158312
2023-08-18Revert "Align mach exception data before accessing it"Jason Molenda
This reverts commit b10c2f846d936a98eecfcef1a90a754522282285. Need to add the phabracator line to the message.
2023-08-18Align mach exception data before accessing itJason Molenda
The mach exception data may not be doubleword aligned when we receive it. We use memcpy to align it later in this method when we save the data, but for printing the value at the top, we need to do the same or ubsan can trigger when LOG_EXCEPTIONS is enabled in debugserver.
2023-04-12AArch64 debugserver parse ESR register for watchpointsJason Molenda
Have debugserver parse the watchpoint flags out of the exception syndrome register when we get a watchpoint mach exception. Relay those fields up to lldb in the stop reply packet, if the watchpoint number was reported by the hardware, use the address from that as the watchpoint address. Change how watchpoints are reported to lldb from using the mach exception data, to using the `reason:watchpoint` and `description:asciihex` method that lldb-server uses, which can relay the actual trap address as well as the address of a watched memory region responsible for the trap, so lldb can step past it. Have debugserver look for the nearest watchpoint that it has set when it gets a watchpoint trap, so accesses that are reported as starting before the watched region are associated with the correct watchpoint to lldb. Add a test case for this specific issue. Differential Revision: https://reviews.llvm.org/D147820 rdar://83996471
2022-05-18Add a darwin platform setting to specify which exceptions debugserverJim Ingham
should not receive as exceptions (some will get converted to BSD signals instead). This is really the only stable way to ensure that a Mach exception gets converted to it's equivalent BSD signal. For programs that rely on BSD signal handlers, this has to happen or you can't even get the program to invoke the signal handler when under the debugger. This builds on a previous solution to this problem which required you start debugserver with the -U flag. This was not very discoverable and required lldb be the one to launch debugserver, which is not always the case. Differential Revision: https://reviews.llvm.org/D125434
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2019-08-07Upstream a few small Apple changes to debugserver - arm64_32, CatalystJason Molenda
Adrian's changes to support Catalyst processes and my changes to support debugserver running on an arm64_32 device (Apple Watch Series 4, which uses an IPL32 model on arm64 cpus). llvm-svn: 368118
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-10Enable listening for EXC_RESOURCE events, and format machJason Molenda
event as a thread stop reason if we receive one, using some macros to decode the payload. Patch originally written by Fred Riss, with a few small changes by myself. Writing a test for this is a little tricky because the mach exception data interpretation relies on header macros or function calls - it may change over time and writing a gdb_remote_client test for this would break as older encoding interpretation is changed. I'll tak with Fred about this more, but neither of us has been thrilled with the kind of tests we could write for it. <rdar://problem/13097323>, <rdar://problem/40144456> llvm-svn: 346571
2018-03-29Prevent double release of mach portsFrederic Riss
Summary: When a MIG routine returns KERN_FAILURE, the demux function will release any OOL resources like ports. In this case, task_port and thread_port will be released twice, potentially resulting in use after free of the ports. I don't think we can test this in any useful way rdar://problem/37331387 Reviewers: jasonmolenda Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D45011 llvm-svn: 328761
2017-12-08[MachException] Avoid alignment UB, NFCVedant Kumar
Fix alignment UB in some Mach exception-handling logic. This lets us build lldb and debugserver with UBSan in trapping mode, and get further along in the testing process before a trap is encountered. rdar://35923991 llvm-svn: 320127
2017-12-08Remove extant references to g_message_mutex, NFCVedant Kumar
Thanks to Jim Ingham for providing the explanation! llvm-svn: 320126
2017-05-12Rename Error -> Status.Zachary Turner
This renames the LLDB error class to Status, as discussed on the lldb-dev mailing list. A change of this magnitude cannot easily be done without find and replace, but that has potential to catch unwanted occurrences of common strings such as "Error". Every effort was made to find all the obvious things such as the word "Error" appearing in a string, etc, but it's possible there are still some lingering occurences left around. Hopefully nothing too serious. llvm-svn: 302872
2017-04-03Back out temporary masking of EXC_SYSCALL mach exceptions.Jason Molenda
<rdar://problem/31359720> llvm-svn: 299345
2017-03-30Mask out EXC_SYSCALL exceptions as well.Jason Molenda
<rdar://problem/31335814> llvm-svn: 299040
2016-09-28Add the ability for the task port to change when a process execs.Greg Clayton
<rdar://problem/28476369> llvm-svn: 282632
2016-09-06*** This commit represents a complete reformatting of the LLDB source codeKate Stone
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
2016-05-12Don't crash when a process' task port goes bad.Greg Clayton
<rdar://problem/26256049> llvm-svn: 269373
2015-07-17More packet performance improvements. Greg Clayton
Changed the "jthreads" key/value in the stop reply packets to be "jstopinfo". This JSON only contains threads with valid stop reasons and allows us not to have to ask about other threads via qThreadStopInfo when we are stepping. The "jstopinfo" only gets sent if there are more than one thread since the stop reply packet contains all the info needed for a single thread. Added a Process::WillPublicStop() in case process subclasses want to do any extra gathering for public stops. For ProcessGDBRemote, we end up sending a jThreadsInfo packet to gather all expedited registers, expedited memory and MacOSX queue information. We only do this for public stops to minimize the packets we send when we have multiple private stops. Multiple private stops happen when a source level single step, step into or step out run the process multiple times while implementing the stepping, and none of these private stops make it out to the UI via notifications because they are private stops. llvm-svn: 242593
2013-11-13<rdar://problem/14814689>Greg Clayton
Add a log message to the console that will display the error code when we fail to reply to a mach message. llvm-svn: 194623
2013-02-16Get rid of a warning.Greg Clayton
llvm-svn: 175337
2013-01-24Don't listen for EXC_RESOURCE exceptions, those should really be handled by ↵Jim Ingham
the system handler. Also put in string translations for a couple of exceptions we were missing. llvm-svn: 173390
2012-09-18Stop using the "%z" size_t modifier and cast all size_t values to uint64_t. ↵Greg Clayton
Some platforms don't support this modification. llvm-svn: 164148
2012-07-17Ran the static analyzer on the codebase and found a few things.Greg Clayton
llvm-svn: 160338
2012-03-08<rdar://problem/11007934> Greg Clayton
On darwin, if child process of process being debugged dies due to mach exception, the debugged process will die. debugserver now only handles the mach exceptions for the task being debugged. llvm-svn: 152291
2012-03-06<rdar://problem/10986692>Greg Clayton
Safeguard against building on next OS and run on current OS. llvm-svn: 152077
2012-03-01<rdar://problem/10963899>Greg Clayton
Allow debugserver to be built on a newer kernel and still allow debugging on older kernels. llvm-svn: 151827
2011-10-28Enabled the "printf" attribute on all debugserver logging functions and fixed Greg Clayton
the ensuing mayhem. llvm-svn: 143244
2010-06-08Initial checkin of lldb code from internal Apple repo.Chris Lattner
llvm-svn: 105619