-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Debugging vere on macOS is quite something because as soon as we get a single SIGSEGV lldb enters an infinite loop. The cause of that is a lldb bug and the root cause of that is a macos kernel bug. Here we implement the same workaround that Go does to make the debugger work. https://bugs.llvm.org/show_bug.cgi?id=22868#c1
- Loading branch information
Showing
6 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "log.h" | ||
|
||
#include <mach/mach.h> | ||
#include <mach/mach_error.h> | ||
#include <mach/exception.h> | ||
#include <mach/task.h> | ||
|
||
|
||
// lldb does not listen to BSD signals, it only listens to Mach exceptions. | ||
// The Mach exception EXC_BAD_ACCESS corresponds to SIGSEGV, but lldb has | ||
// problems converting between them because of a longstanding macOS kernel bug. | ||
// This means that without this workaround we cannot debug our binaries with | ||
// lldb. The first segfault we hit causes an infinite loop in lldb no matter | ||
// how many times you try to continue. This workaround is implemented in projects | ||
// such as the Go runtime. | ||
// See https://bugs.llvm.org/show_bug.cgi?id=22868#c1 for more details. | ||
|
||
void darwin_register_mach_exception_handler() { | ||
kern_return_t kr = task_set_exception_ports( | ||
mach_task_self(), | ||
EXC_MASK_BAD_ACCESS, // SIGSEGV | ||
MACH_PORT_NULL, | ||
EXCEPTION_STATE_IDENTITY, | ||
MACHINE_THREAD_STATE); | ||
if ( KERN_SUCCESS != kr) { | ||
u3l_log("mach: unable to register exception handler"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters