Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug properly and find causes for crashes?

I dont know what to do anymore... its hopeless. I'm getting tired of guessing whats causing the crashes. Recently i noticed some opengl calls crashes programs randomly on some gfx cards. so i am getting really paranoid what can cause crashes now. The bad thing on this crash is that it crashes only after a long time of using the program, so i can only guess what is the problem.

I cant remember what changes i made to the program that may cause the crashes, its been so long time. But luckily the previous version doesnt crash, so i could just copypaste some code and waste 10 hours to see at which point it starts crashing... i dont think i want to do that yet.

The program crashes after i make it to process the same files about 5 times in a row, each time it uses about 200 megabytes of memory in the process. It crashes at random times while and after the reading process.

I have createn a "safe" free() function, it checks the pointer if its not NULL, and then frees the memory, and then sets the pointer to NULL. Isn't this how it should be done?

I watched the task manager memory usage, and just before it crashed it started to eat 2 times more memory than usual. Also the program loading became exponentially slower every time i loaded the files; first few loads didnt seem much slower from each other, but then it started rapidly doubling the load speeds. What should this tell me about the crash?

Also, do i have to manually free the c++ vectors by using clear() ? Or are they freed after usage automatically, for example if i allocate vector inside a function, will it be freed every time the function has ended ? I am not storing pointers in the vector.

--

Shortly: i want to learn to catch the damn bugs as fast as possible, how do i do that? Using Visual Studio 2008.

like image 348
Newbie Avatar asked Jun 02 '10 21:06

Newbie


People also ask

How do you debug a crashed application?

You can use the stack trace available in the report details if you are using Play Console or the output of the logcat tool. If you don't have a stack trace available, you should locally reproduce the crash, either by manually testing the app or by reaching out to affected users, and reproduce it while using logcat.

How you would figure out an error without debugger?

But how to debug a program without a debugger? One possible approach which I know is simply putting print statements in your code wherever you want to check for the problems.

What causes app crashes?

Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.


1 Answers

A "random" crash that occurs sometime after a complex operation is almost certainly the result of heap corruption. Heap corruption bugs are a bitch, since they usually manifest themselves very far away from the place that actually caused the bug. My suggestion, since you're on Windows, is to use Application Verifier, which can be freely downloaded from MS.

Launch AV, configure it to watch your program, and turn on all of the memory-related options. Then run your program under a debugger. (These two things will make your program run extremely slow.) The extra checks that AV does will hopefully cause your program to crash at a different place than you've been seeing so far, but it will be the location that's the real cause of the bug.

like image 81
JSBձոգչ Avatar answered Sep 17 '22 20:09

JSBձոգչ