feat: add support for tty local debugger
This commit is contained in:
parent
829a8d33e9
commit
2f7228cea6
3 changed files with 35 additions and 3 deletions
|
@ -1,10 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
#include <csignal>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void install_debugger();
|
void install_debugger();
|
||||||
|
void install_remote_debugger();
|
||||||
void install_backtrace();
|
void install_backtrace();
|
||||||
void install_jitdebugger();
|
void install_jitdebugger();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -31,7 +30,8 @@ static void get_pid_binpath() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const auto lldb{"/usr/bin/lldb"};
|
static const auto lldb{"/usr/bin/lldb"};
|
||||||
static const auto default_debugger{"/usr/bin/gdbserver"};
|
static const auto default_debugger{"/usr/bin/gdb"};
|
||||||
|
static const auto default_remote_debugger{"/usr/bin/gdbserver"};
|
||||||
|
|
||||||
static auto get_debugger() -> const char * {
|
static auto get_debugger() -> const char * {
|
||||||
const char *debugger = secure_getenv("JITDEBUG");
|
const char *debugger = secure_getenv("JITDEBUG");
|
||||||
|
@ -47,6 +47,20 @@ static auto get_debugger() -> const char * {
|
||||||
}
|
}
|
||||||
const char *const debugger = get_debugger();
|
const char *const debugger = get_debugger();
|
||||||
|
|
||||||
|
static auto get_remote_debugger() -> const char * {
|
||||||
|
const char *debugger = secure_getenv("JITDEBUG");
|
||||||
|
if (not debugger)
|
||||||
|
return default_remote_debugger;
|
||||||
|
if (strcmp(debugger, "on") == 0)
|
||||||
|
return default_remote_debugger;
|
||||||
|
if (strcmp(debugger, "1") == 0)
|
||||||
|
return default_remote_debugger;
|
||||||
|
if (strcmp(debugger, "true") == 0)
|
||||||
|
return default_remote_debugger;
|
||||||
|
return debugger;
|
||||||
|
}
|
||||||
|
const char *const remote_debugger = get_remote_debugger();
|
||||||
|
|
||||||
void start_debugger(const char *dbg, const char **argv) {
|
void start_debugger(const char *dbg, const char **argv) {
|
||||||
#if defined(PR_SET_PTRACER)
|
#if defined(PR_SET_PTRACER)
|
||||||
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); // NOLINT
|
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); // NOLINT
|
||||||
|
@ -67,11 +81,21 @@ void start_debugger(const char *dbg, const char **argv) {
|
||||||
extern "C" void sighdl_debugger(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
extern "C" void sighdl_debugger(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
||||||
get_pid_binpath();
|
get_pid_binpath();
|
||||||
const char *argv[] = {// NOLINT
|
const char *argv[] = {// NOLINT
|
||||||
debugger, "--attach", "[::1]:7777", pid_s, nullptr};
|
debugger, "--pid", pid_s, nullptr};
|
||||||
start_debugger(debugger, argv);
|
start_debugger(debugger, argv);
|
||||||
(void)raise(no);
|
(void)raise(no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void sighdl_remote_debugger(int no, siginfo_t * /*sigi*/,
|
||||||
|
void * /*uco*/) {
|
||||||
|
get_pid_binpath();
|
||||||
|
const char *argv[] = {// NOLINT
|
||||||
|
remote_debugger, "--attach", "[::1]:7777", pid_s,
|
||||||
|
"-ex", "continue", nullptr};
|
||||||
|
start_debugger(remote_debugger, argv);
|
||||||
|
(void)raise(no);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void sighdl_backtrace(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
extern "C" void sighdl_backtrace(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
||||||
get_pid_binpath();
|
get_pid_binpath();
|
||||||
const char *argv[] = {// NOLINT
|
const char *argv[] = {// NOLINT
|
||||||
|
@ -98,6 +122,9 @@ static void install_crash_handler(void (*hdlr)(int, siginfo_t *, void *)) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C" void install_debugger() { install_crash_handler(sighdl_debugger); }
|
extern "C" void install_debugger() { install_crash_handler(sighdl_debugger); }
|
||||||
|
extern "C" void install_remote_debugger() {
|
||||||
|
install_crash_handler(sighdl_remote_debugger);
|
||||||
|
}
|
||||||
extern "C" void install_backtrace() { install_crash_handler(sighdl_backtrace); }
|
extern "C" void install_backtrace() { install_crash_handler(sighdl_backtrace); }
|
||||||
extern "C" void install_jitdebugger() {
|
extern "C" void install_jitdebugger() {
|
||||||
if (secure_getenv("JITDEBUG"))
|
if (secure_getenv("JITDEBUG"))
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub var stack_trace_on_errors: bool = false;
|
||||||
pub const subprocess = if (builtin.os.tag == .windows) @import("subprocess_windows.zig") else @import("subprocess.zig");
|
pub const subprocess = if (builtin.os.tag == .windows) @import("subprocess_windows.zig") else @import("subprocess.zig");
|
||||||
|
|
||||||
pub const install_debugger = c.install_debugger;
|
pub const install_debugger = c.install_debugger;
|
||||||
|
pub const install_remote_debugger = c.install_remote_debugger;
|
||||||
pub const install_backtrace = c.install_backtrace;
|
pub const install_backtrace = c.install_backtrace;
|
||||||
pub const install_jitdebugger = c.install_jitdebugger;
|
pub const install_jitdebugger = c.install_jitdebugger;
|
||||||
pub const max_message_size = 8 * 4096;
|
pub const max_message_size = 8 * 4096;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue