[CP] CRASH ERROR improve

This commit is contained in:
tushicheng
2024-02-04 09:12:28 +00:00
committed by ob-robot
parent 5e08668e62
commit 6acb97c9f6
9 changed files with 30 additions and 258 deletions

View File

@ -81,9 +81,9 @@ signal_handler_t &get_signal_handler()
bool g_redirect_handler = false;
static __thread int g_coredump_num = 0;
#define COMMON_FMT "timestamp=%ld, tid=%ld, tname=%s, trace_id=%lu-%lu-%lu-%lu, extra_info=(%s), lbt=%s"
#define COMMON_FMT "timestamp=%ld, tid=%ld, tname=%s, trace_id="TRACE_ID_FORMAT_V2", extra_info=(%s), lbt=%s"
void coredump_cb(int, siginfo_t*, void*);
void coredump_cb(int, int, void*, void*);
void ob_signal_handler(int sig, siginfo_t *si, void *context)
{
if (!g_redirect_handler) {
@ -98,7 +98,7 @@ void ob_signal_handler(int sig, siginfo_t *si, void *context)
if (ctx.req_id_ != req_id) return;
ctx.handler_->handle(ctx);
} else {
coredump_cb(sig, si, context);
coredump_cb(sig, si->si_code, si->si_addr, context);
}
}
}
@ -106,7 +106,7 @@ void ob_signal_handler(int sig, siginfo_t *si, void *context)
void hook_sigsegv_msg(int sig, siginfo_t *si, void *context)
{
if (mprotect_page(si->si_addr, 8, PROT_READ | PROT_WRITE, "release signal addr") != 0) {
coredump_cb(sig, si, context);
coredump_cb(sig, si->si_code, si->si_addr, context);
} else {
// thread_name
char tname[16];
@ -126,18 +126,18 @@ void close_socket_fd()
int fd = -1;
int pid = getpid();
safe_snprintf(path, 32, "/proc/%d/fd/", pid);
lnprintf(path, 32, "/proc/%d/fd/", pid);
if (NULL == (dir = opendir(path))) {
} else {
while(NULL != (fd_file = readdir(dir))) {
if (0 != strcmp(fd_file->d_name, ".") && 0 != strcmp(fd_file->d_name, "..")
&& 0 != strcmp(fd_file->d_name, "0") && 0 != strcmp(fd_file->d_name, "1")
&& 0 != strcmp(fd_file->d_name, "2")) {
safe_snprintf(name, 32, "/proc/%d/fd/%s", pid, fd_file->d_name);
lnprintf(name, 32, "/proc/%d/fd/%s", pid, fd_file->d_name);
if (-1 == readlink(name, real_name, 32)) {
DLOG(INFO, "[CLOSEFD], err read link %s, errno = %d", name, errno);
} else {
safe_snprintf(name, 32, "%s", real_name);
lnprintf(name, 32, "%s", real_name);
if (NULL != strstr(name, "socket")) {
fd = atoi(fd_file->d_name);
close(fd);
@ -153,7 +153,7 @@ void close_socket_fd()
}
void coredump_cb(int sig, siginfo_t *si, void *context)
void coredump_cb(volatile int sig, volatile int sig_code, void* volatile sig_addr, void *context)
{
int ret = OB_SUCCESS;
if (g_coredump_num++ < 1) {
@ -170,7 +170,7 @@ void coredump_cb(int sig, siginfo_t *si, void *context)
char tname[16];
prctl(PR_GET_NAME, tname);
// backtrace
char bt[256];
char bt[512];
int64_t len = 0;
#ifdef __x86_64__
safe_backtrace(bt, sizeof(bt) - 1, &len);
@ -183,7 +183,7 @@ void coredump_cb(int sig, siginfo_t *si, void *context)
if (trace_id != nullptr) {
trace_id->get_uval(uval);
}
char print_buf[512];
char print_buf[1024];
const ucontext_t *con = (ucontext_t *)context;
#if defined(__x86_64__)
int64_t ip = con->uc_mcontext.gregs[REG_RIP];
@ -195,20 +195,20 @@ void coredump_cb(int sig, siginfo_t *si, void *context)
#endif
char rlimit_core[32] = "unlimited";
if (UINT64_MAX != g_rlimit_core) {
safe_snprintf(rlimit_core, sizeof(rlimit_core), "%lu", g_rlimit_core);
lnprintf(rlimit_core, sizeof(rlimit_core), "%lu", g_rlimit_core);
}
char crash_info[128] = "CRASH ERROR!!!";
int64_t fatal_error_thread_id = get_fatal_error_thread_id();
if (-1 != fatal_error_thread_id) {
safe_snprintf(crash_info, sizeof(crash_info),
"Right to Die or Duty to Live's Thread Existed before CRASH ERROR!!!"
"ThreadId=%ld,", fatal_error_thread_id);
lnprintf(crash_info, sizeof(crash_info),
"Right to Die or Duty to Live's Thread Existed before CRASH ERROR!!!"
"ThreadId=%ld,", fatal_error_thread_id);
}
ssize_t print_len = safe_snprintf(print_buf, sizeof(print_buf),
"%s IP=%lx, RBP=%lx, sig=%d, sig_code=%d, sig_addr=%p, RLIMIT_CORE=%s, "COMMON_FMT", ",
crash_info, ip, bp, sig, si->si_code, si->si_addr, rlimit_core,
ts, GETTID(), tname, uval[0], uval[1], uval[2], uval[3],
(NULL == extra_info) ? NULL : to_cstring(*extra_info), bt);
ssize_t print_len = lnprintf(print_buf, sizeof(print_buf),
"%s IP=%lx, RBP=%lx, sig=%d, sig_code=%d, sig_addr=%p, RLIMIT_CORE=%s, "COMMON_FMT", ",
crash_info, ip, bp, sig, sig_code, sig_addr, rlimit_core,
ts, GETTID(), tname, TRACE_ID_FORMAT_PARAM(uval),
(NULL == extra_info) ? NULL : to_cstring(*extra_info), bt);
const auto &si_guard = ObSqlInfoGuard::get_cur_guard();
char sql[] = "SQL=";
char end[] = "\n";