GDB 5.1/Core files and ptids (CONT)

Takis Psarogiannakopoulos takis@XFree86.Org
Sun Jan 20 11:20:00 GMT 2002


On Fri, 18 Jan 2002, Kevin Buettner wrote:

>
> Yep, I agree.  As I pointed out to Takis in an earlier message, I think
> the right way to fix it is to modify both corelow.c on the GDB side
> and elf.c on the bfd side.
>
> My suggestion was that instead of naming sections .reg/PIDLWP where
> PIDLWP is a combined (numeric) pid and lwp identifier that these
> sections instead be named .reg/PID+LWP where PID is the pid and LWP is
> the lwp.
>
> When the LWP doesn't exist or is simply zero, we simply use .reg/PID
> as before.  (Or we could use .reg/PID+0.  It doesn't really matter
> so long as both sides are in agreement.)
>

Hi Kevin, 
Below is a core from omniORB. Take a look. My GDB 5.1 will say:

=========================================================================
(gdb) info threads
* 5 -> PID: 14546 DG/UX Kernel LWP: 4  0x08058b77 in fde_split
                   (linear=0x801de790, erratic=0x801de798) at frame.c:313
  4 -> PID: 14546 DG/UX Kernel LWP: 3  0x801ac4dc in __nsl_accept () from
                                                    /usr/dglib/libnsl.so.1
  3 -> PID: 14546 DG/UX Kernel LWP: 2  0x801d67eb in __dg_kfc () from
                                                 /usr/dglib/libthread.so.1
  2 -> PID: 14546 DG/UX Kernel LWP: 1  0x801d67eb in __dg_kfc () from
                                                 /usr/dglib/libthread.so.1
  1 -> PID: 14546 DG/UX Kernel LWP: 0  0x801d67eb in __dg_kfc () from
                                                 /usr/dglib/libthread.so.1
Current language:  auto; currently c


(gdb) info threads-status 
* 5 -> PID: 14546 DG/UX Kernel LWP: 4
                               eligible,dumping-core,caught-signal,detached
  4 -> PID: 14546 DG/UX Kernel LWP: 3 eligible
  3 -> PID: 14546 DG/UX Kernel LWP: 2  
                               frozen,cond-wait(0x80673c8)-mutex(0x80673a4)
  2 -> PID: 14546 DG/UX Kernel LWP: 1
                             frozen,cond-wait(0x8067334)-mutex(0x8067310)
  1 -> PID: 14546 DG/UX Kernel LWP: 0
                             frozen,cond-wait(0x80177184)-mutex(0x80177160)

(gdb) thread 1
[Switching to thread 1 (-> PID: 14546 DG/UX Kernel LWP: 0)]#0  0x801d67eb
                             in __dg_kfc () from /usr/dglib/libthread.so.1

(gdb) info lwp-status 
 DG/UX Kernel based LWP status space: 
   PID / LWP ID          :      14546 / 0 
   LWP Group ID          :      0
   Last on CPU ID        :      2
   LWP Kernel state      :
   LWP is waiting on the user-level condition variable at
              address 0x80177184, with associated mutex 0x80177160 
   LWP is marked as user frozen and cannot run at user level 
   Stack info            :      NO dedicated stack
   LWP sched is          :      LOCAL
   Sched policy          :      SCHED_OTHER
   Sched priority        :      2047
   Stop-on-store bmaps   : 
   Bit map num 0 is      :      0x0
   Bit map num 1 is      :      0x0
(gdb) quit

=====================================================================

As you can see if we put a conditional 

if ( (elf_tdata (abfd)->core_lwpid) == 0)

inside bfd/elf.c/elfcore_make_ptid_str(abfd) for DG/UX OS at least
we are loosing a thread. Below is what I worked out for GDB 5.1.
It will patch elf.c and corelow.c. according to your suggestions.
If this is acceptable someone should check it in at least for
the upcoming GDB 5.x.x.

=====================================================================

diff -rcN /target/GDB/gdb-5.1/bfd/elf.c gdb-5.1/bfd/elf.c
*** /target/GDB/gdb-5.1/bfd/elf.c       Sun Jan 20 16:54:02 2002
--- gdb-5.1/bfd/elf.c   Sat Jun 30 04:05:12 2001
***************
*** 5349,5365 ****
          + (elf_tdata (abfd)->core_pid));
  }

- static char *
- elfcore_make_ptid_str (abfd)
-      bfd *abfd;
- {
-    static char ptid_buf[40];
-
-    sprintf (ptid_buf, "%d+%ld", (elf_tdata (abfd)->core_pid),
-                       (elf_tdata (abfd)->core_lwpid) );
-    return ptid_buf;
- }
-
  /* If there isn't a section called NAME, make one, using
     data from SECT.  Note, this function will generate a
     reference to NAME, so you shouldn't deallocate or
--- 5349,5354 ----
***************
*** 5391,5398 ****
     actually creates up to two pseudosections:
     - For the single-threaded case, a section named NAME, unless
       such a section already exists.
!    - For the multi-threaded case, a section named "NAME/PID+LWPID",
where
!      PID is prepared by elfcore_make_ptid_str (abfd).
     Both pseudosections have identical contents. */
  boolean
  _bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
