How to do it...

We are going to identify the root cause of a crash in an application that was not run in the GDB:

  1. In this recipe, we will use the same environment and the same test application as in the first recipe. Refer to steps 1 to 7 of the first recipe to build the application and copy it over to the target system.
  2. Firstly, we need to enable the generation of core dumps for crashing applications. This feature is turned off by default in most Linux distribution. Run the ulimit -c command to check the current status:
$ ulimit -c
  1. The value reported by the preceding command is the maximum size of core dumps to generate. Zero means no core dumps. To increase the limit, we need to get superuser privileges first. Run the su - command. When prompted for a Password, type root:
$ su -
Password:
  1. Run the ulimit -c unlimited command to allow core dumps of any size:
# ulimit -c unlimited
  1. Now, exit the root shell by pressing Ctrl + D or by running the logout command.
  2. Preceding commands changed the core dump limit for the superuser only. To apply it to the current user, run the same command again in the user shell:
$ ulimit -c unlimited
  1. Make sure that the limit was changed:
$ ulimit -c
unlimited
  1. Now, run the application as usual: 
$ ./loop 
  1. It will crash with an exception. Run the ls command to check whether a core file was created in the current directory:
$ ls -l core
-rw------- 1 dev dev 536576 May 31 00:54 core
  1. Now, run gdb, passing the executable and the core files as parameters:
$ gdb ./loop core
  1. In the GDB shell, run the bt command to see the stack trace:
(gdb) bt
  1. You can see the same stack trace as for the application running from inside gdb. However, in this case, we see the stack trace of the core dump.
  2. At this point, we can use the same debugging techniques as in the first recipe to narrow down the cause of the crash.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.147.124