Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: scott.harrison@tandberg.com
To: gdb-patches@sourceware.org
Subject: New feature: allow thread command to take a LWPID.
Date: Thu, 04 Feb 2010 11:35:00 -0000	[thread overview]
Message-ID: <20100204113543.GB2704@tandberg.com> (raw)

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

             reply	other threads:[~2010-02-04 11:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-04 11:35 scott.harrison [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100204113543.GB2704@tandberg.com \
    --to=scott.harrison@tandberg.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox