jaulib v1.3.0
Jau Support Library (C++, Java, ..)
backtrace.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef JAU_BACKTRACE_HPP_
26#define JAU_BACKTRACE_HPP_
27
28#include <string>
29
30#include <jau/int_types.hpp>
31
32namespace jau {
33
34 /**
35 * Returns a de-mangled backtrace string separated by newline excluding this function.
36 * <p>
37 * Returns one line per stack frame, each with
38 * <pre>
39 * - stack frame number
40 * - demangled function name + offset (sp)
41 * - the instruction pointer (pc)
42 * - the stack pointer (sp)
43 * </pre>
44 * </p>
45 * @param skip_anon_frames if true, skip all frames w/o proc-name
46 * @param max_frames number of stack frames to be printed or -1 for unlimited, defaults to -1
47 * @param skip_frames number of stack frames to skip, default is one frame for this function.
48 * @return the de-mangled backtrace, separated by newline
49 */
50 std::string get_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=1) noexcept;
51
52 /**
53 * Prints the de-mangled backtrace string separated by newline excluding this function to stderr, using get_backtrace().
54 * @param skip_anon_frames if true, skip all frames w/o proc-name
55 * @param max_frames number of stack frames to be printed or -1 for unlimited, defaults to -1
56 * @param skip_frames number of stack frames to skip, default is two frames for this function and for get_backtrace().
57 * @see get_backtrace()
58 */
59 void print_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=2) noexcept;
60
61} // namespace jau
62
63#endif /* JAU_BACKTRACE_HPP_ */
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
Definition: int_types.hpp:65
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
std::string get_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=1) noexcept
Returns a de-mangled backtrace string separated by newline excluding this function.
Definition: debug.cpp:94
void print_backtrace(const bool skip_anon_frames, const jau::snsize_t max_frames=-1, const jau::snsize_t skip_frames=2) noexcept
Prints the de-mangled backtrace string separated by newline excluding this function to stderr,...
Definition: debug.cpp:173