Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Make linux native always have at least one thread
Date: Mon, 24 Mar 2008 20:54:00 -0000	[thread overview]
Message-ID: <200803242054.39769.pedro@codesourcery.com> (raw)

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

The non-stop mode requires gdb to always have a thread in
the thread list, so we can use the new non-stop MI options
on it.  In ST programs, the main thread should be listed as
the single thread in the thread list.  Currently, when
debugging a single-threaded application in native linux,
"info threads" comes out empty.

Ideally, every platform should do this, so we can get rid
of a lot of weird ugly code to work around that fact
(state is stored and swapped between plain old global
variables, and struct thread_info, struct execution_control_state,
and struct inferior_status depending on what gdb is doing).

Daniel recently made this fix very simple, by removing
the tid component of a thread_db thread off of the
ptid of each thread.

So, this patch closes the issue for linux native.

Tested on x86_64-unknown-linux-gnu.

OK?

-- 
Pedro Alves

[-- Attachment #2: linux_always_have_a_thread.diff --]
[-- Type: text/x-diff, Size: 1970 bytes --]

2008-01-24  Pedro Alves  <pedro@codesourcery.com>

	* linux-nat.c (linux_nat_attach): Add the pid we attached to, to
	gdb's thread list.
	(linux_nat_wait): Add main lwp to gdb's thread list.
	* linux-thread-db.c (find_new_threads_callback): Also attach to
	already listed threads which thread_db didn't know about yet.

---
 gdb/linux-nat.c       |    6 ++++++
 gdb/linux-thread-db.c |    4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c	2008-03-24 20:42:25.000000000 +0000
+++ src/gdb/linux-nat.c	2008-03-24 20:47:11.000000000 +0000
@@ -1173,6 +1173,10 @@ linux_nat_attach (char *args, int from_t
   lp = add_lwp (inferior_ptid);
   lp->cloned = cloned;
 
+  /* If this process is not using thread_db, then we still don't
+     detect any other threads, but add at least this one.  */
+  add_thread_silent (lp->ptid);
+
   lp->stopped = 1;
   lp->resumed = 1;
 
@@ -2387,6 +2391,8 @@ linux_nat_wait (ptid_t ptid, struct targ
 				 GET_PID (inferior_ptid));
       lp = add_lwp (inferior_ptid);
       lp->resumed = 1;
+      /* Add the main thread to GDB's thread list.  */
+      add_thread_silent (lp->ptid);
     }
 
   sigemptyset (&flush_mask);
Index: src/gdb/linux-thread-db.c
===================================================================
--- src.orig/gdb/linux-thread-db.c	2008-03-24 20:42:25.000000000 +0000
+++ src/gdb/linux-thread-db.c	2008-03-24 20:42:29.000000000 +0000
@@ -918,6 +918,7 @@ find_new_threads_callback (const td_thrh
   td_thrinfo_t ti;
   td_err_e err;
   ptid_t ptid;
+  struct thread_info *tp;
 
   err = td_thr_get_info_p (th_p, &ti);
   if (err != TD_OK)
@@ -945,7 +946,8 @@ find_new_threads_callback (const td_thrh
       return 0;
     }
 
-  if (!in_thread_list (ptid))
+  tp = find_thread_pid (ptid);
+  if (tp == NULL || tp->private == NULL)
     attach_thread (ptid, th_p, &ti);
 
   return 0;

             reply	other threads:[~2008-03-24 20:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-24 20:54 Pedro Alves [this message]
2008-03-24 22:50 ` Daniel Jacobowitz
2008-03-25 12:33   ` Pedro Alves
2008-03-25 12:40     ` Daniel Jacobowitz

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=200803242054.39769.pedro@codesourcery.com \
    --to=pedro@codesourcery.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