]> git.cworth.org Git - apitrace/blob - common/trace_backtrace.hpp
Backtrace via call detail
[apitrace] / common / trace_backtrace.hpp
1 #ifndef _TRACE_BACKTRACE_HPP_
2 #define _TRACE_BACKTRACE_HPP_
3
4 #include <vector>
5
6 #include "trace_model.hpp"
7
8 namespace trace {
9
10
11 struct RawStackFrame {
12     char* module;
13     char* function;
14     char* filename;
15     char* linenumber;
16     char* offset;
17     RawStackFrame() :
18       module(0),
19       function(0),
20       filename(0),
21       linenumber(0),
22       offset(0)
23     {
24     }
25 };
26
27 #if defined(ANDROID) or defined(__linux__)
28
29 std::vector<RawStackFrame> get_backtrace();
30 bool backtrace_is_needed(const char* fname);
31
32 #if defined(ANDROID)
33
34 #define MAX_BT_FUNC 20
35 #define PREFIX_MAX_FUNC_NAME 100
36 #define APITRACE_FNAMES_FILE "/data/apitrace.fnames"
37 #define APITRACE_FNAMES_SOURCE APITRACE_FNAMES_FILE
38
39 #elif defined(__linux__)
40
41 #define MAX_BT_FUNC 20
42 #define PREFIX_MAX_FUNC_NAME 100
43 #define APITRACE_FNAMES_ENV "APITRACE_BT_FUNCTIONS"
44 #define APITRACE_FNAMES_SOURCE APITRACE_FNAMES_ENV
45
46 #endif
47
48 #else /* !__linux__ && !ANDROID */
49
50 static inline std::vector<StackFrame> get_backtrace() {
51     return std::vector<StackFrame>();
52 }
53
54 static inline bool backtrace_is_needed(const char*) {
55     return false;
56 }
57
58 #endif
59
60 } /* namespace trace */
61
62 #endif