Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
BackTrace.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. 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 - if you've distributed a copy of the program without symbols, you can use gdb to read back symbol names with:
53 * > gdb-multiarch Output/arm-linux-gnueabi/Debug/BLKQCL-Controller
54 * info symbol 0x770368
55 * info symbol 0x1b974
56 * ... etc for each symbol returned in []
57 *
58 * \note to get symbols working on Linux (GNU linker), it may be necessary to link with -rdynamic
59 * This can be done with the Stroika configure flags:
60 * --extra-linker-args -rdynamic
61 * OR
62 * --apply-default-debug-flags
63 *
64 * \note BackTrace () Uses no Stroika classes internally (like String, InlineBuffer) etc, since
65 * doing so could create deadlocks in the likely use cases where one would want to call this, from
66 * a low level place where you might have locks.
67 *
68 * This DOES - however - however, call STL routines and C-library routines, like string::CTOR {}
69 *
70 * \note On Windows, this maybe implemented using Boost, and may use COM, initializing it with unfriendly
71 * values (like MultiThreading init).
72 *
73 * You can construct a Execution::Platform::Windows::COMInitializer before any invocations to Capture()
74 * (stacktrace) - to avoid problems caused by this (only really affects COM-based applications).
75 *
76 * \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)
77 * but it doesn't appear to have made the cat.
78 *
79 * For now, typically delegate to https://www.boost.org/doc/libs/1_65_1/doc/html/stacktrace.html
80 *
81 * \note The first few frames are internal to the implementation of BackTrace() so not interesting
82 */
83 wstring Capture (const Options& options = {});
84 }
85
86}
87#endif /*_Stroika_Foundation_Debug_Backtrace_h_*/
wstring Capture(const Options &options={})
Definition BackTrace.cpp:46