Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know which illegal address the program access when a segmentation fault happens

Plus, The program runs on a arm device running Linux, I can print out stack info and register values in the sig-seg handler I assign. The problem is I can't add -g option to the source file, since the bug may won't reproduce due to performance downgrade.

like image 703
overboming Avatar asked May 12 '10 09:05

overboming


People also ask

How do you determine where a segmentation fault occurs?

Use debuggers to diagnose segfaults Start your debugger with the command gdb core , and then use the backtrace command to see where the program was when it crashed. This simple trick will allow you to focus on that part of the code.

What do you understand by segmentation fault or memory access violation show a code that causes this error?

A common run-time error for C programs by beginners is a "segmentation violation" or "segmentation fault." When you run your program and the system reports a "segmentation violation," it means your program has attempted to access an area of memory that it is not allowed to access.

Why am I getting a segmentation fault?

A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).


1 Answers

Compiling with the -g option to gcc does not cause a "performance downgrade". All it does is cause debugging symbols to be included; it does not affect the optimisation or code generation.

If you install your SIGSEGV handler using the sa_sigaction member of the sigaction struct passed to sigaction(), then the si_addr member of the siginfo_t structure passed to your handler contains the faulting address.

like image 153
caf Avatar answered Sep 20 '22 23:09

caf