Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
update version, print fatal error info, print only line if column is …
Browse files Browse the repository at this point in the history
…not available, windows use stdcall for handler function
  • Loading branch information
LaoLittle committed Dec 19, 2022
1 parent b160276 commit 7caf1be
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atri_bot"
version = "0.8.0"
version = "0.8.2"
edition = "2021"
authors = ["LaoLittle"]
description = "A simple bot"
Expand Down
10 changes: 9 additions & 1 deletion src/signal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ impl fmt::Display for DlBacktrace {
f,
" {}\n at {}",
symbol.name().unwrap_or(backtrace::SymbolName::new(&[])),
symbol.filename().and_then(Path::to_str).unwrap_or(""),
symbol
.filename()
.and_then(Path::to_str)
.unwrap_or("unknown"),
)?;

match (symbol.lineno(), symbol.colno()) {
(Some(line), Some(column)) => write!(f, ":{line}:{column}")?,
(Some(line), None) => write!(f, ":{line}")?,
_ => {}
}

Expand All @@ -52,3 +56,7 @@ impl fmt::Display for DlBacktrace {
Ok(())
}
}

fn fatal_error_print() {
eprintln!("An fatal error has been detected");
}
2 changes: 2 additions & 0 deletions src/signal/sys/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ unsafe extern "C" fn handle(
}
}

crate::signal::fatal_error_print();

let bt = backtrace::Backtrace::new();

eprintln!("addr: {:p}", (*_info)._sifields._sigfault.si_addr);
Expand Down
2 changes: 2 additions & 0 deletions src/signal/sys/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ unsafe extern "C" fn handle(
}
}

crate::signal::fatal_error_print();

let bt = backtrace::Backtrace::new();

eprintln!("addr: {:p}", (*_info).si_addr);
Expand Down
8 changes: 6 additions & 2 deletions src/signal/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn init_crash_handler() {
}
}

unsafe extern "C" fn handle(_: *const std::os::raw::c_void) -> DWORD {
unsafe extern "stdcall" fn handle(_: *const ExceptionPointers) -> DWORD {
fn dl_get_name(addr: *const std::ffi::c_void) -> String {
const MAX_PATH: usize = 260;

Expand Down Expand Up @@ -53,6 +53,8 @@ unsafe extern "C" fn handle(_: *const std::os::raw::c_void) -> DWORD {
String::from_utf16_lossy(slice)
}

crate::signal::fatal_error_print();

let bt = backtrace::Backtrace::new();
eprintln!(
"stack backtrace:\n{}",
Expand All @@ -67,7 +69,9 @@ unsafe extern "C" fn handle(_: *const std::os::raw::c_void) -> DWORD {
1
}

type LpTopLevelExceptionFilter = unsafe extern "C" fn(*const std::os::raw::c_void) -> DWORD;
type ExceptionPointers = std::os::raw::c_void; // FIXME

type LpTopLevelExceptionFilter = unsafe extern "stdcall" fn(*const ExceptionPointers) -> DWORD;

type DWORD = std::os::raw::c_ulong;

Expand Down

0 comments on commit 7caf1be

Please sign in to comment.