Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* New feature: allow thread command to take a LWPID.
@ 2010-02-04 11:35 scott.harrison
  2010-02-04 23:30 ` Tom Tromey
  0 siblings, 1 reply; 9+ messages in thread
From: scott.harrison @ 2010-02-04 11:35 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

All,

We script GDB to attach to our application when it crashes and generate a 
crash report giving lots of valuable information for developers to debug 
the problem.  Before invoking GDB we know the LWPID and the PID so we 
attach to the PID (--pid), however, currently GDB only knows about its own 
threadids, we don't know this before invoking GDB but our script is already 
written, so I have created a small patch to the "thread" command to take a 
%<LWPID> option, and swtich to that thread.  We thought you might be 
interested.

Changelog
---------

2010-02-04  Scott Harrison <scott.harrison@tandberg.com>

	* gdb/thread.c: Add support for LWPID to the thread command.


Patch is attached.  I realise that this patch may not be applicable to all 
platforms that gdb is used on, sorry.

Kind regards,

Scott Harrison

---
TANDBERG Telecom UK Ltd
Registered in England and Wales No: 3390345. Registered address: Unit 2
Pine Trees, Chertsey Lane, Staines, Middlesex, TW18 3HR

[-- Attachment #2: gdb-tid.patch --]
[-- Type: text/plain, Size: 1075 bytes --]

diff -Nru gdb-7.0.1/gdb/thread.c gdb-7.0.1-1/gdb/thread.c
--- gdb-7.0.1/gdb/thread.c	2009-09-13 17:28:28.000000000 +0100
+++ gdb-7.0.1-1/gdb/thread.c	2010-02-03 17:01:26.000000000 +0000
@@ -311,6 +311,18 @@
   return NULL;
 }
 
+struct thread_info *
+find_thread_lwp (int num)
+{
+  struct thread_info *tp;
+
+  for (tp = thread_list; tp; tp = tp->next)
+    if (tp->ptid.lwp == num)
+      return tp;
+
+  return NULL;
+}
+
 /* Find a thread_info by matching PTID.  */
 struct thread_info *
 find_thread_ptid (ptid_t ptid)
@@ -1164,11 +1176,19 @@
 do_captured_thread_select (struct ui_out *uiout, void *tidstr)
 {
   int num;
+  char *tidstring=(char *)tidstr;
   struct thread_info *tp;
 
-  num = value_as_long (parse_and_eval (tidstr));
-
-  tp = find_thread_id (num);
+  if (tidstring[0] == '%')
+  {
+    num = value_as_long (parse_and_eval ((void *)(tidstring+1)));
+    tp = find_thread_lwp (num);
+  }
+  else
+  {
+    num = value_as_long (parse_and_eval (tidstr));
+    tp = find_thread_id (num);
+  }
 
   if (!tp)
     error (_("Thread ID %d not known."), num);

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-02-08  6:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-04 11:35 New feature: allow thread command to take a LWPID scott.harrison
2010-02-04 23:30 ` Tom Tromey
2010-02-05  3:28   ` Joel Brobecker
2010-02-05  9:40     ` scott.harrison
2010-02-05 10:07       ` Joel Brobecker
2010-02-05 10:53     ` Andreas Schwab
2010-02-05 11:49       ` Joel Brobecker
2010-02-05 16:04         ` Tom Tromey
2010-02-08  6:13           ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox