Project

General

Profile

Actions

Feature #8344

closed

libc ulwp walker should use CTF for uberdata offsets

Added by Robert Mustacchi almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
mdb - modular debugger
Start date:
2017-06-05
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

At present, the ulwp (aka ulwps) walker in mdb uses the OFFSETOF() macro to locate the all_lwps pointer within the uberdata_t. Unfortunately, this member has changed offset at least once in recent history – from 0x295c to 0x29dc.

We should attempt to use the CTF which is invariably present in libc.so.1 to determine what this offset is, and only use the compile-time value as a fallback. As this module is Private, we should use mdb_ctf_offsetof() here.

Actions #1

Updated by Robert Mustacchi almost 6 years ago

For testing, Jason found a couple old cores that current mdb seems unhappy with (using ::uberdata just to illustrate that the built-in offsets are obviously wrong for this core):

[root@c1748f12-9915-67d4-a625-a1a41dd84898 ~]# mdb core.34733
mdb: failed to initialize //lib/libc_db.so.1: libthread_db call failed unexpectedly
mdb: warning: debugger will only be able to examine raw LWPs
Loading modules: [ libc.so.1 ld.so.1 ]
> ::uberdata
libc.so.1`_uberdata:
           &link_lock            &ld_lock              &fork_lock
+0x0       0xfeefa1c0            0xfeefa200            0xfeefa240
           &atfork_lock          &callout_lock         &tdb_hash_lock
+0xc0      0xfeefa280            0xfeefa2c0            0xfeefa2e0
 ...
           ulwp_one              all_lwps              all_zombies
+0x2a78    <NULL>                <NULL>                0xfeedfd3e
           nthreads   nzombies   ndaemons   pid
+0x2a84    -17957550  -17957534  -17957510  -17957497
...
> ::walk ulwp
>

With new libc.so:

[root@c1748f12-9915-67d4-a625-a1a41dd84898 ~]# mdb -L /home/build/smartos-live/proto/usr/lib/mdb/proc core.34733
mdb: failed to initialize //lib/libc_db.so.1: libthread_db call failed unexpectedly
mdb: warning: debugger will only be able to examine raw LWPs
Loading modules: [ libc.so.1 ld.so.1 ]
> ::walk ulwp
0xfed42a40
>
(other window -- verify it's using the new lib)
[root@c1748f12-9915-67d4-a625-a1a41dd84898 ~]# pldd `pgrep mdb`
22647:    mdb -L /home/build/smartos-live/proto/usr/lib/mdb/proc core.34733
/usr/bin/i86/mdb
/lib/libumem.so.1
/usr/lib/libdisasm.so.1
/proc/52439/object/ufs.36.64.12234
/lib/libctf.so.1
/lib/libcurses.so.1
/usr/lib/libkvm.so.1
/lib/libproc.so.1
/lib/librtld_db.so.1
/lib/libelf.so.1
/usr/lib/libzonecfg.so.1
/lib/libxml2.so.2
/lib/libz.so.1
/lib/libm.so.2
/lib/libsocket.so.1
/lib/libnsl.so.1
/lib/libpthread.so.1
/usr/lib/libgcc_s.so.1
/lib/libuuid.so.1
/lib/libc_db.so.1
/home/build/smartos-live/proto/usr/lib/mdb/proc/libc.so
/lib/libavl.so.1
/home/build/smartos-live/proto/usr/lib/mdb/proc/ld.so

A current system:

[root@c1748f12-9915-67d4-a625-a1a41dd84898 ~]# mdb -p 52439
Loading modules: [ libumem.so.1 libc.so.1 libuutil.so.1 libavl.so.1 libnvpair.so.1 ]
> ::walk ulwp
0xfedf2a40
0xfe790240
0xfe790a40
0xfe791240
0xfe791a40
0xfe792240
0xfe793240
0xfe793a40
0xfe794240
0xfe794a40
0xfe795240
0xfe795a40
0xfe796240
0xfe796a40
0xfe797240
0xfe797a40
0xfe798240
0xfe798a40
0xfe799240
0xfe799a40
0xfe79a240
0xfe79aa40
0xfe79b240
0xfe79ba40
0xfe79c240
0xfe79ca40
0xfe79d240
0xfe79e240
>
[root@c1748f12-9915-67d4-a625-a1a41dd84898 ~]#  mdb -L /home/build/smartos-live/proto/usr/lib/mdb/proc -p 52439
Loading modules: [ libumem.so.1 libuutil.so.1 libavl.so.1 libnvpair.so.1 ]
> ::load libc.so
> ::walk ulwp
0xfedf2a40
0xfe790240
0xfe790a40
0xfe791240
0xfe791a40
0xfe792240
0xfe793240
0xfe793a40
0xfe794240
0xfe794a40
0xfe795240
0xfe795a40
0xfe796240
0xfe796a40
0xfe797240
0xfe797a40
0xfe798240
0xfe798a40
0xfe799240
0xfe799a40
0xfe79a240
0xfe79aa40
0xfe79b240
0xfe79ba40
0xfe79c240
0xfe79ca40
0xfe79d240
0xfe79e240
>

Also ran the same tests from a platform image built with the change with similar results (though no -L needed – as expected – for successful ::walk ulwp with same core files that don't work on current platform)

Actions #2

Updated by Electric Monk almost 6 years ago

  • Status changed from New to Closed

git commit e0ee3ced1741d2c52b01a4527f8504cb24701b58

commit  e0ee3ced1741d2c52b01a4527f8504cb24701b58
Author: Jason King <jason.king@joyent.com>
Date:   2017-06-22T18:49:43.000Z

    8344 libc ulwp walker should use CTF for uberdata offsets
    Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
    Reviewed by: Hans Rosenfeld <hans.rosenfeld@joyent.com>
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
    Approved by: Richard Lowe <richlowe@richlowe.net>

Actions

Also available in: Atom PDF