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.
So strange, I run the program and it gives the result, but when debugging it, using kdbg , It gives the message "Segmentation fault"
and even strange when it come to
->{
and stop....and give the message"Segmentation fault"
Any Ideas?
No, of course not. Not without some code.
You are only telling your program segfaults, and that the same thing happens when you run it in a debugger. You didn't even tell what the program is for or what it should do. What ideas did you expect from people here?
Then, compile the program with the -g flag if you're using gcc and run the program and make it crash. This time, the program should say something like: Segmentation Fault (Core dumped).
Now, type this:
gdb program core
where, program is the name of your program and core is the dumped core file (it could also be named core.xxxx, where xxxx is the pid of the crashed program).
I'm not going to go into a detailed gdb tutorial. You can find many of those online. Go google for one of them. But, as soon as you enter gdb, if'll probably tell you the line number and function where it crashed.
The strange thing is : when running, it is ok, no error message, but when debuging, it give"segmentation fault" . And more : when debuging : if I press F5 fast and continously, it gives the right result (no error), but when slowing pressing F5 , it comes to that error "segme....."
and one more question : kdbg and gbd , for you, which is better?( not about the graphical interface)?
(the code is so long, I can not put here"
Well, from your description, I cannot figure out what is wrong. I don't even know what kind of an application you're talking about. If you can get it to crash inside gdb (is that what you meant when you said it crashes during debugging?), then you can type "bt" inside gdb to find out what happened.
I prefer gdb to kdbg. But, it's just my personal preference. You might want to check out ddd.
You might give Electric Fence a shot. It may make the seg fault more consistent, and/or cause it at the soure of the problem rather than later on. Once you get it installed, just run "LD_PRELOAD=libefence.so.0.0 ./yourprogram", and if it seg faults you can "gdb yourprogram core"
This will only help *if* the problem happens because you're writing past the end of a dynamically allocated array, but that condition does happen a lot. Without electric fence you may get past the bad write and then crash somewhere else because you overwrote random memory. Sometimes this will happen only under some seemingly condition.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.