File tree Expand file tree Collapse file tree 2 files changed +31
-10
lines changed Expand file tree Collapse file tree 2 files changed +31
-10
lines changed Original file line number Diff line number Diff line change 17
17
* project authors may be found in the CONTRIBUTORS.md file in the root
18
18
* of the source tree.
19
19
*/
20
- #include < unistd.h>
21
- #include < execinfo.h>
22
- #include < cxxabi.h>
23
- #include < dlfcn.h>
24
-
25
- #include < iostream>
26
- #include < iomanip>
27
- #include < sstream>
28
20
29
21
#include " backtrace.h"
30
22
23
+ /* *
24
+ * 目前只有glibc支持execinfo.h,其它库如uclibc是没有支持。为避免编译出错,在此区别处理
25
+ * 如果外面没有指定HAVE_EXECINFO_H,则根据是否采用glibc库自动处理
26
+ */
27
+ #ifndef HAVE_EXECINFO_H
28
+ # ifdef __GLIBC__
29
+ # define HAVE_EXECINFO_H 1
30
+ # else
31
+ # define HAVE_EXECINFO_H 0
32
+ # endif // __GLIBC__
33
+ #endif // HAVE_EXECINFO_H
34
+
35
+ #if HAVE_EXECINFO_H
36
+ # include < execinfo.h>
37
+ # include < cxxabi.h>
38
+ # include < dlfcn.h>
39
+ # include < unistd.h>
40
+ # include < iostream>
41
+ # include < iomanip>
42
+ #endif // HAVE_EXECINFO_H
43
+
44
+ #include < sstream>
45
+
31
46
namespace tbox {
32
47
33
48
std::string DumpBacktrace (const unsigned int max_frames)
34
49
{
50
+ std::ostringstream oss;
51
+
52
+ #if HAVE_EXECINFO_H
35
53
Dl_info info;
36
54
37
55
void *callstack[max_frames];
38
- std::ostringstream oss;
39
56
40
57
unsigned int number_frames = ::backtrace (callstack, max_frames);
41
58
char **symbols = ::backtrace_symbols (callstack, number_frames);
@@ -68,6 +85,10 @@ std::string DumpBacktrace(const unsigned int max_frames)
68
85
if (number_frames >= max_frames)
69
86
oss << " [truncated]" << std::endl;
70
87
88
+ #else
89
+ oss << " not support backtrace" << std::endl;
90
+ #endif // HAVE_EXECINFO_H
91
+
71
92
return oss.str ();
72
93
}
73
94
Original file line number Diff line number Diff line change 21
21
# TBOX版本号
22
22
TBOX_VERSION_MAJOR := 1
23
23
TBOX_VERSION_MINOR := 10
24
- TBOX_VERSION_REVISION := 21
24
+ TBOX_VERSION_REVISION := 22
You can’t perform that action at this time.
0 commit comments