Project

General

Profile

Bug #7258

6951 caused uberdata32_t size to be incorrect

Added by Denis Kozadaev about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Category:
lib - userland libraries
Start date:
2016-08-02
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

I use gdb and dbx to debug programs.
They both use thread_db library to access to the thread system inside a process.
When I debug 32 bits application in 64 bits environment a debugger cannot initialize that library.
witch% uname -a              
SunOS witch 5.11 illumos-1c755ac i86pc i386 i86pc
witch% isainfo -b
64
witch% file rblock.32
rblock.32:      ELF 32-bit LSB executable 80386 Version 1, dynamically linked, not stripped
witch% gdb rblock.32
Reading symbols from rblock.32...done.
(gdb) b main
Breakpoint 1 at 0x8054082: file main.c, line 67.
(gdb) r
Starting program: /home/denis/projects/Register/ipf/2.1/rblock.32 
warning: Cannot initialize thread debugging library: Debugger service failed

Breakpoint 1, main (argc=1, argv=0x8046f80) at main.c:67
67              setlocale(LC_ALL, "");
*skipped*

Now I know the cause (the subject), after two days of deep debugging of gdb I found it.
The bug is in libthread_db.so.1 (linked to libc_db.so.1), in function td_read_uberdata()
http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc_db/common/thread_db.c#150
When a debugger runs a "native" programm, it goes to line 156 after the condition in line 155,
but if I run the same debugger with a 32bits application, it goes to line 173
witch% gdb /usr/bin/amd64/gdb
GNU gdb (GDB) 7.10.1
(gdb) b td_read_uberdata
Function "td_read_uberdata" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (td_read_uberdata) pending.
(gdb) r rblock.32
Starting program: /usr/bin/amd64/gdb rblock.32
[Thread debugging using libthread_db enabled]
Reading symbols from rblock.32...done.
(gdb) b main
Breakpoint 1 at 0x8054082: file main.c, line 67.
(gdb) r
Starting program: /home/denis/projects/Register/ipf/2.1/rblock.32 
[Switching to Thread 1 (LWP 1)]
Breakpoint 1, td_read_uberdata (ta_p=0x2254c20) at ../common/thread_db.c:152
152             struct ps_prochandle *ph_p = ta_p->ph_p;
(gdb) n
155             if (ta_p->model == PR_MODEL_NATIVE) {
(gdb) n
176                     if (ps_pdread(ph_p, ta_p->uberdata_addr,
(gdb) p sizeof(uberdata32_t)
$2 = 10864
(gdb) n
179                     ta_p->primary_map = uberdata.primary_map;
(gdb) n
180                     ta_p->tdb_eventmask_addr = ta_p->uberdata_addr +
(gdb) 
182                     ta_p->tdb_register_sync_addr = ta_p->uberdata_addr +
(gdb) 
184                     ta_p->hash_table_addr = (psaddr_t)uberdata.thr_hash_table;
(gdb) 
185                     ta_p->hash_size = uberdata.hash_size;
(gdb) 
186                     if (ps_pdread(ph_p, (psaddr_t)uberdata.tdb.tdb_events,
(gdb) 
188                             return (TD_DBERR);

And the error occured.
About uberdata_t:
http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc/inc/thr_uberdata.h#923
  • This is data that is global to all link maps (uberdata, aka super-global).
  • Note: When changing this, please be sure to keep the 32-bit variant of
  • this in sync. (see uberdata32_t below)
    KEEP THIS IN SYNC! But bow it is desynced, I don't know why.
    witch% gdb /usr/bin/i86/gdb  
    GNU gdb (GDB) 7.10.1
    (gdb) b td_read_uberdata
    Function "td_read_uberdata" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) y
    Breakpoint 1 (td_read_uberdata) pending.
    (gdb) r rblock.32
    Starting program: /usr/bin/i86/gdb rblock.32
    warning: Cannot initialize thread debugging library: Debugger service failed
    warning: Cannot initialize thread debugging library: Debugger service failed
    GNU gdb (GDB) 7.10.1
    Reading symbols from rblock.32...done.
    (gdb) b main
    Breakpoint 1 at 0x8054082: file main.c, line 67.
    (gdb) r
    Starting program: /home/denis/projects/Register/ipf/2.1/rblock.32 
    Breakpoint 1, td_read_uberdata (ta_p=0x86deae8) at ../common/thread_db.c:152
    152             struct ps_prochandle *ph_p = ta_p->ph_p;
    (gdb) n
    155             if (ta_p->model == PR_MODEL_NATIVE) {
    (gdb) n
    158                     if (ps_pdread(ph_p, ta_p->uberdata_addr,
    (gdb) p sizeof(uberdata_t)
    $1 = 10860
    (gdb)
    

    10860 bytes in native mode (32) vs 10864 bytes in 64 bits mode
    I tried to fix it, so, I did it by a hammer-style ;-)
    I just add attribute(packed)) to the structures uberdata32_t and quickexit_root32_t.
    This "hack" fixed the issue but it is incorrect, studio does not know this attribute.
    I hope you know how to fix it correctly better than me.
    Thank you anyway.
#1

Updated by Robert Mustacchi about 4 years ago

  • Category set to lib - userland libraries
  • Assignee set to Robert Mustacchi
  • Tags deleted (needs-triage)
#2

Updated by Robert Mustacchi about 4 years ago

  • Subject changed from uberdata32_t has different size from uberdata_t to 6951 forgot to update the uberdata32_t

The problem here is that we forgot to update the uberdata32_t as part of the work done on 6951. Packing it doesn't fix it, instead we need to properly define the 32-bit version. I'll get that put together shortly.

#3

Updated by Robert Mustacchi about 4 years ago

  • Subject changed from 6951 forgot to update the uberdata32_t to struct _qexthdlr isn't properly defined in uberdata32_t

The original analysis was spot on and in a rush I misread the struct description. It turns out we need to do the packing here, but just need to use #pragma pack.

#4

Updated by Robert Mustacchi about 4 years ago

  • Subject changed from struct _qexthdlr isn't properly defined in uberdata32_t to 6951 caused uberdata32_t size to be incorrect
#5

Updated by Electric Monk about 4 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit ff892b7ce7155120a08759aeabce0b4cd24bc867

commit  ff892b7ce7155120a08759aeabce0b4cd24bc867
Author: Robert Mustacchi <rm@joyent.com>
Date:   2016-08-25T20:46:03.000Z

    7258 6951 caused uberdata32_t size to be incorrect
    Reviewed by: Dan McDonald <danmcd@omniti.com>
    Approved by: Gordon Ross <gordon.w.ross@gmail.com>

Also available in: Atom PDF