Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to get a human readable backgrace in Allegro 4

This thread is locked; no one can reply to it. rss feed Print
How to get a human readable backgrace in Allegro 4
larienna
Member #3,185
January 2003
avatar

I ran into a buffer overflow bug this morning and it was hard to find why it crashed. The main problem is because we are in graphic mode, all the regular debugging tools does not work.

strace: did not give much information that could be used.

gdb: Freezes in graphic mode and never return to gdb, so I cannot display the backtrace or do any other commands.

Valgrind: Ended up giving me a clue that I was writting outside a buffer.

Allegro gave me a backtrace, but it looked like this:

*** Error in `/mnt/data/git/glymmer/bin/glymmer': double free or corruption (!prev): 0x000056220431cea0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x7f647571bbcb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76f96)[0x7f6475721f96]
/lib/x86_64-linux-gnu/libc.so.6(+0x777de)[0x7f64757227de]
/mnt/data/git/glymmer/bin/glymmer(+0x1bb3)[0x56220377ebb3]
/mnt/data/git/glymmer/bin/glymmer(+0x10b8)[0x56220377e0b8]
/mnt/data/git/glymmer/bin/glymmer(+0x11b0)[0x56220377e1b0]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7f64756cb2b1]
/mnt/data/git/glymmer/bin/glymmer(+0xeaa)[0x56220377deaa]

It does not give me any filename, function name or lines of code. Not very useful. Debbuging symbols were activated.

Else, I need to add tons of debugging message on the console and see where it fails. It's just long and annoying and it waste of time.

Any suggestions?

Enjoy! and have fun

Dizzy Egg
Member #10,824
March 2009
avatar

Double free means you are trying to free a pointer to something that has already been free’d. So if you malloc something, then free it, then try and free it again. Set your pointers to null after freeing them, and then check pointers are not null before freeing them, and you should avoid double free errors.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Chris Katko
Member #1,881
January 2002
avatar

larienna said:

gdb: Freezes in graphic mode and never return to gdb, so I cannot display the backtrace or do any other commands.

That's not normal or right. You must be doing something pretty evil. I've never had it hang and I would immediately search for solutions to that. You can't solve problems if your tools don't work. When it does work, make sure you're looking at backtraces for the correct thread as it won't always start in the Allegro thread.

Quote:

*** Error in `/mnt/data/git/glymmer/bin/glymmer': double free or corruption (!prev): 0x000056220431cea0 ***

Is "!prev" a function for a custom-made double linked list? Is this a C or C++ program?

ala

https://en.cppreference.com/w/cpp/iterator/prev

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

larienna
Member #3,185
January 2003
avatar

I already found the bug, I was writting into a 2D dynamically allocated buffer, but I did not crop my values, so I was writting outside the limits of the buffer. I just clamped X and Y to the limits of the screen and it worked.

It's just that I would have like to have a way to backtrace my program with meaningful information, but I can't. Only valgrind seems usable with graphic mode applications.

Else I though that maybe if I run the program in windowed mode instead of fullscreen I could maybe have a debugger into another window. The idea is to avoid getting into a situation where you spend days trying to figure out a bug.

So I was wondering if there was any tools that worked well with allegro?
And if there was a way to get a meaningful backtrace?

Enjoy! and have fun

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

larienna
Member #3,185
January 2003
avatar

I made a test by using mode "GFX_AUTODETECT_WINDOWED" and run my program from gdb and it seems to work. I made a division by zero and could display a backtrace. So maybe I could have a kind of debug mode where I use the windowed mode instead to use GDB. Here is an example of backtrace results:

(gdb) bt
#0  0x0000555555555bc0 in gm_draw_dialog_stack (bmp=0x555555799af0, 
    engine=0x7fffffffde00) at /mnt/data/git/glymmer/src/lib/engine.c:112
#1  0x00005555555551b0 in main (argc=1, args=0x7fffffffdf58)
    at /mnt/data/git/glymmer/src/demo/main.c:79

Enjoy! and have fun

Go to: