[RFC] make gdb handle weak function better

Hui Zhu
2010-08-05T09:04:11Z

Hi,

I meet following trouble:
cat 1.c
int
main ()
{
calloc (3, 1);
}
gcc -g 1.c
gdb ./a.out
(gdb) start
Temporary breakpoint 1 at 0x8048385: file 1.c, line 4.
Starting program: /home/teawater/gdb/bgdbno/gdb/a.out

Temporary breakpoint 1, main () at 1.c:4
4 calloc (3, 1);
(gdb) b calloc
During symbol reading, incomplete CFI data; unspecified registers
(e.g., eax) at 0x8048382.
Breakpoint 2 at 0xb7ff82a6
(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0xb7fe47f0 0xb7ff97df Yes (*) /lib/ld-linux.so.2
0xb7e80230 0xb7f80ea4 Yes (*) /lib/tls/i686/cmov/libc.so.6
(*): Shared library is missing debugging information.
(gdb) c
Continuing.

Program exited with code 010.

The inferior is not break because gdb set breakpoint in the weak
function calloc in lib/ld-linux.so.2.
But the inferior call the calloc in /lib/tls/i686/cmov/libc.so.6.

And I check the lookup_symbol and lookup_minimal_symbol, both of them
are return the first symbol that they found.
What about do some work on it?

What I think is:
In lookup_symbol and lookup_minimal_symbol, when it get a weak symbol,
just record it but keep search. When the search complete, if GDB get
a simple symbol then return it. If GDB doesn't get a simple symbol.
Then return the weak symbol.

BTW, looks minimal_symbol and symbol don't have interface access to
asymbol. So I suggest we can extend "struct general_symbol_info" and
elf_symtab_read to make minimal_symbol and symbol have the weak
message.

Thanks,
Hui