Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Nathan J. Williams" <nathanw@wasabisystems.com>
To: Marcel Moolenaar <marcel@xcllnt.net>
Cc: Joel Brobecker <brobecker@gnat.com>,
	Andrew Cagney <cagney@gnu.org>,
	gdb-patches@sources.redhat.com
Subject: Re: thread ptids when debugging from core file (x86-linux)
Date: Fri, 06 Aug 2004 19:10:00 -0000	[thread overview]
Message-ID: <mtullgsaxqb.fsf@contents-vnder-pressvre.mit.edu> (raw)
In-Reply-To: <20040806180811.GA25829@dhcp50.pn.xcllnt.net>

Marcel Moolenaar <marcel@xcllnt.net> writes:

> On Fri, Aug 06, 2004 at 10:58:18AM -0700, Joel Brobecker wrote:
> > > >I've always assumed that corelow.c's mapping between .reg sections and
> > > >threads was intended as a minimal fallback. The module I wrote for
> > > >NetBSD's threads (which I'll get into shape for the FSF tree Real Soon
> > > >Now) punts that list and generates its own list of threads from the
> > > >memory structures of libpthread in the core file, just as it would for
> > > >a live process.
> > > 
> > So do you think I'll have to dig into the inferior memory for data used
> > by the libpthread library to find that information? Is this something
> > that would be portable across NPTL versions? Supposing we want to go
> > that route, does anybody know where to find some documentation (or some
> > code) that exposes the data structures, so I can try digging into them?
> 
> [not strictly Linux, but more genericly]
> 
> But how do you map register contents in the various .reg/# sections to
> the right thread if there's no way to correlate .reg/# sections to light-
> weight processes? Would this in fact imply that the IDs needs to match?

The Linux thread code (thread-db.c) already knows how to poke around
in memory and find all the threads. That memory also includes the
thread-to-LWP mapping, in some form. The trick is getting the process
callbacks in proc-service.c to look up registers of LWPs in the
matching core file section. Here's the getregs callback in
nbsd-thread.c:

nbsd_thread_proc_getregs (void *arg, int regset, int lwp, void *buf)
{
  struct cleanup *old_chain;
  int ret;

  old_chain = save_inferior_ptid ();
  
  if (target_has_execution)
    {
      inferior_ptid = BUILD_LWP (lwp, main_ptid);
      child_ops.to_fetch_registers (-1);
    }
  else
    {
      inferior_ptid = pid_to_ptid ((lwp << 16) | GET_PID (main_ptid));
      orig_core_ops.to_fetch_registers (-1);
    }

  ret = 0;
  switch (regset)
    {
    case 0:
      fill_gregset ((gregset_t *)buf, -1);
      break;
    case 1:
      fill_fpregset ((fpregset_t *)buf, -1);
      break;
    default: /* XXX need to handle other reg sets: SSE, AltiVec, etc. */
      ret = TD_ERR_INVAL;
    }

  do_cleanups (old_chain);
}

On Solaris and NetBSD, the .reg/NNN sections have NNN values equal to
PID + (LWPID << 16), so it's straightforward to map from a LWP to a
core section. I'm not sure how Linux names them.

It also helps to use init_thread_list() to blow away the list that
corelow.c generates.

        - Nathan


  parent reply	other threads:[~2004-08-06 19:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-06  4:10 Joel Brobecker
2004-08-06  4:40 ` Nathan J. Williams
2004-08-06  5:39   ` Andrew Cagney
2004-08-06 17:58     ` Joel Brobecker
2004-08-06 18:08       ` Marcel Moolenaar
2004-08-06 18:35         ` Joel Brobecker
2004-08-06 19:10         ` Nathan J. Williams [this message]
2004-08-06 20:53           ` Marcel Moolenaar
2004-08-06 19:18       ` Andrew Cagney

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=mtullgsaxqb.fsf@contents-vnder-pressvre.mit.edu \
    --to=nathanw@wasabisystems.com \
    --cc=brobecker@gnat.com \
    --cc=cagney@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=marcel@xcllnt.net \
    /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