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.

3
  • 1) try to debug core dump in gdb 2) try to enable aslr in gdb (it is off by default) Commented Jun 5, 2017 at 14:33
  • 1
    @ks1322: Thanks, aslr worked for me. Commented Jun 5, 2017 at 14:40
  • 1
    The 'duplicate' question seems to be about programmatically printing a stack trace - this is more about how to use GDB on a core file. Voting to reopen. Commented Jun 6, 2017 at 12:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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ää guess I submitted mine just before the question was closed and you did not...
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.
@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ç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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.