1

I normally use GDB (in Linux, with the Qt Creator debugger GUI) to debug. But right now I have a crash that refuses to ever happen when running under the debugger, yet happens easily when running outside of it.

How do I get a stack trace of my crash, in these circumstances?

A linux-specific solution is OK.

Note: I'm talking about running a debug build only, even when it's run outside the debugger.

Stefan Monov
  • 11,332
  • 10
  • 63
  • 120

1 Answers1

3

The easiest way to be sure you can obtain a stacktrace after a crash is to run

ulimit -c unlimited

In your shell before starting the program. This will ensure that the kernel is allowed to produce a "core dump" of unlimited size (for many distros the default size is 0) when a program crashes.

That core file can then be loaded into gdb as gdb programfile corefile and then the command thread apply all bt will give you stack traces for all threads for that specific crash (use just bt if you only care about the crashing thread).

You can also use the pstack program to get a stacktrace from a running program.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • How did you manage to post your answer? I was writing mine before your answer showed up, and suddenly question was closed. FWIW, I had some info not available in your answer. – Erik Alapää Jun 05 '17 at 14:39
  • @Erik Alapää guess I submitted mine just before the question was closed and you did not... – Jesper Juhl Jun 05 '17 at 14:41
  • Probaby so ;) Anyway, it is kind of annoying with these SO police officers closing questions that are relevant. I don't care that almost duplicates exist, often, there are suble differences or new developments that merit a new answer. – Erik Alapää Jun 05 '17 at 14:43
  • @ErikAlapää The question was closed by Community. Community is a special account that preforms actions automatically according to votes cast by the Stack Overflow community. That is to say, in this case, the "SO police officers" is the SO community. – François Andrieux Jun 05 '17 at 14:48
  • @FrançoisAndrieux As far as I am concerned, if there are disciples asking questions, and knowledgeable people answering the questions, the 'community' should refrain from interfering with their exchange of information on SO. – Erik Alapää Jun 05 '17 at 23:18