0

I have a c++ project where the beahviour in debug and release mode differs. E.g. in release mode i get bad alloc errors wheras in debug mode everthing runs fine. Maybe this difference comes from different runtime speed.

Do you have any tips and hints how to debug a program without a standard debugger (like gdb)? I could try to cout a lot in critical areas but that seems not be the smartest way to go... Maybe there is a way to get some information about locations of some kinds of errors without using debugging symbols? Are there any tools?

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
Simson
  • 829
  • 6
  • 16
  • are you sure the difference is casued by debugging symbol? what are the compile commands to generate debug/release binaries? – tristan Oct 11 '13 at 15:28
  • 2
    You can have debugging symbols available in a release build and it shouldn't change the behavior of the program at all. If you're having issues between debug/release builds then it's likely you have some undefined behavior or uninitialized variables that are causing issues. – Retired Ninja Oct 11 '13 at 15:33
  • Is a bad alloc error an exception? Can you catch and log the exception with a stacktrace? How much memory does each version actually use? – doctorlove Oct 11 '13 at 15:37
  • Just adding `-g` to release build's flags shouldn't change a thing in execution flow. If it does - this thing needs to be debugged. Meanwhile, you could try using separate debugging symbol map file, gdb supports this. – keltar Oct 11 '13 at 16:12
  • Kinda related question: http://stackoverflow.com/questions/4386291/c-program-dies-with-stdbad-alloc-but-valgrind-reports-no-memory-leaks – yasouser Oct 11 '13 at 21:12

1 Answers1

0

If you can get a stack trace from the crash, you may be able to symbolicate it later. For example, on MacOS there's the tool atos which, according to the man page:

converts numeric addresses to their symbolic equivalents.

This would allow you to run without symbols, but use them later.

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • For GNU toolchain, equivalent would be `addr2line`. This, however, only partially related to question. – keltar Oct 11 '13 at 16:01