Code runs on the cmd line but crashes in gdb

Hi,

Please excuse cross posting but I'm not sure if this is a beginner question or a linux question so I posted in both.

I have a C++ program that calls a large library of functions. I have built it and can execute it successfully from the command line in ubuntu. I would like to step through the code in order to see what is going on in some of the functions that it calls. I am using gdb to do this. However, at a certain point in the code gdb reports a "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc".

How come the code can execute on the command line, but terminates in gdb?

Many thanks,
Greer
I suspect that you are invoking undefined behaviour.

> terminate called after throwing an instance of 'std::bad_alloc'
probably you are trying to create a really big array (by instance, of -1 elements)
backtrace
How come the code can execute on the command line, but terminates in gdb?

Probably compiling in release mode or not using +wall
Sometimes a problem will show up just because the area in one compile contained left over crud and another time that left over crud was all zeros. When I forget to zero a pointer upon creation and took for granted a func would return 0 for fail I get that.

The debugger will check for each line. Running in the open a lot of stuff can get grouped and dumped at once like with cout iostream stuff. Running in release, the app will just bail.

I usually get that message if I don't accurately use a std call where the call may finish though something didn't quite work right like sending a buffer pointer with the wrong size value.
Topic archived. No new replies allowed.