V8 debugging and multithreading

64 views
Skip to first unread message

Pavlo Mur

unread,
May 16, 2017, 6:49:06 AM5/16/17
to v8-users
While integrating debugger support into our v8 embedding application it was discovered that debugger state is not saved/restored when threads are switched - thus once we step over any such C++ call that temporary unlocks v8 engine, debugger is not able to stop on next statement and script just runs without stops.

v8 version 5.8.283.32

* Are there any workarounds to save debug context without modifying v8 souces?
* Why Debug::ArchiveDebug does "Simply reset state. Don't archive anything." in this case?


Details:
Corresponding source fragment

char* Debug::ArchiveDebug(char* storage) {
 
// Simply reset state. Don't archive anything.
 
ThreadInit();
 
return storage + ArchiveSpacePerThread();
}
 
char* Debug::RestoreDebug(char* storage) {
 
// Simply reset state. Don't restore anything.
 
ThreadInit();
 
return storage + ArchiveSpacePerThread();
}
int Debug::ArchiveSpacePerThread() { return 0; }


Call stack:

Actual sequence:
1. While step by step debugging stop on API exported from C++ that does following
2.a. Unlock v8 via v8::Unlocker
2.b. Set native event
2.c. Meanwhile other C++ thread will wake, lock v8 via v8::Locker
, issue JS callback, unlock v8
2.d. Wait for confirmation from that other C++ thread 
2.e. Lock v8 again in destuctor of v8::Unlocker
3. After return from that API debugger does not stop any more because inside of Debug::Break(JavaScriptFrame* frame)
 call to last_step_action(); now returns StepNone instead of
StepNext and JS continues to run instead of stopping on next JS statement.

Jakob Gruber

unread,
May 17, 2017, 2:29:41 AM5/17/17
to v8-u...@googlegroups.com
We removed support for preserving debugger state across thread switches because it was untested, probably buggy, and unused. 

As a workaround, you would need to store state (e.g. active breakpoints) yourself and reissue debugger commands after switching threads.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pavlo Mur

unread,
May 17, 2017, 6:56:57 AM5/17/17
to v8-users
Thanks for prompt reply, Jakob,
 
To solve our issue we did following changes in our local v8 copy (looks drastical, but works perfectly for our purpose):

In debug.h for storage location for registers when handling debug break calls we just added static thread_local
static thread_local ThreadLocal thread_local_;


and in debug.cc
//Make thread_local_ really thread_local :)
thread_local
Debug::ThreadLocal Debug::thread_local_;
 
char* Debug::ArchiveDebug(char* storage) {
 
// Leave thread_local storage as is in thread_local memory

   
return storage + ArchiveSpacePerThread();
}
 
char* Debug::RestoreDebug(char* storage) {

 
// Leave thread_local storage as is in thread_local memory
   
return storage + ArchiveSpacePerThread();
}





17 травня 2017 р. 09:29:41 UTC+3 користувач Jakob Gruber написав:
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages