Debugging core file?

Z

Zach

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@netrek:~/netrek/cow/build$ file core
core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-
style

zu22@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
 
K

karthikbalaguru

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@netrek:~/netrek/cow/build$ file core
core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-
style

zu22@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.

1)Can you try step debugging and analyse variables/memory w.r.t
reaching till 'map' and inside map .

You have tried backtrace which shows a(one) line per frame, for many
frames, starting with the currently executing frame (frame zero),
followed by its caller (frame one), and on up the stack.
But, we are not aware of your design flow. Is the design flow correct
as you have thought ?

Signal 11 - "segmentation fault" and as you might be aware that the
reason for this can be due to
accessing a memory location that was not assigned. So, Check for the
proper use of memory (Memory/Buffer management,proper use of
pointers,typecasting,string manipulation as APIs related
with it does not have proper buffer overflow / buffer management
checks)

Karthik Balaguru
 
S

srikrishanmalik

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@netrek:~/netrek/cow/build$ file core
core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-
style
zu22@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.

1)Can you try step debugging and analyse variables/memory w.r.t
reaching till 'map' and inside map .

You have tried backtrace which shows a(one) line per frame, for many
frames, starting with the currently executing frame (frame zero),
followed by its caller (frame one), and on up the stack.
But, we are not aware of your design flow. Is the design flow correct
as you have thought ?

Signal 11 - "segmentation fault" and as you might be aware that the
reason for this can be due to
accessing a memory location that was not assigned. So, Check for the
proper use of memory (Memory/Buffer management,proper use of
pointers,typecasting,string manipulation as APIs related
with it does not have proper buffer overflow / buffer management
checks)

Karthik Balaguru


From the stack it seems that the -g flag didn't work. the stack looks
like a stack of non debug binary. Once you create the binary with
debugging symbols...you will see the line numbers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,725
Members
45,511
Latest member
Osiris-Team

Latest Threads

Top