ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
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.
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.
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?
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$
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.