Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the crashing assembly instruction from core dump on Linux

If I load the crashing program and the core dump into gdb, it shows me a stack trace and crash point as below.

Core was generated by `./cut --output-d=: -b1,1234567890- /dev/fd/63'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  is_printable_field (i=1234567890) at src/cut.c:266
266   return (printable_field[n] >> (i % CHAR_BIT)) & 1;
(gdb) bt
#0  is_printable_field (i=1234567890) at src/cut.c:266
#1  set_fields (fieldstr=0x7ffccb0561c4 "") at src/cut.c:533
#2  main (argc=4, argv=0x7ffccb055cf8) at src/cut.c:865

Is there any means to know the exact assembly instruction that caused the segfault?

like image 336
Holmes.Sherlock Avatar asked Jan 19 '16 09:01

Holmes.Sherlock


People also ask

Where are core files dumped in Linux?

By default, core dumps are sent to systemd-coredump which can be configured in /etc/systemd/coredump. conf . By default, all core dumps are stored in /var/lib/systemd/coredump (due to Storage=external ) and they are compressed with zstd (due to Compress=yes ).

What is core dump in Linux?

A core dump is a file that gets automatically generated by the Linux kernel after a program crashes. This file contains the memory, register values, and the call stack of an application at the point of crashing.


1 Answers

One possibility is to set:

(gdb)layout asm

When GDB stops the corresponding assembly line is pointed.

Example:

   │0x7ffff7aa441d <strtok+45>      je     0x7ffff7aa44d6 <strtok+230>                                                                                       │
   │0x7ffff7aa4423 <strtok+51>      mov    %rsi,%rax                                                                                                         │
  >│0x7ffff7aa4426 <strtok+54>      mov    (%rax),%cl                                                                                                        │
   │0x7ffff7aa4428 <strtok+56>      test   %cl,%cl                                                                                                           │
   │0x7ffff7aa442a <strtok+58>      je     0x7ffff7aa4454 <strtok+100>


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7aa4426 in strtok () from /lib64/libc.so.6
(gdb) 
like image 125
terence hill Avatar answered Oct 05 '22 17:10

terence hill