Hey Andreas, Simon, Just wanted to drop a quick note to say thanks. Your advice hit the mark and the interrupt request method worked like a charm. Really appreciate it!
Take care, Patric Lemo On Monday, June 19, 2023 at 6:57:26 PM UTC+8 Simon Zünd wrote: > Hi Patric, > > one more thing to note is that signal handlers might have a separate > stack, depending on whether one was set up with "sigaltstack". > > As Andreas mentioned, your best bet is to request an interrupt from the > signal handler (or a separate thread) and capture the stack trace in the > callback. > > On Mon, Jun 19, 2023 at 12:10 PM 'Andreas Haas' via v8-dev < > [email protected]> wrote: > >> Hi Partric, >> >> I am not an expert with stack traces, so I don't know if there is a >> better method, but I think your approach is flawed. v8::StackTrace:: >> CurrentStackTrace() can only work when code execution made a valid >> transition from JavaScript to C++, in other words, when there is an Exit >> frame on the stack. With a signal you transition from JavaScript code >> directly to the signal handling code, without an Exit frame. However, >> without the Exit frame V8 cannot find the beginning of the JavaScript >> stack, and can therefore not generate a stack trace. >> >> You could try to request an interrupt with >> https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:v8/include/v8-isolate.h;l=1115;drc=8d3b19d9432fa06963a1efbd8b85d5d310c3a05a, >> >> and then create the stack trace from within the callback. Maybe that works >> better. >> >> Cheers, Andreas >> >> On Mon, Jun 19, 2023 at 10:27 AM Patric Lemo <[email protected]> wrote: >> >>> >>> Hello all: >>> >>> I am working on a project where I need to print the JS stack trace when >>> a JS process becomes unresponsive. My approach involves setting a periodic >>> alarm using the `alarm()` function, and in the timeout function, I attempt >>> to print the JS stack trace. >>> >>> I'm experiencing an issue where `v8::StackTrace::CurrentStackTrace` >>> returns a frame count of 0 when invoked within the signal handler. I >>> understand there could be some complications using the V8 API within a >>> signal handler due to its asynchronous signal-unsafe nature. >>> >>> Here is a simplified version of my current approach: >>> >>> // Assume isolate and context are correctly setup >>> void signalHandler(int signal) { >>> // Try to get stack trace and print >>> v8::HandleScope handleScope(isolate); >>> v8::Local<v8::StackTrace> stackTrace = >>> v8::StackTrace::CurrentStackTrace( >>> isolate, >>> 10, >>> v8::StackTrace::kDetailed >>> ); >>> int frameCount = stackTrace->GetFrameCount(); >>> printf("Frame Count: %d\n", frameCount); >>> // Iterate and print each frame here... >>> } >>> >>> int main() { >>> // Setup V8, isolate and context here... >>> signal(SIGALRM, signalHandler); >>> alarm(10); // Set alarm >>> // Rest of the program... >>> } >>> >>> >>> Is my approach flawed? Is there a safer or more effective method to >>> achieve what I'm trying to do? >>> >>> Thanks >>> >>> -- >>> -- >>> v8-dev mailing list >>> [email protected] >>> http://groups.google.com/group/v8-dev >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "v8-dev" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/v8-dev/0e06f5e3-b37b-4bcc-a293-65d152b0938fn%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/v8-dev/0e06f5e3-b37b-4bcc-a293-65d152b0938fn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> >> Andreas Haas >> >> Software Engineer >> >> [email protected] >> >> >> Google Germany GmbH >> >> Erika-Mann-Straße 33 >> >> 80636 München >> >> >> Geschäftsführer: Paul Manicle, Liana Sebastian >> >> Registergericht und -nummer: Hamburg, HRB 86891 >> >> Sitz der Gesellschaft: Hamburg >> >> >> Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten >> haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, >> löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, >> dass die E-Mail an die falsche Person gesendet wurde. >> >> >> >> This e-mail is confidential. If you received this communication by >> mistake, please don't forward it to anyone else, please erase all copies >> and attachments, and please let me know that it has gone to the wrong >> person. >> >> -- >> -- >> v8-dev mailing list >> [email protected] >> http://groups.google.com/group/v8-dev >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/v8-dev/CAELSTveAc5EhxCBbKvixwHmTy1G9tfwnKPDRW%3D45S%3DPA8qPGYA%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/v8-dev/CAELSTveAc5EhxCBbKvixwHmTy1G9tfwnKPDRW%3D45S%3DPA8qPGYA%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/e9fc9bcc-064f-4b59-9b3b-ff2257757673n%40googlegroups.com.
