# New stack trace functions

**URL:** <https://forum.juce.com/t/new-stack-trace-functions/10088>\
**Category:** General JUCE discussion\
**Created:** [March 10, 2013, 6:57pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088 "2013-03-10T18:57:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 10, 2013, 6:57pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/1 "2013-03-10T18:57:54Z")

</div>

Just added something that might be helpful to some of you: I needed some crash dump functionality, so added functions SystemStats::getStackBacktrace() and SystemStats::setApplicationCrashHandler(). Feedback welcome!

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 10, 2013, 9:25pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/2 "2013-03-10T21:25:39Z")

</div>

I got this in my crash log:

```auto
Ctrlr crashed on: 10 Mar 2013 22:20:56
0: Ctrlr-Debug-Win32: juce::SystemStats::getStackBacktrace + 0x7f
1: Ctrlr-Debug-Win32: CtrlrManager::crashHandler + 0x249
2: Ctrlr-Debug-Win32: juce::handleCrash + 0xf
3: UnhandledExceptionFilter + 0x164
4: RtlCreateUserThread + 0xaadc
5: RtlInitializeExceptionChain + 0x58
```

Will setting the:JUCE\_CATCH\_UNHANDLED\_EXCEPTIONS to something help, make the crash dump a bit more informative ?

Also what can we use in the crash handler, i used the FIle() class to write the stack trace to disk, are there any dos and donts?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 10, 2013, 9:34pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/3 "2013-03-10T21:34:45Z")

</div>

hmm… I didn’t test the PC version very carefully. Might need to rethink that a bit.

```auto
are there any dos and donts?
```

Well, your app’s already crashed, so probably not much point worrying too much about dos and don’ts!

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 11, 2013, 9:14am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/4 "2013-03-11T09:14:52Z")

</div>

I know that this situation is a bad one as it is. Can i try to show a dialog window, or maybe i should prepare a different EXE (crashreporter.exe) that gets executed on crash ? I really don’t know what happens when a crash occurs that’s why i ask. I assume the memory got corrupted (i do a test crash by using a bad pointer), i know that i shouldn’t do anything and exit as quick as possible. It’s just that i need to inform the user of that fact and write some meaningful information to a CRASH file so that the poor user can send me a report.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 11, 2013, 9:18am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/5 "2013-03-11T09:18:41Z")

</div>

Probably best to avoid any UIs, but yes, you could launch another app. In tracktion I think I’ll just make it dump some info to the log file.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 11, 2013, 1:53pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/6 "2013-03-11T13:53:01Z")

</div>

I thought about starting my app just with a CLI parameter “-crash pathToExecutableThatCrashed” sort of thing co i don’t over complicate stuff.

Do you think that the stack trace on Windows can be more precise, i mean at some time in the future, i saw that you are getting a MS surface, are you getting the PRO x86 based one or the ARM based with ARM onboard ?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 11, 2013, 2:03pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/7 "2013-03-11T14:03:42Z")

</div>

