Help w/ gdb
I read the "Help w/ gdb" thread and I have found that one of the proposed solutions solves one problem that I had on LinuxPPC R5:
I recompiled my small example program with -gdwarf-2 (and gcc 2.95.2) instead of just -g and then I was able to step into the shared library function call correctly.
Kevin Buettner, suggested this fix last month in
http://lists.linuxppc.org/listarcs/linuxppc-dev/200001/msg00245.html
However, the problem persists in a different form when I try the fix with a larger program and larger library (compiled with gcc 2.95.2 with -fPIC and -gdwarf-2). In gdb, I want to step into the statement
return ((int (*) (void)) functionPtrs[0])();
and I end up with this:
0xfd1859c in InitInterfaceCorrection ()
at/usr/local/lib/gcc-lib/powerpc-unknown-linux-gnu/2.95.2/../../../../include/g++-3/stl_alloc.h:518
518 return(_S_chunk_alloc(__size, __nobjs));
If I then give the "next" command, the program continues until it exits. InitInterfaceCorrection() is the correct function name. Its first statement is:
int error = InitInterfaceCorrection_X(NULL, NULL);
Here is the bug report I sent to the GDB mailing list on 21 Jan 2000, which includes the example program. Note however that since then I have upgraded to gcc/g++ 2.95.2.
I am still using gdb 4.17.0.11 (which came with LinuxPPC R5).
===========================================================================
GDB does not step correctly into a runtime-loaded function under LinuxPPC R5. The problem does not occur under RedHat 5.2 on a Pentium.
The Power Macintosh has the following characterics:
- kernel 2.2.6-15apmac #1 Mon May 31 03:54:09 EDT 1999
- /lib/libc-2.1.1.so
- GNU gdb 4.17.0.11
- gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
Here is the main program (prog.c):
---------------------------------------------------------------------------
#include <assert.h>
#include <stddef.h>
#include <dlfcn.h>
int main(int argc, char *argv[])
{
void *handle;
void (*function)(void);
handle = dlopen("./libfoo.so", RTLD_NOW);
assert(handle != NULL);
function = dlsym(handle, "library_function");
assert(dlerror() == NULL && function != NULL);
(*function)();
dlclose(handle);
return 0;
}---------------------------------------------------------------------------
Here is the library source file (libfoo.c):
---------------------------------------------------------------------------
#include <stdio.h>
void library_function(void)
{
printf("This is library_function()\n");
printf("--------------------------\n");
}---------------------------------------------------------------------------
Here is the Makefile:
---------------------------------------------------------------------------
CFLAGS=-fPIC -g -Wall
all: libfoo.so prog
libfoo.so: libfoo.o
gcc -shared libfoo.o -o libfoo.so
libfoo.o: libfoo.c
gcc $(CFLAGS) -c libfoo.c
prog: prog.o
gcc -rdynamic -o prog prog.o -ldl
prog.o: prog.c
gcc $(CFLAGS) -c prog.c
clean:
rm -f prog lib*.so *.o core
---------------------------------------------------------------------------
The program executes fine by itself, as well as in GDB without breakpoints.
Here is the scenario. I enter GDB and set a breakpoint on this line of prog.c:
(*function)();
Then I run the program and GDB stops on that line. I give the "step" command and get this:
---------------------------------------------------------------------------
(gdb) break 15
Breakpoint 1 at 0x1800734: file prog.c, line 15. (gdb) run
Starting program: /home/sarrazip/pgm/bug-gdb-dll/prog
Breakpoint 1, main (argc=1, argv=0x7ffffbd4) at prog.c:15
15 (*function)();
(gdb) step0x161a61c in library_function () at libfoo.c:7
7 }
(gdb) next
This is library_function()
--------------------------
main (argc=1, argv=0x7ffffbd4) at prog.c:17
17 dlclose(handle);
(gdb)
---------------------------------------------------------------------------
On a Pentium machine running RedHat Linux 5.2, the "step" works fine:
it stops on line 5 of libfoo.c, i.e., the first printf() statement. This Pentium machine has the following characteristics:
- kernel 2.0.36 #1 Tue Oct 13 22:17:11 EDT 1998
- /lib/libc-2.0.7.so
- GNU gdb 4.17.0.4
- gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
--
Pierre Sarrazin <[email protected]>
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 3 lines · Pierre Sarrazin
However, the problem persists in a different form when I try the fix with a larger program and larger library (compiled with gcc 2.95.2 with -fPIC and -gdwarf-2).
Pierre,
Thanks for the report.
It is quite timely because this week I'm working on integrating linux/ppc support into the gdb cvs repository at sourceware.cygnus.com.
I'll try your example program once I get farther along.
Thanks again,
Kevin
--
Kevin Buettner
[email protected], [email protected]
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
On Feb 16, 2:11pm, Pierre Sarrazin wrote:
[lots of stuff snipped]
Quoted 17 lines
The program executes fine by itself, as well as in GDB without breakpoints.
Here is the scenario. I enter GDB and set a breakpoint on this line of
prog.c:(*function)();Then I run the program and GDB stops on that line. I give the "step" command and get this:
---------------------------------------------------------------------------
(gdb) break 15
Breakpoint 1 at0x1800734: fileprog.c, line 15. (gdb) run
Starting program:/home/sarrazip/pgm/bug-gdb-dll/prog
Quoted 12 lines
Breakpoint 1, main (argc=1, argv=0x7ffffbd4) at prog.c:15
15 (*function)();
(gdb) step0x161a61cinlibrary_function() at libfoo.c:7
7 }
(gdb) next
This islibrary_function()
--------------------------
main (argc=1, argv=0x7ffffbd4) at prog.c:17
17 dlclose(handle);
(gdb)
---------------------------------------------------------------------------
Pierre,
Thanks for including the program and detailed bug report. I mentioned in earlier email that I was merging the patches for linux/ppc gdb into the current sourcebase. I am happy to report that this merge is complete and that the source may be downloaded from the sourceware site. See
http://sourceware.cygnus.com/gdb
for more information. Franz Sirl has also created an RPM from sources earlier in the week and placed it in
ftp://devel.linuxppc.org/users/fsirl/
(I'm not sure if his sources contain my most recent shared library fixes though.)
Anyway, when I run your program, I'm now seeing the following (correct, I believe) output:
GNU gdb 20000204
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-unknown-linux-gnu"...
(gdb) b 15
Breakpoint 1 at 0x1800734: file prog.c, line 15.
(gdb) r
Starting program: /home/kev/ctests/pierre/prog
Breakpoint 1, main (argc=1, argv=0x7ffffd54) at prog.c:15
15 (*function)();
(gdb) s
library_function () at libfoo.c:5
5 printf("This is library_function()\n");
(gdb) next
This is library_function()
6 printf("--------------------------\n");
(gdb) next
--------------------------
7 }
(gdb) next
main (argc=1, argv=0x7ffffd54) at prog.c:17
17 dlclose(handle);Kevin
--
Kevin Buettner
[email protected], [email protected]
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/