-
Notifications
You must be signed in to change notification settings - Fork 149
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
Fix debug Linux #679
base: master
Are you sure you want to change the base?
Fix debug Linux #679
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
# include <sys/wait.h> | ||
# include <sys/user.h> | ||
# include <signal.h> | ||
# include <errno.h> | ||
# define USE_PTRACE | ||
#endif | ||
|
||
|
@@ -84,6 +85,7 @@ HL_API bool hl_debug_stop( int pid ) { | |
# elif defined(MAC_DEBUG) | ||
return mdbg_session_detach(pid); | ||
# elif defined(USE_PTRACE) | ||
kill(pid, SIGTRAP); // DETACH needs ptrace-stop | ||
return ptrace(PTRACE_DETACH,pid,0,0) >= 0; | ||
# else | ||
return false; | ||
|
@@ -248,14 +250,23 @@ HL_API int hl_debug_wait( int pid, int *thread, int timeout ) { | |
return mdbg_session_wait(pid, thread, timeout); | ||
# elif defined(USE_PTRACE) | ||
int status; | ||
int ret = waitpid(pid,&status,0); | ||
//printf("WAITPID=%X %X\n",ret,status); | ||
// *** HACK *** | ||
// usleep here is needed for a good result. | ||
// Without it, waitpid can miss many stop event; | ||
// With it, and more we wait, less we miss stop event. | ||
usleep(100 * 1000); | ||
int ret = waitpid(pid, &status, WNOHANG); | ||
Comment on lines
+253
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect that I'm not sure how to fix this other than by doing the same thread & semaphore dance as the Mac debugger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also suspect the I tested your implementation with thread (it helps me a lot!), but it failed when we are actually waiting (by default the vscode extension call wait with a timeout = 0) and has a timeout. I didn't managed to get it works yet :'( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was another PR, I never actually submitted the thread & semaphore implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I misunderstood :( |
||
if( ret == -1 && errno == ECHILD ) { | ||
*thread = pid; | ||
return 0; | ||
} | ||
*thread = ret; | ||
if( ret <= 0 ) | ||
return -1; | ||
if( WIFEXITED(status) ) | ||
return 0; | ||
if( WIFSTOPPED(status) ) { | ||
int sig = WSTOPSIG(status); | ||
//printf(" STOPSIG=%d\n",sig); | ||
if( sig == SIGSTOP || sig == SIGTRAP ) | ||
return 1; | ||
return 3; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
SIGSTOP
would be more appropriate here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. But when I test with SIGSTOP, the disconnect does not works properly (maybe SIGSTOP is not actually stopping - the signal is forward to our thread? or has some delay / different behavior than SIGTRAP). :(