--- 5380,5387 ----
     actually creates up to two pseudosections:
     - For the single-threaded case, a section named NAME, unless
       such a section already exists.
!    - For the multi-threaded case, a section named "NAME/PID", where
!      PID is elfcore_make_pid (abfd).
     Both pseudosections have identical contents. */
  boolean
  _bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
***************
*** 5407,5413 ****

    /* Build the section name.  */

!   sprintf (buf, "%s/%s", name, elfcore_make_ptid_str (abfd));
    threaded_name = bfd_alloc (abfd, strlen (buf) + 1);
    if (threaded_name == NULL)
      return false;
--- 5396,5402 ----

    /* Build the section name.  */

!   sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd));
    threaded_name = bfd_alloc (abfd, strlen (buf) + 1);
    if (threaded_name == NULL)
      return false;
***************
*** 5699,5705 ****

    /* Make a ".reg/999" section.  */

!   sprintf (buf, ".reg/%s", elfcore_make_ptid_str (abfd));
    name = bfd_alloc (abfd, strlen (buf) + 1);
    if (name == NULL)
      return false;
--- 5688,5694 ----

    /* Make a ".reg/999" section.  */

!   sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
    name = bfd_alloc (abfd, strlen (buf) + 1);
    if (name == NULL)
      return false;
***************
*** 5728,5734 ****

    /* Make a ".reg2/999" section */

!   sprintf (buf, ".reg2/%s", elfcore_make_ptid_str (abfd));
    name = bfd_alloc (abfd, strlen (buf) + 1);
    if (name == NULL)
      return false;
--- 5717,5723 ----

    /* Make a ".reg2/999" section */

!   sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd));
    name = bfd_alloc (abfd, strlen (buf) + 1);
    if (name == NULL)
      return false;
diff -rcN /target/GDB/gdb-5.1/gdb/corelow.c gdb-5.1/gdb/corelow.c
*** /target/GDB/gdb-5.1/gdb/corelow.c   Sun Jan 20 17:00:59 2002
--- gdb-5.1/gdb/corelow.c       Tue May 15 00:03:36 2001
***************
*** 234,262 ****
  static void
  add_to_thread_list (bfd *abfd, asection *asect, PTR reg_sect_arg)
  {
!   int p_id, count;
!   long t_id;
    asection *reg_sect = (asection *) reg_sect_arg;

    if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
      return;

!   count = sscanf(bfd_section_name (abfd, asect), ".reg/%d+%ld", &p_id,
&t_id);

! #if defined(DEBUG)
!   if ( count == 2 )
!     printf("Adding thread PID=%d+LWPID=%ld \n", p_id, t_id);
!   else if ( count == 1)
!     printf("Adding thread PID=%d+LWPID=? not found lwpid\n", p_id);
! #endif /* DEBUG */
!
!   add_thread ( ptid_build (p_id, t_id, 0) );

  /* Warning, Will Robinson, looking at BFD private data! */

    if (reg_sect != NULL
        && asect->filepos == reg_sect->filepos) /* Did we find .reg? */
!     inferior_ptid = ptid_build (p_id, t_id, 0);       /* Yes, make it
current */
  }

  /* This routine opens and sets up the core file bfd.  */
--- 234,254 ----
  static void
  add_to_thread_list (bfd *abfd, asection *asect, PTR reg_sect_arg)
  {
!   int thread_id;
    asection *reg_sect = (asection *) reg_sect_arg;

    if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
      return;

!   thread_id = atoi (bfd_section_name (abfd, asect) + 5);

!   add_thread (pid_to_ptid (thread_id));

  /* Warning, Will Robinson, looking at BFD private data! */

    if (reg_sect != NULL
        && asect->filepos == reg_sect->filepos) /* Did we find .reg? */
!     inferior_ptid = pid_to_ptid (thread_id);  /* Yes, make it current */
  }

  /* This routine opens and sets up the core file bfd.  */
***************
*** 415,422 ****
    char *contents;

    if (PIDGET (inferior_ptid))
!       sprintf (section_name, "%s/%d+%ld", name,
!               PIDGET(inferior_ptid), TIDGET(inferior_ptid) );
    else
      strcpy (section_name, name);

--- 407,413 ----
    char *contents;

    if (PIDGET (inferior_ptid))
!     sprintf (section_name, "%s/%d", name, PIDGET (inferior_ptid));
    else
      strcpy (section_name, name);

========================================================================










More information about the Binutils mailing list