Debug a program segment error with core dump

Source: Internet
Author: User

Some programs can be compiled, but segment fault (segment errors) occur at run time. This is usually caused by a pointer error. But this is not the same as compiling errors will prompt the file-> line, but there is no information, so that our debugging becomes difficult.


1. In general Linux systems, the default is not to produce a core dump file. Ulimit-c to view the size of the core dump file, typically starting with 0.
You can set the core file size, Ulimit-c 1024 (Kbytes units), or Ulimit-c Unlimited. (Note: Use-c unlimited does not limit core file size)
2. Generate core files: $ sudo sh-c "Ulimit-c unlimited;./main_arm" # Main_arm is the executable file name.
3. Remember to add-G at compile time to facilitate debugging, attention do not add optimization options-os (or-o0-o1 ...)
4. View core files with GDB:
GDB [exec file] [core file]
such as: GDB Main_arm Core
After entering GDB, use the BT or where command to view the backtrace to check where the program is running to locate the file line for core dump.
5. For example:
[HTML]  View Plain Copy a program Cmm_test_tool error at run time, and generated a core file, as follows:           -rw-r–r– 1 root cmm_test_tool.c          -rw-r–r–  1 root cmm_test_tool.o          -rwxr-xr-x 1  root cmm_test_tool          -RW ——- 1 root core.19344           -rw ——- 1 root core.19351           -rw-r–r– 1 root cmm_test_tool.cfg           -rw-r–r– 1 root cmm_test_tool.res           -rw-r–r– 1 root cmm_test_tool.log          [ root@autotest_sim2 mam2cm]#      can use command gdb to find, parameter one is the name of the application, parameter two is core file, run     &nbsP gdb cmm_test_tool core.19344 results are as follows:          [root@autotest_sim2  mam2cm]# gdb cmm_test_tool core.19344          gnu  gdb Red Hat Linux  (5.2.1-4)           copyright  2002 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  "I386-redhat-linux" ...          Core was generated by  './cmm_test_tool ' .          program terminated with signal 11, segmentation fault.           reading symbols from /lib/i686/libpthread.so.0 ... done.          loaded symbols for /lib/i686/ libpthread.so.0          reading symbols from /lib/i686/ libm.so.6...done.          loaded symbols for /lib/i686/ libm.so.6          reading symbols from /usr/lib/ libz.so.1...done.          Loaded symbols for /usr/lib/libz.so.1           Reading symbols from /usr/lib/libstdc++.so.5...done.          Loaded symbols for /usr/lib/libstdc++.so.5          Reading symbols from /lib/i686/libc.so.6...done.          Loaded symbols for /lib/i686/libc.so.6           Reading symbols from /lib/libgcc_s.so.1...done.           Loaded symbols for /lib/libgcc_s.so.1          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     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.