Eric Pouech : winedbg: Use standard Wine lists for threads.

Alexandre Julliard julliard at winehq.org
Tue Apr 13 11:24:40 CDT 2010


Module: wine
Branch: master
Commit: e4c29f908759d3567fbfd5982780bc133ba2a2b1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e4c29f908759d3567fbfd5982780bc133ba2a2b1

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Mon Apr 12 21:18:37 2010 +0200

winedbg: Use standard Wine lists for threads.

---

 programs/winedbg/debugger.h   |    5 ++---
 programs/winedbg/gdbproxy.c   |   10 +++++-----
 programs/winedbg/tgt_active.c |    3 +--
 programs/winedbg/winedbg.c    |   23 ++++++++++-------------
 4 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h
index 2965389..8ebac1e 100644
--- a/programs/winedbg/debugger.h
+++ b/programs/winedbg/debugger.h
@@ -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];
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c
index c1dac01..3d8ccd5 100644
--- a/programs/winedbg/gdbproxy.c
+++ b/programs/winedbg/gdbproxy.c
@@ -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);
diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c
index c612615..0511063 100644
--- a/programs/winedbg/tgt_active.c
+++ b/programs/winedbg/tgt_active.c
@@ -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;
diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c
index 60a15ee..3e64506 100644
--- a/programs/winedbg/winedbg.c
+++ b/programs/winedbg/winedbg.c
@@ -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);
 }




More information about the wine-cvs mailing list