> [@atom](#):
>
> Do you think that the stack trace on Windows can be more precise

Tricky… There’s nothing wrong with the stack trace function, but it seems that when Windows invokes the exception handler, it does so from a different thread than the one that crashed (doh!), so it’s showing a correct printout of the wrong stack. Not really sure what could be done about that. Suggestions welcome!

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [March 11, 2013, 2:29pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/8 "2013-03-11T14:29:44Z")

</div>

You can maybe check what BreakPad does

[http://code.google.com/p/google-breakpad/](http://code.google.com/p/google-breakpad/)

---

<div class="post-metadata">

**Author:** ![bruce-wheaton](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@bruce-wheaton](https://forum.juce.com/u/bruce-wheaton)\
**Post date:** [March 11, 2013, 7:01pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/9 "2013-03-11T19:01:04Z")

</div>

> [@jules](#):
>
> Probably best to avoid any UIs, but yes, you could launch another app. In tracktion I think I’ll just make it dump some info to the log file.

Would you mind putting an example of this sort of use into the Juce docs? I guess you’d have to re-open the apps log file and append the data?

Bruce

---

<div class="post-metadata">

**Author:** ![jpo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jpo/32/503_2.png) [@jpo](https://forum.juce.com/u/jpo)\
**Post date:** [March 11, 2013, 9:58pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/10 "2013-03-11T21:58:53Z")

</div>

I think you have to use StackWalk64 from the dbghelp.h in order to get correct backtraces in exception handlers, but it requires the ms debugging tools to be installed

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 11, 2013, 10:12pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/11 "2013-03-11T22:12:35Z")

</div>

I’ve actually gone down a different path for tracktion - even if it got the stack trace, the lack of debug info makes it fairly useless, so instead I’ve littered the more risky bits of code with some local scoped objects that keep a fake stack of file/line number positions. That works better for this scenario. I’ll leave these methods in place though, since both are still useful in their own way.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [March 12, 2013, 12:38am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/12 "2013-03-12T00:38:47Z")

</div>

> [@jules](#):
>
> …the lack of debug info makes it fairly useless…

Why not ship with debug symbols?

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [March 13, 2013, 12:59pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/13 "2013-03-13T12:59:54Z")

</div>

That begs the question. Can i ship my application binary with debug symbols in it ? will it affect performance ? Also on windows won’t it be linked to different debug DLLs that are only available if you have VS installed ?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [March 13, 2013, 3:09pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/14 "2013-03-13T15:09:31Z")

</div>

> [@atom](#):
>
> That begs the question. Can i ship my application binary with debug symbols in it ? will it affect performance ? Also on windows won’t it be linked to different debug DLLs that are only available if you have VS installed ?

Don’t confuse linking against the Debug C Runtime with producing symbols. You can have an optimized Release build that also has debug symbols and a .pdb file. In fact, you need this for most profilers to work, that’s why I kept bothering Jules to fix IntroJucer so that it could produce Release builds that have debug symbols.

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [March 13, 2013, 8:30pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/15 "2013-03-13T20:30:48Z")

</div>

> [@](#):
>
> …the lack of debug info makes it fairly useless…

there is a linker option to create a map file, which contains the offsets of the entry positions of methods (at least in VS2008)  
i made a script that copies the map file with every release build and counts a version number, which is also shown in the about dialog…

so if i have the buildnumber, i have also the mapfile, i can backtrace anything, with release builds, without build-in symbols…

---

<div class="post-metadata">

**Author:** ![svenT](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@svenT](https://forum.juce.com/u/svenT)\
**Post date:** [March 14, 2013, 8:04am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/16 "2013-03-14T08:04:36Z")

</div>

Hey,

I am fairly new to juce but this topic seems fimiliar to me. I tried to use Stackwalker in the past. Unfortuntely, I never got it working correctly.  
Please be gentle, I a newbee in this topic as well.

@chkn: you said you can create a map file for every release an you have a stacktrace. I am not sure how to create this map file. Is /MAP enough?  
The worst thing is how to connect the map file with the stacktrace (mini dump file?). I can open up VS2008 with a file FirstTry.dll.dmp. FirstTry.dll  
was a full release build with optimizations. In VS2008 I don’t see anything in the dump file, no stack trace. I case I am lucky I see the entry Function Pointer that crashes.  
Well I really like to see a full stack trace and in best cases the line number where it crahes 🙂

I hope you can help me. Until now, I am quite lost when my software crashes on the end users side.

Thank you!  
Sven

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [March 14, 2013, 10:37am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/17 "2013-03-14T10:37:51Z")

</div>

> [@](#):
>
> The worst thing is how to connect the map file with the stacktrace

i just open the map file in notepad, and look where i can find the positions from the stack trace between the offsets. You will learn how to count in hexadecimal numbers 😉  
Maybe someone could write a tool for this 😉

---

<div class="post-metadata">

**Author:** ![svenT](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@svenT](https://forum.juce.com/u/svenT)\
**Post date:** [March 14, 2013, 10:40am UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/18 "2013-03-14T10:40:28Z")

</div>

are you telling me that VS2008 doesn’t resolve this for me?

Btw, I know how to count in hex 😉

---

<div class="post-metadata">

**Author:** ![svenT](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@svenT](https://forum.juce.com/u/svenT)\
**Post date:** [March 14, 2013, 4:57pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/19 "2013-03-14T16:57:37Z")

</div>

I found it 😃 here:  
[http://dotnetforum.net/topic/67250-crash-dump-no-symbols-are-loaded-for-any-call-stack-frame-the-source-code-cannot-be-displayed/](http://dotnetforum.net/topic/67250-crash-dump-no-symbols-are-loaded-for-any-call-stack-frame-the-source-code-cannot-be-displayed/)

when I am doing this:

`1) C/C++/General; Set Debug Info Format to Program Database (/Zi)
2) Linker/Debugging; Set Generate Debug Info to Yes (/DEBUG)
3) Linker/Optimizations; Set References to Eliminate Unref Data (/OPT:REF)
4) Linker/Enable COMDAT Folding; Set to Remove Redundant COMDATs (/OPT:ICF)`

It works like a charme! I can crash my software in release mode and dumping a mini dump. After that I use VS2008 to load up the dmp attach the symbols and I can see the crash point in source code. No hex counting 😉

---

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [March 14, 2013, 6:11pm UTC](https://forum.juce.com/t/new-stack-trace-functions/10088/20 "2013-03-14T18:11:31Z")

</div>

Thanks svenT

[Next page](https://forum.juce.com/t/new-stack-trace-functions/10088.md?page=2)
