Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
BackTrace.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Debug_Backtrace_h_
5#define _Stroika_Foundation_Debug_Backtrace_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <limits>
10
12
13/**
14 * \file
15 *
16 */
17
18namespace Stroika::Foundation::Debug {
19
20 namespace BackTrace {
21 struct Options {
22 /**
23 * SkipFrames allows skipping the initial couple of frames that are really implementation details of the stacktrace code
24 * and uninteresting.
25 */
26 optional<unsigned int> fSkipFrames;
27 static inline unsigned int sDefault_SkipFrames = 0;
28
29 /**
30 * Max frames to return (doesn't count skipped frames)
31 */
32 optional<unsigned int> fMaxFrames;
33 static inline unsigned int sDefault_MaxFrames = numeric_limits<unsigned int>::max ();
34
35 /**
36 * IncludeSourceLines wont always work, and defaults off cuz makes stacktrace longer without adding much value.
37 */
38 optional<bool> fIncludeSourceLines;
39 static inline bool sDefault_IncludeSourceLines = false;
40 };
41
42 /**
43 * Return a string/printable version of the current stack backtrace (deepest part of the stack first). This is handy in debugging.
44 *
45 * This function will fail gracefully and return an empty string if needed.
46 *
47 * There are cases where one would want to limit the number of 'stack frames' returned - since this is just used
48 * for debugging...
49 *
50 * The frames are EOL (line) delimited.
51 *
52 * \note ***Not Cancelation Point*** - but since it allocates memory, it can throw
53 *
54 * \note - if you've distributed a copy of the program without symbols, you can use gdb to read back symbol names with:
55 * > gdb-multiarch Output/arm-linux-gnueabi/Debug/BLKQCL-Controller
56 * info symbol 0x770368
57 * info symbol 0x1b974
58 * ... etc for each symbol returned in []
59 *
60 * \note to get symbols working on Linux (GNU linker), it may be necessary to link with -rdynamic
61 * This can be done with the Stroika configure flags:
62 * --extra-linker-args -rdynamic
63 * OR
64 * --apply-default-debug-flags
65 *
66 * \note BackTrace () Uses no Stroika classes internally (like String, InlineBuffer) etc, since
67 * doing so could create deadlocks in the likely use cases where one would want to call this, from
68 * a low level place where you might have locks.
69 *
70 * This DOES - however - however, call STL routines and C-library routines, like string::CTOR {}
71 *
72 * \note On Windows, this maybe implemented using Boost, and may use COM, initializing it with unfriendly
73 * values (like MultiThreading init).
74 *
75 * You can construct a Execution::Platform::Windows::COMInitializer before any invocations to Capture()
76 * (stacktrace) - to avoid problems caused by this (only really affects COM-based applications).
77 *
78 * \note There was a proposal to add something like this to C++20 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0881r5.html)
79 * but it doesn't appear to have made the cat.
80 *
81 * For now, typically delegate to https://www.boost.org/doc/libs/1_65_1/doc/html/stacktrace.html
82 *
83 * \note The first few frames are internal to the implementation of BackTrace() so not interesting
84 */
85 wstring Capture (const Options& options = {});
86 }
87
88}
89#endif /*_Stroika_Foundation_Debug_Backtrace_h_*/
wstring Capture(const Options &options={})
Definition BackTrace.cpp:47