New feature: allow thread command to take a LWPID.

scott.harrison
2010-02-04T11:35:56Z

[-- 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);