Skip to content

Commit

Permalink
Add back workaround for LLDB debugging on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Mar 14, 2022
1 parent 059b222 commit e002b7b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum-iterator = "0.7.0"
corosensei = { version = "0.1.2" }
scopeguard = "1.1.0"

[target.'cfg(target_vendor = "apple")'.dependencies]
mach = "0.3.2"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] }

Expand Down
37 changes: 37 additions & 0 deletions lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,43 @@ cfg_if::cfg_if! {
if cfg!(target_arch = "arm") || cfg!(target_vendor = "apple") {
register(&mut PREV_SIGBUS, libc::SIGBUS);
}

// This is necessary to support debugging under LLDB on Darwin.
// For more details see https://github.com/mono/mono/commit/8e75f5a28e6537e56ad70bf870b86e22539c2fb7
#[cfg(target_vendor = "apple")]
{
use mach::exception_types::*;
use mach::kern_return::*;
use mach::port::*;
use mach::thread_status::*;
use mach::traps::*;
use mach::mach_types::*;

extern "C" {
fn task_set_exception_ports(
task: task_t,
exception_mask: exception_mask_t,
new_port: mach_port_t,
behavior: exception_behavior_t,
new_flavor: thread_state_flavor_t,
) -> kern_return_t;
}

#[allow(non_snake_case)]
#[cfg(target_arch = "x86_64")]
let MACHINE_THREAD_STATE = x86_THREAD_STATE64;
#[allow(non_snake_case)]
#[cfg(target_arch = "aarch64")]
let MACHINE_THREAD_STATE = 6;

task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC,
MACH_PORT_NULL,
EXCEPTION_STATE_IDENTITY as exception_behavior_t,
MACHINE_THREAD_STATE,
);
}
}

unsafe extern "C" fn trap_handler(
Expand Down

0 comments on commit e002b7b

Please sign in to comment.