top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I debug Segmentation fault in C code with inlining function?

+2 votes
How can I debug Segmentation fault in C code with inlining function?
posted Nov 27, 2014 by Varun Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can do the following:

1. Very first go through your program and comment out the the line of the code on which you have doubt
     and try to compile and run the program. If it is working fine, then you know that which line is making your
     code to seg fault.

    /* If you are not able to find out using this, try 2nd one */

2. use "gdb",   before using gdb you have to compile your code with -g option in gcc to store the debug information.
       gcc -g your_program.c           // it will give an a.out exutable

       gdb ./a.out
       ... // you will get something like this
       Reading symbols from ./a.out...done.
      <just type start and enter>
       and for every (gdb) now type "n" for next statement.
       untill you get your line where you are getting seg fault.

   for more info regaring gdb see the manual page of gdb.
answer Dec 2, 2014 by Arshad Khan
Similar Questions
0 votes

How can we debug the segmentation fault in a program which has been compiled without "-g" option?

0 votes

We are running debian linux stable (Jessie) with apache 2.4.10 and mod_wsgi 4.3.0-1 on a x86_64 machine. Our application is written in python 2.7 and django 1.8.

The list of modules as reported by apachectl -M are:Loaded Modules: core_module (static) so_module (static) watchdog_module (static) http_module (static) log_config_module (static) logio_module (static) version_module (static) unixd_module (static) access_compat_module (shared) alias_module (shared) auth_basic_module (shared) authn_core_module (shared) authn_file_module (shared) authz_core_module (shared) authz_host_module (shared) authz_user_module (shared) autoindex_module (shared) cgi_module (shared) deflate_module (shared) dir_module (shared) env_module (shared) filter_module (shared) mime_module (shared) mpm_worker_module (shared) negotiation_module (shared) perl_module (shared) rewrite_module (shared) setenvif_module (shared) socache_shmcb_module (shared) status_module (shared) wsgi_module (shared)

We were getting segmentation faults when rest api clients were making requests. The apache error log has the following messages:

[Mon Jul 27 09:04:38.375433 2015] [core:notice] [pid 32693:tid 140315326191488] AH00052: child pid 32700 exit signal Segmentation fault (11)
[Mon Jul 27 09:04:38.375556 2015] [core:notice] [pid 32693:tid 140315326191488] AH00052: child pid 32701 exit signal Segmentation fault (11)

I have enabled core dumps by setting ulimit to unlimited and adding core dump config directive in the apache2.conf file.
but the core dumps are not happening. When I tried to debug using gdb (gdb /usr/sbin/apache2), the environment variables are not getting read. Any clues on how to go about this?

+1 vote

How can we debug the Android framework Java code? i know how I can debug the c/c++ code with the help of GDB server etc, but I searched a lot on Google but did not get the solution, currently i am totally relying on Logs but I really need something to Debug the java code inside framework and etc?
please give me some pointers or some details about debugging AOSP framework java code?

0 votes

Following is my code and getting segmentation fault. Please help

    char *p,str[100]="Hi, How Are You, Fine, Thank You";
    while(p != NULL)

O/p is:
How Are You
Thank You
and then Segmentation fault.

+4 votes

I have written print("%s", __LINE__); I get crashed. Can someone please explain why it is happened ?