Jacek Caban : winedbg: Set auto attach event after processing the first exception.

Alexandre Julliard julliard at winehq.org
Tue Jul 2 15:32:02 CDT 2019


Module: wine
Branch: master
Commit: 1bb98982d682a85b82e1496a2321daa043d8a6c5
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=1bb98982d682a85b82e1496a2321daa043d8a6c5

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Jul  2 18:02:30 2019 +0200

winedbg: Set auto attach event after processing the first exception.

On Windows, the process is broken into by ordering an actual debug
break execution in a new thread. We need to process this event before
continuing exception handling in debuggee to avoid race.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/winedbg/debugger.h   |  4 ++--
 programs/winedbg/tgt_active.c | 14 +++++---------
 programs/winedbg/winedbg.c    | 10 ++++++++--
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h
index ee33ca0..d8d7a69 100644
--- a/programs/winedbg/debugger.h
+++ b/programs/winedbg/debugger.h
@@ -235,8 +235,8 @@ struct dbg_process
     const WCHAR*		imageName;
     struct list           	threads;
     struct backend_cpu*         be_cpu;
-    BOOL                        continue_on_first_exception : 1,
-                                active_debuggee : 1;
+    HANDLE                      event_on_first_exception;
+    BOOL                        active_debuggee;
     struct dbg_breakpoint       bp[MAX_BREAKPOINTS];
     unsigned                    next_bp;
     struct dbg_delayed_bp*      delayed_bp;
diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c
index f2ea753..71e0bc1 100644
--- a/programs/winedbg/tgt_active.c
+++ b/programs/winedbg/tgt_active.c
@@ -334,9 +334,11 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de)
                    de->dwProcessId, de->dwThreadId,
                    de->u.Exception.ExceptionRecord.ExceptionCode);
 
-        if (dbg_curr_process->continue_on_first_exception)
+        if (dbg_curr_process->event_on_first_exception)
         {
-            dbg_curr_process->continue_on_first_exception = FALSE;
+            SetEvent(dbg_curr_process->event_on_first_exception);
+            CloseHandle(dbg_curr_process->event_on_first_exception);
+            dbg_curr_process->event_on_first_exception = NULL;
             if (!DBG_IVAR(BreakOnAttach)) break;
         }
         if (dbg_fetch_context())
@@ -788,13 +790,7 @@ enum dbg_start  dbg_active_attach(int argc, char* argv[])
             SetEvent((HANDLE)evt);
             return start_error_init;
         }
-        dbg_curr_process->continue_on_first_exception = TRUE;
-        if (!SetEvent((HANDLE)evt))
-        {
-            WINE_ERR("Invalid event handle: %lx\n", evt);
-            return start_error_init;
-        }
-        CloseHandle((HANDLE)evt);
+        dbg_curr_process->event_on_first_exception = (HANDLE)evt;
     }
     else return start_error_parse;
 
diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c
index 92d248c..5dee3b7 100644
--- a/programs/winedbg/winedbg.c
+++ b/programs/winedbg/winedbg.c
@@ -312,7 +312,7 @@ struct dbg_process*	dbg_add_process(const struct be_process_io* pio, DWORD pid,
     p->pio_data = NULL;
     p->imageName = NULL;
     list_init(&p->threads);
-    p->continue_on_first_exception = FALSE;
+    p->event_on_first_exception = NULL;
     p->active_debuggee = FALSE;
     p->next_bp = 1;  /* breakpoint 0 is reserved for step-over */
     memset(p->bp, 0, sizeof(p->bp));
@@ -372,6 +372,7 @@ void dbg_del_process(struct dbg_process* p)
     source_free_files(p);
     list_remove(&p->entry);
     if (p == dbg_curr_process) dbg_curr_process = NULL;
+    if (p->event_on_first_exception) CloseHandle(p->event_on_first_exception);
     HeapFree(GetProcessHeap(), 0, (char*)p->imageName);
     HeapFree(GetProcessHeap(), 0, p);
 }
@@ -559,7 +560,12 @@ BOOL dbg_interrupt_debuggee(void)
     p = LIST_ENTRY(list_head(&dbg_process_list), struct dbg_process, entry);
     if (list_next(&dbg_process_list, &p->entry)) dbg_printf("Ctrl-C: only stopping the first process\n");
     else dbg_printf("Ctrl-C: stopping debuggee\n");
-    p->continue_on_first_exception = FALSE;
+    if (p->event_on_first_exception)
+    {
+        SetEvent(p->event_on_first_exception);
+        CloseHandle(p->event_on_first_exception);
+        p->event_on_first_exception = NULL;
+    }
     return DebugBreakProcess(p->handle);
 }
 




More information about the wine-cvs mailing list