strange Debugging Error: possible memory corruption? - c++

I've got a strange problem:
I use eclipse and have written a program which is quite long. Now if I compile "Debug" (so no compiler optimization) and click "Run" then everything is finde and my Program produces the expected output.
Now If I compile "Release" the program does not terminate but instead "stops" at one point...
So I've started Debugging with the dgb Debugger build into eclipse and clicked through the program. And if I let it just run through everything is fine, but If I click through every single line of code then the program "stops" at some other point.
Now I've gone one step further and clicked not only through every line but stepped into each function.
What I found very strange is that in depence on HOW I step through my program with the debugger I get the error at different positions. So I think the stopping of the debugger is related to eclipse which cannot show something in the debugger-window or so.
Additionally the error critically depends on other lines of code.
So my best guess is that the error is related to some memory problem.
Thank you very much!

Related

How can I see where my program crashes in a given file?

My problem is that when I debug my modification on a c++ project (it is very huge) and when the program crashes, the visual studio shows me another cpp file where the program crashes. I know it shows me that because it is related to it, but I need the root where the crash started to I can fix my code. I have tried doing "step out" SHIFT + F11, not worked. So how can I make the debugger strict to my file ?
I know this question is gonna be underrated, but I can only explain this way.

Netbeans v7 C++ debugger bug

I have a program that I have written in C++ under linux (Ubuntu 10.10).
The programming and debugging worked perfectly until the moment I added the following lines to the code:
mapfile = fopen(map_filename,"wb");
fwrite(map_header,1,20,mapfile); // <-- this is the problem line
fclose(mapfile);
After I added those, the program compiles ok, but the debugger now won't start. It immediately fails with this message:
Program completed, Exit code 0x177
error while loading shared libraries: unexpected PLT reloc type 0xcc
And if I remove the line with the "fwrite", the debugger will start normally.
This problem only happends inside Netbeans.
When I debug it using the command-line "gdb" it also works ok without any problems.
Anyone have idea why its happening and how to fix it?
P.S: Those problems started recently so I assume maybe it has to do something with system updates, I'm not sure.
Found the problem:
Not long ago, I removed some old C++ projects from netbeans. It figures out that netbeans (at least v7.0) remembers all the breakpoints that I put on old projects that don't even exist in the IDE anymore.
I found this by looking at the Debugger Console (Window->Debugging->Debugging Console) and seeing that when "gdb" starts, it tries to setup all these breakpoints from other projects or from projects that do not exists (this is a bug in netbeans, btw)
The solution: I simply cleaned all the breakpoints (inside Window->Debugging->Breakpoints) and now the program can be debugged properly.
Hope this will help to anyone out there who has the similar problem.

Visual Studio 2012 Release only error

There are a number of errors going on here but I'm sure they are all linked, so first off I'm getting Access violation reading location exceptions at locations (generally near 0x00000000)
but I only get these exceptions in release and not in debug, even if i setup debugging to do so. Also I found where the error happens but when I step over that it goes in to a complete unrelated function that is not called in the line or in any of the functions in that line of code. But when similar code is called it still goes to this unrelated function but doesn't fail. This all only happens in release versions. I know which piece of code is causing the error as if I comment it out its all fine. Also in the watch window in release all the numbers are wrong most of the time, which has never been a problem but it could help also a added some code to it to output the values of variables to a file and the variables are all fine, the pointers are sensible, but when the exception happens it always says their 0x00000020 but when I look at the log they are fine. This is in 32 bit , but on 64 bit windows 7 in c++. Please any help would be good!
Visual Studio's debugger will cause the program to use a debug heap that can hide uninitialized memory if you use the option "Start with Debugging" to start your program, in release or debug. You can try to run your program built in the Debug configuration without the debugger attached, and then use the Attach to Process... option in the debug menu to attach to your executable.
If this doesn't help, I recommend using windbg to debug your program. For help getting started with windbg, take a look at the answers on this question.
Once windbg is configured and symbol paths are set up, you can use the "!analyze -v" option once the program crashes to get a lot of information about the crash automatically.

Segfaults from command line but works from GDB run

I'm really lost in here. Maybe some of you can point me to a right direction.
I'm developing a tool in ANSI C using GCC over MinGW. The tool is to be run only from command line. Probably only on windows machine. It elaborates some data locally and generates files for use by other programs. Basically it does a lot of math and a few file handling. Nothing really fancy. I didn't find it necessary posting the whole 1000+ lines here for examination...
I compile it with GCC -ansi making sure not even a single warning is present. Everything worked always well as the development evolved. But recently I started getting (almost) random segfaults. I checked for the last changes made, but found nothing. I removed the last changes completely coming back to when it perfectly worked. Still segfaults. I traced line by line. I went back to read and re-read the whole code searching for possible pointers/malloc errors. I simply can't find the reason for it to fail so often and so randomly.
So here is the strange thing - I compiled it with -g and run through GDB.
start MSYS
change dir where the program resides
$ gdb generatore.exe (the one compiled -g that fails)
$ run
And it perfectly works inside GDB. I went step by step. Line by line. Perfect. I tried stressing it with huge amounts of data. All works. Can't reproduce the error. But if the same executable is run from command line, it fails.
I suspect an unpredictable behavior with some pointer but I cannot find it anywhere.
Has anyone ever encountered anything similar? Where should I be checking? Also, I am not as familiar with GDB, since it runs smoothly, can I enforce the control somehow to find the reason it fails? Are any other free debugging solutions for windows you can advise me? How can I debug for unpredictable behaviors?
Thanks a lot for your attention,
maxim
There is a great free tool for catching all kind of runtime errors to do with pointers, memory allocations, deallocations, etc., which cannot be caught at compile time, so your compiler will not warn you about them: valgrind http://valgrind.org/. The problem is, AFAIK it doesn't run on Windows. However, if your program is pure ANSI C you should be able to build it and run it with valgrind on a Linux box.
I'm not 100% sure about it, but it should run OK in a virtual machine, so if you don't have a separate Linux computer you can try installing e.g. Ubuntu in Virtual Box or VmWare and try running your program with valgrind in it.

Xcode debugger doesn't display any code

I'm a C++ noob, have been using Terminal/gcc to compile and run my code, but wanted to make the switch to Xcode (v 3.2.5). I've been going through some tutorials but having problems getting the Debugger to work properly.
When I select Build and Debug, if my code has no errors, the Debugger and Debugger Console open and I get a message in the console that debugging ended normally.
When there are errors in the code, I get red error icons in the Editor, but neither the Debugger nor the console open automatically. This isn't a big deal, I can manually open the Debugger. What is a problem is that when I do open it, it's completely empty: nothing at all in the threads, vars or editor panes.
I'm using the default build configuration for the template Command Line Tool > C++ stdc++ (Generate Debug Symbols: on, Strip Debug Symbols: off, Optimization: off). I read the "Troubleshooting Debugger Display" section in the Xcode Debugging Guide and it seems like I'm doing all those things correctly, but as I said, I'm a beginner, so maybe I'm overlooking something really obvious? Appreciate any help, thanks!
Based on your statement about red error icons in the editor, it sounds like you have compile-time errors in your program.
I think you might be confused about what a debugger is for - it's used to find runtime errors with your code, not compile-time errors. The debugger won't be any use to you if your code isn't syntactically correct.