master
h 69 lines 2.31 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_STACKTRACE_COMMON_H
4 #define NETDATA_STACKTRACE_COMMON_H 1
5
6 #include "libnetdata/libnetdata.h"
7 #include "stacktrace.h"
8 #include "../libjudy/judyl-typed.h"
9
10 #define NO_STACK_TRACE_PREFIX STACK_TRACE_INFO_PREFIX "stack trace is not available, "
11
12 #if defined(HAVE_LIBBACKTRACE)
13 #include "backtrace-supported.h"
14 #if BACKTRACE_SUPPORTED == 1
15 #define USE_LIBBACKTRACE 1
16 #endif
17 #endif
18
19 #if !defined(USE_LIBBACKTRACE) && defined(HAVE_LIBUNWIND)
20 #define USE_LIBUNWIND 1
21 #endif
22
23 #if !defined(USE_LIBBACKTRACE) && !defined(USE_LIBUNWIND) && defined(HAVE_BACKTRACE)
24 #define USE_BACKTRACE 1
25 #endif
26
27 #if !defined(USE_LIBBACKTRACE) && !defined(USE_LIBUNWIND) && !defined(USE_BACKTRACE) && !defined(HAVE_BACKTRACE)
28 #define USE_NOTRACE 1
29 #endif
30
31 // The structure for stacktrace storage
32 struct stacktrace {
33 uint64_t hash; // Hash of the stack trace
34 char *text; // Text representation (cached, lazy-initialized)
35 int frame_count; // Number of frames
36 void *frames[1]; // Variable-length array of frame pointers
37 };
38
39 // Cache for storing stack traces
40 DEFINE_JUDYL_TYPED(STACKTRACE, struct stacktrace *);
41 extern STACKTRACE_JudyLSet stacktrace_cache;
42 extern SPINLOCK stacktrace_lock;
43 extern bool cache_initialized;
44
45 // Filter names
46 extern const char *signal_handler_function;
47 extern const char *auxiliary_functions[];
48 extern const char *logging_functions[];
49
50 // Thread-local storage for root cause
51 extern __thread char root_cause_function[48];
52
53 // Common helper functions
54 void stacktrace_cache_init(void);
55 struct stacktrace *stacktrace_create(int num_frames);
56 bool stacktrace_is_auxiliary_function(const char *function);
57 bool stacktrace_is_logging_function(const char *function);
58 bool stacktrace_contains_logging_function(const char *text);
59 bool stacktrace_is_netdata_function(const char *function, const char *filename);
60 bool stacktrace_is_signal_handler_function(const char *function);
61 bool stacktrace_contains_signal_handler_function(const char *text);
62 void stacktrace_keep_first_root_cause_function(const char *function);
63
64 // Implementation-specific declarations
65 void impl_stacktrace_init(void);
66 int impl_stacktrace_get_frames(void **frames, int max_frames, int skip_frames);
67 void impl_stacktrace_to_buffer(STACKTRACE trace, BUFFER *wb);
68
69 #endif /* NETDATA_STACKTRACE_COMMON_H */