Prev: C++ code to read a binary file larger than 2GB on a 32-bit system?
Next: About some snippet on APUE
From: Zach on 3 Nov 2007 18:24 I compiled a game client and it crashed (segmentation fault) resulting in a core file being generated. I'm trying to find out exactly what caused it to crash. Any ideas how I can do this with gdb? In the Makefile can I just add a "-g" flag to have the binary produced with debugging symbols? The source is written in ANSI C. This is what I have now: "CC = gcc" The client binary is 433680 and the core file produced when it crashed is almost double that, it's 860160. Here is what I've done so far: 1]+ Segmentation fault (core dumped) ./netrek zu22(a)netrek:~/netrek/cow/build$ file core core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4- style zu22(a)netrek:~/netrek/cow/build$ gdb ./netrek core GNU gdb 6.6.90.20070912-debian Copyright (C) 2007 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. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu"... Using host libthread_db library "/lib/libthread_db.so.1". warning: Can't read pathname for load map: Input/output error. Reading symbols from /usr/lib/libmp.so.3...done. Loaded symbols for /usr/lib/libmp.so.3 Reading symbols from /usr/lib/libgmp.so.3...done. Loaded symbols for /usr/lib/libgmp.so.3 Reading symbols from /usr/lib/libXpm.so.4...done. Loaded symbols for /usr/lib/libXpm.so.4 Reading symbols from /usr/lib/libX11.so.6...done. Loaded symbols for /usr/lib/libX11.so.6 Reading symbols from /lib/libnsl.so.1...done. Loaded symbols for /lib/libnsl.so.1 Reading symbols from /lib/libm.so.6...done. Loaded symbols for /lib/libm.so.6 Reading symbols from /lib/libc.so.6...done. Loaded symbols for /lib/libc.so.6 Reading symbols from /usr/lib/libXau.so.6...done. Loaded symbols for /usr/lib/libXau.so.6 Reading symbols from /usr/lib/libXdmcp.so.6...done. Loaded symbols for /usr/lib/libXdmcp.so.6 Reading symbols from /lib/libdl.so.2...done. Loaded symbols for /lib/libdl.so.2 Reading symbols from /lib/ld-linux.so.2...done. Loaded symbols for /lib/ld-linux.so.2 Reading symbols from /lib/libnss_files.so.2...done. Loaded symbols for /lib/libnss_files.so.2 Reading symbols from /lib/libnss_mdns4_minimal.so.2...done. Loaded symbols for /lib/libnss_mdns4_minimal.so.2 Reading symbols from /lib/libnss_dns.so.2...done. Loaded symbols for /lib/libnss_dns.so.2 Reading symbols from /lib/libresolv.so.2...done. Loaded symbols for /lib/libresolv.so.2 Reading symbols from /usr/lib/libXcursor.so.1...done. Loaded symbols for /usr/lib/libXcursor.so.1 Reading symbols from /usr/lib/libXrender.so.1...done. Loaded symbols for /usr/lib/libXrender.so.1 Reading symbols from /usr/lib/libXfixes.so.3...done. Loaded symbols for /usr/lib/libXfixes.so.3 Reading symbols from /lib/libnss_compat.so.2...done. Loaded symbols for /lib/libnss_compat.so.2 Reading symbols from /lib/libnss_nis.so.2...done. Loaded symbols for /lib/libnss_nis.so.2 Core was generated by `./netrek'. Program terminated with signal 11, Segmentation fault. #0 0x0805cc99 in map () (gdb) run Starting program: /home/zu22/netrek/cow/build/netrek Failed to read a valid object file image from memory. Reading defaults file /home/zu22/.netrekrc Program exited normally. (gdb) bt #0 0x0805cc99 in map () #1 0x08083757 in redraw () #2 0x080838bc in intrupt () #3 0x08051d08 in input () #4 0x08082289 in cowmain () #5 0x0804b787 in main () (gdb) quit I used cscope to check map() and it's a pretty big function with different uses depending on the context so I'm still not sure exactly why the client is crashing. Zach
From: Darko on 4 Nov 2007 10:12 On Nov 3, 11:24 pm, Zach <net...(a)gmail.com> wrote: > I compiled a game client and it crashed (segmentation fault) resulting > in a core file being generated. I'm trying to find out exactly what > caused it to crash. Any ideas how I can do this with gdb? In the > Makefile can I just add a "-g" flag to have the binary produced with > debugging symbols? The source is written in ANSI C. > > This is what I have now: > "CC = gcc" > > The client binary is 433680 and the core file produced when it crashed > is almost double that, it's 860160. > > Here is what I've done so far: > 1]+ Segmentation fault (core dumped) ./netrek > > zu22(a)netrek:~/netrek/cow/build$ file core > core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4- > style > > zu22(a)netrek:~/netrek/cow/build$ gdb ./netrek core > GNU gdb 6.6.90.20070912-debian > Copyright (C) 2007 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. > There is NO WARRANTY, to the extent permitted by law. Type "show > copying" > and "show warranty" for details. > This GDB was configured as "i486-linux-gnu"... > Using host libthread_db library "/lib/libthread_db.so.1". > > warning: Can't read pathname for load map: Input/output error. > Reading symbols from /usr/lib/libmp.so.3...done. > Loaded symbols for /usr/lib/libmp.so.3 > Reading symbols from /usr/lib/libgmp.so.3...done. > Loaded symbols for /usr/lib/libgmp.so.3 > Reading symbols from /usr/lib/libXpm.so.4...done. > Loaded symbols for /usr/lib/libXpm.so.4 > Reading symbols from /usr/lib/libX11.so.6...done. > Loaded symbols for /usr/lib/libX11.so.6 > Reading symbols from /lib/libnsl.so.1...done. > Loaded symbols for /lib/libnsl.so.1 > Reading symbols from /lib/libm.so.6...done. > Loaded symbols for /lib/libm.so.6 > Reading symbols from /lib/libc.so.6...done. > Loaded symbols for /lib/libc.so.6 > Reading symbols from /usr/lib/libXau.so.6...done. > Loaded symbols for /usr/lib/libXau.so.6 > Reading symbols from /usr/lib/libXdmcp.so.6...done. > Loaded symbols for /usr/lib/libXdmcp.so.6 > Reading symbols from /lib/libdl.so.2...done. > Loaded symbols for /lib/libdl.so.2 > Reading symbols from /lib/ld-linux.so.2...done. > Loaded symbols for /lib/ld-linux.so.2 > Reading symbols from /lib/libnss_files.so.2...done. > Loaded symbols for /lib/libnss_files.so.2 > Reading symbols from /lib/libnss_mdns4_minimal.so.2...done. > Loaded symbols for /lib/libnss_mdns4_minimal.so.2 > Reading symbols from /lib/libnss_dns.so.2...done. > Loaded symbols for /lib/libnss_dns.so.2 > Reading symbols from /lib/libresolv.so.2...done. > Loaded symbols for /lib/libresolv.so.2 > Reading symbols from /usr/lib/libXcursor.so.1...done. > Loaded symbols for /usr/lib/libXcursor.so.1 > Reading symbols from /usr/lib/libXrender.so.1...done. > Loaded symbols for /usr/lib/libXrender.so.1 > Reading symbols from /usr/lib/libXfixes.so.3...done. > Loaded symbols for /usr/lib/libXfixes.so.3 > Reading symbols from /lib/libnss_compat.so.2...done. > Loaded symbols for /lib/libnss_compat.so.2 > Reading symbols from /lib/libnss_nis.so.2...done. > Loaded symbols for /lib/libnss_nis.so.2 > Core was generated by `./netrek'. > Program terminated with signal 11, Segmentation fault. > #0 0x0805cc99 in map () > (gdb) run > Starting program: /home/zu22/netrek/cow/build/netrek > Failed to read a valid object file image from memory. > Reading defaults file /home/zu22/.netrekrc > > Program exited normally. > (gdb) bt > #0 0x0805cc99 in map () > #1 0x08083757 in redraw () > #2 0x080838bc in intrupt () > #3 0x08051d08 in input () > #4 0x08082289 in cowmain () > #5 0x0804b787 in main () > (gdb) quit > > I used cscope to check map() and it's a pretty big function with > different uses depending on the context so I'm still not sure exactly > why the client is crashing. > > Zach Yes, -g is good enough to insert the symbols into the executable. Once in gdb (as you run it), try typing "where" (withoug quotes) to have the whole stack printed on screen. You should check the functions arguments' addresses, since it is most common that some pointers are invalid (if, e.g. they have very low values, such as 0x02, 0x00, 0x20, etc. you should check what's wrong). Anyway, you'll get the point where the program broke, so you localize the problem. Once I read in fortune that "debugging requires more efforts & brains than coding, so if you put all your efforts and brains into coding, than you'll probably not be able to debug it" ;-) Good luck Darko
From: Sheth Raxit on 5 Nov 2007 09:50 On Nov 4, 3:24 am, Zach <net...(a)gmail.com> wrote: > I compiled a game client and it crashed (segmentation fault) resulting > in a core file being generated. I'm trying to find out exactly what > caused it to crash. Any ideas how I can do this with gdb? In the > Makefile can I just add a "-g" flag to have the binary produced with > debugging symbols? The source is written in ANSI C. > > This is what I have now: > "CC = gcc" > > The client binary is 433680 and the core file produced when it crashed > is almost double that, it's 860160. > > Here is what I've done so far: > 1]+ Segmentation fault (core dumped) ./netrek > > zu22(a)netrek:~/netrek/cow/build$ file core > core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4- > style > > zu22(a)netrek:~/netrek/cow/build$ gdb ./netrek core > GNU gdb 6.6.90.20070912-debian > Copyright (C) 2007 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. > There is NO WARRANTY, to the extent permitted by law. Type "show > copying" > and "show warranty" for details. > This GDB was configured as "i486-linux-gnu"... > Using host libthread_db library "/lib/libthread_db.so.1". > > warning: Can't read pathname for load map: Input/output error. > Reading symbols from /usr/lib/libmp.so.3...done. > Loaded symbols for /usr/lib/libmp.so.3 > Reading symbols from /usr/lib/libgmp.so.3...done. > Loaded symbols for /usr/lib/libgmp.so.3 > Reading symbols from /usr/lib/libXpm.so.4...done. > Loaded symbols for /usr/lib/libXpm.so.4 > Reading symbols from /usr/lib/libX11.so.6...done. > Loaded symbols for /usr/lib/libX11.so.6 > Reading symbols from /lib/libnsl.so.1...done. > Loaded symbols for /lib/libnsl.so.1 > Reading symbols from /lib/libm.so.6...done. > Loaded symbols for /lib/libm.so.6 > Reading symbols from /lib/libc.so.6...done. > Loaded symbols for /lib/libc.so.6 > Reading symbols from /usr/lib/libXau.so.6...done. > Loaded symbols for /usr/lib/libXau.so.6 > Reading symbols from /usr/lib/libXdmcp.so.6...done. > Loaded symbols for /usr/lib/libXdmcp.so.6 > Reading symbols from /lib/libdl.so.2...done. > Loaded symbols for /lib/libdl.so.2 > Reading symbols from /lib/ld-linux.so.2...done. > Loaded symbols for /lib/ld-linux.so.2 > Reading symbols from /lib/libnss_files.so.2...done. > Loaded symbols for /lib/libnss_files.so.2 > Reading symbols from /lib/libnss_mdns4_minimal.so.2...done. > Loaded symbols for /lib/libnss_mdns4_minimal.so.2 > Reading symbols from /lib/libnss_dns.so.2...done. > Loaded symbols for /lib/libnss_dns.so.2 > Reading symbols from /lib/libresolv.so.2...done. > Loaded symbols for /lib/libresolv.so.2 > Reading symbols from /usr/lib/libXcursor.so.1...done. > Loaded symbols for /usr/lib/libXcursor.so.1 > Reading symbols from /usr/lib/libXrender.so.1...done. > Loaded symbols for /usr/lib/libXrender.so.1 > Reading symbols from /usr/lib/libXfixes.so.3...done. > Loaded symbols for /usr/lib/libXfixes.so.3 > Reading symbols from /lib/libnss_compat.so.2...done. > Loaded symbols for /lib/libnss_compat.so.2 > Reading symbols from /lib/libnss_nis.so.2...done. > Loaded symbols for /lib/libnss_nis.so.2 > Core was generated by `./netrek'. > Program terminated with signal 11, Segmentation fault. > #0 0x0805cc99 in map () > (gdb) run > Starting program: /home/zu22/netrek/cow/build/netrek > Failed to read a valid object file image from memory. > Reading defaults file /home/zu22/.netrekrc > > Program exited normally. > (gdb) bt > #0 0x0805cc99 in map () > #1 0x08083757 in redraw () > #2 0x080838bc in intrupt () > #3 0x08051d08 in input () > #4 0x08082289 in cowmain () > #5 0x0804b787 in main () > (gdb) quit > is your program multithreaded ? use print/dump,info threads. also you may want to catch errno. > I used cscope to check map() and it's a pretty big function with > different uses depending on the context so I'm still not sure exactly > why the client is crashing. > > Zach -Raxit
|
Pages: 1 Prev: C++ code to read a binary file larger than 2GB on a 32-bit system? Next: About some snippet on APUE |