Bug 634660

Summary: "heap" command sometimes not available
Product: [Fedora] Fedora Reporter: Dave Malcolm <dmalcolm>
Component: gdbAssignee: Jan Kratochvil <jan.kratochvil>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 14CC: dmalcolm, jan.kratochvil, pmuldoon
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: gdb-7.2-16.fc14 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-10-05 09:15:39 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Dave Malcolm 2010-09-16 12:20:13 EDT
Description of problem:
I tried attaching to gedit, but "heap" was not available; the hooks were not autoloaded

"Reading symbols from /lib64/libc.so.6...Reading symbols from /usr/lib/debug/lib64/libc-2.12.90.so.debug...done."
whereas my hooks are in: /usr/share/gdb/auto-load/lib64/ld-2.12.90.so-gdb.py
do we need them in both?  or to be moved?

Version-Release number of selected component (if applicable):
gdb-heap-0.5-1.fc14.x86_64

How reproducible:
100%

Steps to Reproduce:
  $ gedit&
  $ gdb attach $(pidof -x gedit)
  (gdb) heap
  
Actual results:
Undefined command: "heap".  Try "help".

Expected results:
Report on heap usage within gdb process

Additional info:
Seems to locate when invoked in this form:
  $ gedit
  (gdb) run
  CtrlC
  (gdb) heap
Comment 1 Dave Malcolm 2010-09-21 19:02:28 EDT
libc.so.6 contains numerous malloc-related symbols:

$ eu-readelf -s /lib64/libc.so.6|grep malloc|wc -l
50

and contains "main_arena".

$ eu-readelf -s /lib64/libc.so.6|grep main_arena
 1118: 00000032ccd8b180   2184 OBJECT  LOCAL  DEFAULT       34 main_arena


ld-2.12.90.so contains just two "malloc" functions, which are marked as "WEAK":
$ eu-readelf -s /lib64/ld-2.12.90.so|grep malloc
   23: 00000032cc615fe0     13 FUNC    WEAK   DEFAULT       11 malloc@@GLIBC_2.2.5
  470: 00000032cc615fe0     13 FUNC    WEAK   DEFAULT       11 malloc

and does not contain "main_arena".


Looks like I should be autoloading the code based on whether libc.so is loaded, not ld.
Comment 2 Dave Malcolm 2010-09-21 19:26:14 EDT
I tried fixing this on a F14 x86_64 vm, but it didn't work.

I tried moving the hook for this code:
  /usr/share/gdb/auto-load/lib64/ld-2.12.90.so-gdb.py
to:
  /usr/share/gdb/auto-load/lib64/libc.so.6-gdb.py
and to 
  /usr/share/gdb/auto-load/lib64/libc-2.19.90.so-gdb.py

but in each case no autoloading occurred when attaching to a "gedit" process.

$ strace gdb attach $(pidof -x gedit) 2>&1 | grep gdb.py
shows very few files being autoloaded.

gdb folks: any ideas why:
  $ gedit &
  $ gdb attach $(pidof -x gedit)
wouldn't have gdb try to autoload -gdb.py files for the various DSOs making up the gedit process?

(reassigning to "gdb" for advice on the above; feel free to reassign back to "gdb-heap")
Comment 3 Jan Kratochvil 2010-09-22 04:35:46 EDT
It works for spawned executables but not for attached executables.
gdbpy_global_auto_load is temporarily suppressed there.
Comment 4 Jan Kratochvil 2010-09-22 05:27:48 EDT
Upstream post:
[patch] python: load *-gdb.py for shlibs during attach
http://sourceware.org/ml/gdb-patches/2010-09/msg00365.html
Comment 5 Fedora Update System 2010-09-22 05:28:53 EDT
gdb-7.2-7.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/gdb-7.2-7.fc14
Comment 6 Dave Malcolm 2010-09-22 11:15:33 EDT
I was using gdb-7.2-3.fc14.x86_64

Trying new gdb: gdb-7.2-7.fc14.x86_64

strace on the new gdb confirms that it's trying to load -gdb.py files for the
various dynamically-loaded DSOs.  Thanks!

As it happens, the test case above now works, in that "ld" is linked into any
process using libc, so this happens to also fix the gdb-heap issue described in
comment #0.

In particular, it tried to load:
  /usr/lib/debug/lib64/libc-2.12.90.so.debug-gdb.py
  /usr/lib/debug/usr/lib/debug/lib64/libc-2.12.90.so.debug-gdb.py
  /usr/share/gdb/auto-load/usr/lib/debug/lib64/libc-2.12.90.so.debug-gdb.py
  /lib64/libc-2.12.90.so-gdb.py
  /usr/lib/debug/lib64/libc-2.12.90.so-gdb.py
  /usr/share/gdb/auto-load/lib64/libc-2.12.90.so-gdb.py

The last of these seems like the most appropriate place for my hooks.

But given that it's also loading relative to "ld.so", this works, without
needing to change gdb-heap.

Marking as VERIFIED.
Comment 7 Fedora Update System 2010-09-22 14:43:18 EDT
gdb-7.2-7.fc14 has been pushed to the Fedora 14 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update gdb'.  You can provide feedback for this update here: https://admin.fedoraproject.org/updates/gdb-7.2-7.fc14
Comment 8 Fedora Update System 2010-09-25 10:12:26 EDT
gdb-7.2-12.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/gdb-7.2-12.fc14
Comment 9 Fedora Update System 2010-09-27 11:29:14 EDT
gdb-7.2-15.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/gdb-7.2-15.fc14
Comment 10 Fedora Update System 2010-09-28 19:57:51 EDT
gdb-7.2-16.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/gdb-7.2-16.fc14
Comment 11 Fedora Update System 2010-10-05 09:15:25 EDT
gdb-7.2-16.fc14 has been pushed to the Fedora 14 stable repository.  If problems still persist, please make note of it in this bug report.