-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does minidump-writer support dumping stack without crash? #37
Comments
or in other words, how to make CrashContext without crashing for linux/macos/windows ? |
For Linux the crash context is optional, but you are correct that it should also be optional for windows and mac as well. That being said, it's also fairly trivial to generate a crash context for Mac and Windows manually. // Unsafe function
use windows_sys::Win32::{
System::{
Diagnostics::Debug::{
RtlCaptureContext, EXCEPTION_POINTERS, EXCEPTION_RECORD,
},
Threading::GetCurrentThreadId,
},
};
let mut exception_record: EXCEPTION_RECORD = std::mem::zeroed();
let mut exception_context = std::mem::MaybeUninit::uninit();
// Get the CPU context
RtlCaptureContext(exception_context.as_mut_ptr());
let mut exception_context = exception_context.assume_init();
let exception_ptrs = EXCEPTION_POINTERS {
ExceptionRecord: &mut exception_record,
ContextRecord: &mut exception_context,
};
let exception_code = <a Windows windows_sys::Win32::Foundation::STATUS_* exception code>;
exception_record.ExceptionCode = exception_code;
let cc = crash_context::CrashContext {
exception_pointers: (&exception_ptrs as *const EXCEPTION_POINTERS)
.cast(),
process_id: std::process::id(),
thread_id: GetCurrentThreadId(), // or even better, the id of the thread that got stuck
exception_code,
}; // Unsafe function
let cc = crash_context::CrashContext {
task: mach2::traps::mach_task_self(),
thread: mach2::mach_init::mach_thread_self(), // preferably the id of the thread that is stuck
handler_thread: mach2::mach_init::mach_thread_self(),
exception: None, // or optionally fill out the exception info
}; |
Thanks @Jake-Shadle for the reply |
If you're dumping the same process you could use std::process:id() to get the process identifier, the thread identifier you either retrieve in the thread itself by calling |
@Jake-Shadle |
That is most likely because you need to the mark the process as dumpable with |
libc::syscall(libc::SYS_prctl, PR_SET_DUMPABLE, 1, 0, 0, 0) did not work and still "No threads left to suspend out of 9" |
Sometimes there are bugs in the program that one thread may run into dead loop and burn cpu.
We can spawn watch-dog thread to monitor all thread and dump stack if dead-loop occur.
So it can be very helpful if minidump-writer supports dumping stack without crash.
The text was updated successfully, but these errors were encountered: