简体   繁体   中英

Debugging gdb - listing source directories in use

Trying to debug an ada program, gdb doesn't seem to be able to locate a source. I did confirm that the running executable was the same one that was just built. Upon attach, it displays the following in the console, when instead it should take me to the current location in the source code:

(gdb) attach 804 
0x0000003de620b68c in ?? ()
(gdb) frame 1
#1  0x0000000000000000 in ?? ()
(gdb) frame 0
#0  0x0000003de620b68c in ?? ()

Is there a way to get the gdb to tell me which source directories it is using? Or is there another way I can troubleshoot this issue?

I am launching this out of GPS 2017 (20170515) hosted on x86_64-pc-linux-gnu GNAT Pro 6.4.2 (20110614-45).

It seems that you have not given gdb the symbol table or your program is stripped.

When you attach to a program, you should tell gdb what executable you attach so that it reads the symbol table. You should have compiled your program with -g (debugging support) and make sure the link pass does not strip symbols. Then, run gdb as follows:

gdb myprog -p 804

But you can also run without attaching (which is whay you did) and then attach.

gdb myprog
GNU gdb (GDB) 7.10 for GNAT GPL 2017 [rev=gdb-7.10-ref-199-g7cfc608]
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
See your support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty for this version of GDB.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from prog...done.
(gdb) attach 804

You can also use the symbol-file command to tell gdb what program file to run:

(gdb) symbol-file myprog
Reading symbols from myprog...done.

If your program is stripped, gdb will print

Reading symbols from prog...(no debugging symbols found)...done.

Having your symbol table read, you can list the source files that are recognized by gdb by using info sources command. This tells you the source files that have been identified in the symbol table.

(gdb) info sources
Source files for which symbols have been read in:

.../b__myprog.adb, 
.../b__myprog.ads, 
/build/eglibc-SvCtMH/eglibc-2.19/elf/rtld.c, 
/build/eglibc-SvCtMH/eglibc-2.19/elf/../sysdeps/generic/_itoa.h, 
/build/eglibc-SvCtMH/eglibc-2.19/elf/../sysdeps/unix/sysv/linux/dl-osinfo.h, 
...

Another interesting command you may use is info files . This tells you the program sections that have been identified with the associated symbol file. If you have dynamic libraries, you should also see them there.

(gdb) info files
Symbols from "myprog".
Native process:
    Using the running image of child Thread 0x7ffff7fb4780 (LWP 32214).
    While running this, GDB does not access memory from...
Local exec file:
    `myprog', file type elf64-x86-64.
    Entry point: 0x40ac5e
    0x0000000000400238 - 0x0000000000400254 is .interp
    0x0000000000400254 - 0x0000000000400274 is .note.ABI-tag
    0x0000000000400278 - 0x0000000000400cb4 is .hash
    0x0000000000400cb8 - 0x0000000000403148 is .dynsym
    0x0000000000403148 - 0x00000000004046b5 is .dynstr
    0x00000000004046b6 - 0x00000000004049c2 is .gnu.version
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM