LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2012, 09:34 AM   #1
grob115
Member
 
Registered: Oct 2005
Posts: 542

Rep: Reputation: 32
Segmentation fault on different server


Hi, I have successfully compiled and ran some code on the latest gcc and Linux but when I try to use the same source and compile it on a slightly older gcc and Linux, the resulting executable will hit a segmentation fault. Has anyone come across a case when seg fault may be due to different gcc or OS? How do you solve this?
 
Old 06-28-2012, 10:38 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by grob115 View Post
Has anyone come across a case when seg fault may be due to different gcc or OS?
Umm.. Sure, but that is the exception to the rule. Both GCC and the kernel do have bugs too.

Are you sure there is no bugs in the code? That would be the first for me, personally. If it is your code, take a step back from the keyboard. It is just code, and because we're human, we make errors. It does not make you a bad programmer. (If it did, then I'd have to switch professions, I guess.) A different perspective often makes it easier to spot the problems.

Quote:
Originally Posted by grob115 View Post
How do you solve this?
The fact that some code compiles and runs successfully does not mean it is correct.

The first thing I'd do is compile it with full warnings (gcc -W -Wall ...), and very, very carefully check the code related to any warnings you get. You might wish to check which C variant you're using, and enforcing it (-std=c99 -pedantic) too.

Then, I'd check all loops for off-by-one errors.

At this point you have usually fixed several bugs already. I personally love the Eyeball-Mark-1 approach, but tools like valgrind make the bug hunt a lot easier.

Is it your code? Can you post it?
 
Old 06-28-2012, 11:54 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Most likely there is a bug in your program. (Even if works in another context, that doesn't prove anything.) Use gdb.
 
Old 06-28-2012, 01:23 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by grob115 View Post
How do you solve this?
First understand that the cases in which your program works tell you less than you think. Serious bugs can easily be symptom free. Debug the situation that fails with the assumption (almost always correct) that the failure is due to a bug in your program (not in gcc nor in the OS).

In gdb you can get a back trace (call stack) of the segment fault. I forget how (because I haven't used gdb in a long time) but is easier than most things you might need to do in gdb.

If you enable core files (via ulimit) and get a core dump of the stack fault, you can get that back trace from gdb using the executable and core dump as inputs to gdb, but without needing to actually run the program under gdb. If you are really ignorant of gdb or you are subject to other constraints, that core dump file approach can be simpler than running the program under gdb.

With an ordinary optimized program without debug symbols, the back trace still may have enough info to identify the problem. A back trace tends to give better info for a debug build (non optimized and with debug info in the executable) but often turning off optimization hides the bug. You might need to compromise on an optimized build with debug info (that is possible in gcc though the debug info isn't terribly accurate).

The majority of times, a careful review of the code indicated by the back trace lets you spot the bug. But sometimes you need real debugging of that section of code to debug the seg fault, and sometimes that is the wrong location entirely: A bug elsewhere can clobber a memory location used by the section of code that seg faults. So the point of failure may be unrelated to the bug. Those may take specialized debugging skills to solve.

Last edited by johnsfine; 06-28-2012 at 01:27 PM.
 
Old 07-02-2012, 04:46 AM   #5
grob115
Member
 
Registered: Oct 2005
Posts: 542

Original Poster
Rep: Reputation: 32
Hi, thanks for all the responses. I have as usual first thing used gdb to debug and each time it hit the seg fault at the exact location, which is when the API calls the call back class. Now what puzzles me is this didn't happen when I compiled it on another platform and the reason I thought it maybe due to a platform issue was because I once compiled code on a Linux variant, the same binary didn't work on a different Linux variant unless I recompile it on that Linux variant.

It may very well be in my code. Unfortunately I'm not an expert in gdb and reading values being passed into a function, or inspecting the variable being pointed to a pointer, etc isn't exactly that easy as within the IDE.

I'm going to take a look at it again. And yes the odds are in gcc's favor rather than mine in terms of bugs.
 
Old 07-02-2012, 08:42 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
probably showing the code can help (to identify the problem). Also please post how did you build your app (command line and related...)
 
Old 07-03-2012, 11:45 AM   #7
grob115
Member
 
Registered: Oct 2005
Posts: 542

Original Poster
Rep: Reputation: 32
Hi, I'm delighted to announce that the program now works. It's due to a bug in my code to instantiate a class instance while inside another class's method (ie outside of the main function). Therefore, when this other class's method exits and returns to the main function the associated created object is destroyed.

A good debugger that works on Windows against a remote Linux box really helps but the only ones that are available (ie visualgdb, etc) all function as a plugin to Visual Studio, or they need to run on a Linux GNOME, etc. Any recommendations for visual debuggers that work on Windows without relying on Visual Studio?
 
Old 07-25-2012, 02:47 PM   #8
keepwalking
Member
 
Registered: Oct 2010
Posts: 46

Rep: Reputation: 0
hello every one I am working on ns2 adding a EECED protocol and now I am getting an error when I trying to simulate this protocol. may you please help me to with advise on what might be the result of this error.

Code:
keepwalking@keepwalking-HP-ProBook-4520s:~/ns-allinone-2.35/ns-2.35/eeced$ ns eeced.tcl
num_nodes is set 64
Creating mobile nodes...
INITIALIZE THE LIST xListHead
Mobile nodes created successfully...
Setting random positions for nodes...
Random positions setup complete...
Setting initial positions for NAM..
Initial NAM positions setup complete...
Creating EECED agents and attaching to mobile nodes...
warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

warning: no class variable Agent/EECED::node_role

	see tcl-object.tcl in tclcl for info about this warning.

EECED agents created and attached successfuly...
Starting the elector agent...
Elector agent started...
Node 0 Broadcast energy request message 
Node 0 has completed sending energy request...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 550.0
SORTING LISTS ...DONE!
Segmentation fault
keepwalking@keepwalking-HP-ProBook-4520s:~/ns-allinone-2.35/ns-2.35/eeced$
 
Old 07-26-2012, 12:56 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
keepwalking please open a new thread for your problem
 
3 members found this post helpful.
Old 07-27-2012, 09:24 AM   #10
keepwalking
Member
 
Registered: Oct 2010
Posts: 46

Rep: Reputation: 0
@pan64

Your response does not shows maturity
Thanks.
 
Old 07-28-2012, 09:14 AM   #11
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Your response does not shows maturity
Actually, it does. These forums are organized by different threads and categories for a good reason. What you have done is considered poor form and is known as thread hijacking.

I don't know much about tcl, but from what you've posted, I don't think you've provided enough information for anyone to estimate the result of your error. I don't think anyone can even estimate the cause of your error.
--- rod.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
X-server segmentation fault on program launching chiendarret Linux - Software 3 04-14-2010 10:30 AM
Segmentation fault over UBUNTU SERVER Freeck Linux - Server 3 02-22-2009 09:08 AM
freeradius-server-2.0.5 + mysql + Segmentation fault conesh Linux - Newbie 0 08-19-2008 01:39 PM
Cannot boot Red Hat server - Segmentation fault ajaykk Linux - Newbie 5 07-13-2007 01:03 AM
Server not booting - Segmentation fault ajaykk Linux - Enterprise 4 09-15-2006 07:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration