winedbg: Use standard Wine lists for threads.
authorEric Pouech <eric.pouech@orange.fr>
Mon, 12 Apr 2010 19:18:37 +0000 (21:18 +0200)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 13 Apr 2010 09:43:09 +0000 (11:43 +0200)
programs/winedbg/debugger.h
programs/winedbg/gdbproxy.c
programs/winedbg/tgt_active.c
programs/winedbg/winedbg.c

index 2965389496b3cfb51dd565a4a568ba1d09741c6b..8ebac1e08f558d860fa57d6d705a2a141edd6441 100644 (file)
@@ -171,6 +171,7 @@ typedef struct tagTHREADNAME_INFO
 
 struct dbg_thread
 {
+    struct list                 entry;
     struct dbg_process*        process;
     HANDLE                     handle;
     DWORD                      tid;
@@ -181,8 +182,6 @@ struct dbg_thread
     int                         stopped_xpoint; /* xpoint on which the thread has stopped (-1 if none) */
     struct dbg_breakpoint      step_over_bp;
     char                        name[9];
-    struct dbg_thread*         next;
-    struct dbg_thread*         prev;
     BOOL                        in_exception;   /* TRUE if thread stopped with an exception */
     EXCEPTION_RECORD            excpt_record;   /* only valid when in_exception is TRUE */
     struct
@@ -224,7 +223,7 @@ struct dbg_process
     const struct be_process_io* process_io;
     void*                       pio_data;
     const WCHAR*               imageName;
-    struct dbg_thread*         threads;
+    struct list                threads;
     unsigned                   continue_on_first_exception : 1,
                                 active_debuggee : 1;
     struct dbg_breakpoint       bp[MAX_BREAKPOINTS];
index c1dac013331aa75dd555413b532cfafad591b1d3..3d8ccd52cfefe2f8b2de6a93fe48084aeed15052 100644 (file)
@@ -1105,7 +1105,7 @@ static enum packet_return packet_verbose(struct gdb_context* gdbctx)
     /* Now, I have this default action thing that needs to be applied to all non counted threads */
 
     /* go through all the threads and stick their ids in the to be done list. */
-    for (thd = gdbctx->process->threads; thd; thd = thd->next)
+    LIST_FOR_EACH_ENTRY(thd, &gdbctx->process->threads, struct dbg_thread, entry)
     {
         threadIDs[threadCount++] = thd->tid;
         /* check to see if we have more threads than I counted on, and tell the user what to do
@@ -1725,10 +1725,10 @@ static enum packet_return packet_query(struct gdb_context* gdbctx)
 
             packet_reply_open(gdbctx);
             packet_reply_add(gdbctx, "m", 1);
-            for (thd = gdbctx->process->threads; thd; thd = thd->next)
+            LIST_FOR_EACH_ENTRY(thd, &gdbctx->process->threads, struct dbg_thread, entry)
             {
                 packet_reply_val(gdbctx, thd->tid, 4);
-                if (thd->next != NULL)
+                if (list_next(&gdbctx->process->threads, &thd->entry) != NULL)
                     packet_reply_add(gdbctx, ",", 1);
             }
             packet_reply_close(gdbctx);
@@ -1764,8 +1764,8 @@ static enum packet_return packet_query(struct gdb_context* gdbctx)
             struct dbg_thread*  thd;
             /* FIXME: doc says 16 bit val ??? */
             /* grab first created thread, aka last in list */
-            assert(gdbctx->process && gdbctx->process->threads);
-            for (thd = gdbctx->process->threads; thd->next; thd = thd->next);
+            assert(gdbctx->process && !list_empty(&gdbctx->process->threads));
+            thd = LIST_ENTRY(list_tail(&gdbctx->process->threads), struct dbg_thread, entry);
             packet_reply_open(gdbctx);
             packet_reply_add(gdbctx, "QC", 2);
             packet_reply_val(gdbctx, thd->tid, 4);
index c61261593c07698deb321675e8cae48b22f94e17..0511063f32db812007b70ab114c79d3ab748286e 100644 (file)
@@ -46,8 +46,7 @@ static void dbg_init_current_thread(void* start)
 {
     if (start)
     {
-       if (dbg_curr_process->threads &&
-            !dbg_curr_process->threads->next && /* first thread ? */
+       if (list_count(&dbg_curr_process->threads) == 1 /* first thread ? */ &&
            DBG_IVAR(BreakAllThreadsStartup))
         {
            ADDRESS64   addr;
index 60a15ee438006d9b15ca2e45447d4d539a408138..3e645065d04e3ae1ce420d8d6e1043c42c8e099c 100644 (file)
@@ -79,7 +79,6 @@
  *        every function call to catch the errors
  *      + BTW check also whether the exception mechanism is the best way to return
  *        errors (or find a proper fix for MinGW port)
- *      + use Wine standard list mechanism for all list handling
  */
 
 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
@@ -305,7 +304,7 @@ struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid,
     p->process_io = pio;
     p->pio_data = NULL;
     p->imageName = NULL;
-    p->threads = NULL;
+    list_init(&p->threads);
     p->continue_on_first_exception = FALSE;
     p->active_debuggee = FALSE;
     p->next_bp = 1;  /* breakpoint 0 is reserved for step-over */
@@ -334,9 +333,12 @@ void dbg_set_process_name(struct dbg_process* p, const WCHAR* imageName)
 
 void dbg_del_process(struct dbg_process* p)
 {
+    struct dbg_thread*  t;
+    struct dbg_thread*  t2;
     int        i;
 
-    while (p->threads) dbg_del_thread(p->threads);
+    LIST_FOR_EACH_ENTRY_SAFE(t, t2, &p->threads, struct dbg_thread, entry)
+        dbg_del_thread(t);
 
     for (i = 0; i < p->num_delayed_bp; i++)
         if (p->delayed_bp[i].is_symbol)
@@ -447,9 +449,9 @@ struct dbg_thread* dbg_get_thread(struct dbg_process* p, DWORD tid)
     struct dbg_thread* t;
 
     if (!p) return NULL;
-    for (t = p->threads; t; t = t->next)
-       if (t->tid == tid) break;
-    return t;
+    LIST_FOR_EACH_ENTRY(t, &p->threads, struct dbg_thread, entry)
+       if (t->tid == tid) return t;
+    return NULL;
 }
 
 struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid,
@@ -477,10 +479,7 @@ struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid,
 
     snprintf(t->name, sizeof(t->name), "%04x", tid);
 
-    t->next = p->threads;
-    t->prev = NULL;
-    if (p->threads) p->threads->prev = t;
-    p->threads = t;
+    list_add_head(&p->threads, &t->entry);
 
     return t;
 }
@@ -488,9 +487,7 @@ struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid,
 void dbg_del_thread(struct dbg_thread* t)
 {
     HeapFree(GetProcessHeap(), 0, t->frames);
-    if (t->prev) t->prev->next = t->next;
-    if (t->next) t->next->prev = t->prev;
-    if (t == t->process->threads) t->process->threads = t->next;
+    list_remove(&t->entry);
     if (t == dbg_curr_thread) dbg_curr_thread = NULL;
     HeapFree(GetProcessHeap(), 0, t);
 }