Linux program exits print call stack unexpectedly

Source: Internet
Author: User
Tags stack trace

/* * Program abnormally terminates when printing exception program call stack * gcc-g-rdynamic backtracetest.c-o backtracetest * * Run Program error: * System error, Stack trace: * 0 ./backtracetest (systemerrorhandler+0x77) [0x40095b] * 1/lib64/libc.so.6 () [0x3a4fe326b0] * 2./backtracetest (Fun1+ 0x10) [0X400A10] * 3./backtracetest (FUN+0XE) [0x400a23] * 4./backtracetest (MAIN+0X37) [0x400a5c] * 5/LIB64/LIBC.SO.6 (__ LIBC_START_MAIN+0XFD) [0x3a4fe1ed5d] * 6./backtracetest () [0x400829] * segmentation fault (core dumped) * GDB print error line information * GDB backtracetest * (GDB) Info Line *0x400a10 * line, "backtracetest.c" starts at address 0x400a0c <Fun1+12> an D ends at 0x400a13 <fun1+19>. * (GDB) List *0x400a10 * 0x400a10 is in Fun1 (backtracetest.c:66). * Warning:source file is more recent than executable. * * * * * 63void Fun1 () * 64{* 65char *p=null; * 66*p = ' A '; * "* * * * * * * * * 69void fun () * 70{* * * * addr2line locator address corresponding Source code location * ADDR2LINE-E backtracetest-i 0X400A10 */home/cyf/workspace/backtracetest/backtracetest.c:66 * */#include &Lt;stdio.h> #include <stdlib.h> #include <signal.h> #include <string.h> #include <execinfo.h >void systemerrorhandler (int signum) {const int len=1024;void *func[len];size_t size;int i;char **funs;signal (signum , SIG_DFL); Size=backtrace (Func,len); funs= (char**) backtrace_symbols (func,size); fprintf (stderr, "System error, Stack Trace:\n "); for (I=0;i<size;++i) fprintf (stderr,"%d%s \ n ", i,funs[i]); free (funs);//exit (1);} void Fun1 () {char *p=null;*p = ' A ';} void Fun () {Fun1 ();} int main (const int argc,const char* argv[]) {signal (Sigsegv,systemerrorhandler);//invaild Memory Addresssignal (SIGABRT , Systemerrorhandler); Abort Signalfun (); return 0;}

Linux program exits print call stack unexpectedly

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.