Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

Thread Tools Search this Thread
Top Forums Programming Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault
# 1  
Old 10-12-2012
Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this :
1. gdb polo
2. run -e1 -o /var/bin
i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 sec) , Watchdog would frequently and immediately , start the app (ie in 15 sec more than 10 times , it would start my app , and then again segmentation fault , again the watchdog script make my app start and son on ...) until i get crash in my environment which my stb get black screen and i have to restart my stb.
i already had fix that segmentation fault , but for next step , i also want to fix , the bug which cause my environment crash (since if in other part of my app , there was a segmentation fault , it shouldn't make my env crash which i have to restart every-time)
my question is , how could i debug , a application with watchdog script which is controlling my app , i mean , i could let that segmentation fault bug exists (for reproducing the env Crash (which i need to investigate) but the problem is before env would be crash , the segment-fault , happened , so it prevents my app to reach environment crash ,Would highly appreciated any idea.
# 2  
Old 10-12-2012
Watchdog scripts should move the core file before restarting. I like compressing it into a file with the date-time in another directory, perhaps /tmp so they get cleaned up if they get too large.

Beyond that, I like to scan for core on prod and dev boxes, ls -l it, copy it to /tmp/core.YYYY-MMDD-HHMMSS so it is not overwritten, automatically locate the main code using 'file' and common PATHs, run gdb for a stack trace (where), sending an email to the group with as much info as I could get, so they know one side effect of their activities is this core dump, which might be missed otherwise. Then I compress it in the background and sleep a second to ensure unique naming. A marker file keeps track of my last scan time, so I do not pick up the same files over and over.

But then, I am more into diagnosis by post mortem than running in debug mode. I am not sure what the environment has to do the the SEGV, that is usually a programmer with too much trust of his inputs.
# 3  
Old 10-12-2012
Here is what you want to do
1. compile polo with the cc option -g
2. run it however you want in your home directory.
3. When segmentation fault happens - STOP at this point.

gdb polo  core
gdb> ba

ba is the backtrace command in gdb.
This will show the line of your code that has a problem. The first line number in polo code after the ba command is the line with the problem.

 .......... ignore these lines
 strcpy in myfunction()  polo. c.:42

# 4  
Old 10-12-2012
Yes, -g and no strip makes it easier to unscrew.
# 5  
Old 10-12-2012
Thanks for replies

1. As explained in first post of thread , using normal gdb backtrace comand could not helpful , since i know Segmentation fault log , my question is not how i could catch the segmentation fault error log or fix it , since i know how.
my question is , If segmentation fault error occur more than 12 times , my environment (or maybe my kernel would crash) it could be kernel bug with my stb , Therefore , using -g and catch the first SEGV is not my desire (i know even the fix for this SEGV) but i deliberately , let it to be , in order to investigate Kernel (or environment) crash

if i use -g option and use gdb , before i could achieve to investigate Kernel (or environment) crash , i would get Segmentation fault (which is not as my desire , since it prevent me to know , why kernel would crash...

2. i compiled polo , with the cc option : -ggdb
could somebody please tell me what is the difference beetween -g and -ggdb in cc option?
# 6  
Old 10-13-2012
You cannot debug kernel code from gdb. You have to use a kernel debugger.

I would suggest that you are probably corrupting the kernel with repeated segfaults.

You probably are not aware, but originally UNIX would panic (crash with a core dump) when any process had a segfault. UNIX is not meant to have bad code violate memory time after time after time. That said, I kinda doubt it is a bug in the true sense of the word.

Your code is acting more like a virus.

What does the system log say about errors? Do you get a core when the system crashes? You probably did get a system dump. You can analyze that system core.

What OS do you have?

You do understand that what I am about to say will let you do what you ask but it may trash your OS eventually:
Block (ignore) the SIGSEGV signal and set up the signal handler to reset the ignore. Then let your code run over and over the bad code until the system dies. Be sure to turn on a full system dump. Some OSes let you turn off system core dumps. You want it on. That may take a lot of GB of disk space. Then go after your bug in the kernel with the correct tool.

I do not know your OS so I cannot give you a better answer.

Last edited by jim mcnamara; 10-13-2012 at 01:30 AM..
This User Gave Thanks to jim mcnamara For This Post:
# 7  
Old 10-13-2012
The os is Stlinux (Cpu Sh4) . Welcome! | STLinux and it run with busybox.
in this article it says , about kernel debugging with stlinux :
Debugging the kernel | STLinux

but i am not sure , if my stb's kernel debugging is enable (i mean , the stb's kernel had compiled with the feature of kernel debugging) but this is not prevent me , since i had installed Stlinux in my pc , if i could achieve to enable System core dump of my stb , maybe i could debug it in my pc , how could i get system core dump with my stlinux's stb? if it would be any link , i appreciate and do it as link instruction...
Does Tail command could be helpful for my case?

P.S: for debugging purposes , i had run my STB , via NFS with the log (shown in Terminal)

Last edited by pooyair; 10-13-2012 at 06:54 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies

2. UNIX for Dummies Questions & Answers

Using gdb to detect segmentation fault in sh?

I am using scientific linux. In the directory user/project/Build, after I ran 'make' to compile and link all the cpp files,I had no problems. But then, when I went to directory user/run/, which runs the project binary in user/project/Build/bin/project, I get a segmentation fault error. In... (1 Reply)
Discussion started by: larry burns
1 Replies

3. Homework & Coursework Questions

Segmentation Fault

this is a network programming code to run a rock paper scissors in a client and server. I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault. -the segmentation fault is fixed Current problem -Also... (3 Replies)
Discussion started by: femchi
3 Replies

4. Programming

Segmentation fault gdb

Hello everyone, I am using the debugger from C++ and these are the message I got: Program received signal SIGSEGV, Segmentation fault. 0x0040cc0e in malloc_consolidate (av=0x4ff3c0) at malloc.c:5169 in malloc.c I don't know if the problem is cause i'm trying to acess an invalid memory... (1 Reply)
Discussion started by: juliecf5
1 Replies

5. Programming

segmentation fault.

This code is causing a segmentation fault and I can't figure out why. I'm new to UNIX and I need to learn how to avoid this segmentation fault thing. Thank you so much. Thanks also for the great answers to my last post.:):b: int main() { mysqlpp::Connection conn(false); if... (3 Replies)
Discussion started by: sepoto
3 Replies

6. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

7. Programming

segmentation fault

What is segmentation fault(core dumped) (1 Reply)
Discussion started by: gokult
1 Replies

8. Linux

Segmentation fault

Hi, on a linux Red HAT(with Oracle DB I have following error : RMAN> delete obsolete; RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 2 using channel ORA_DISK_1 Segmentation fault What does it mean ? And the solution ? Many thanks. (0 Replies)
Discussion started by: big123456
0 Replies

9. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

10. Programming

Hi! segmentation fault

I have written a program which takes a directory as command line arguments and displays all the dir and files in it. I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
Discussion started by: vijlak
4 Replies
Login or Register to Ask a Question

Featured Tech Videos