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 1717 * project authors may be found in the CONTRIBUTORS.md file in the root
1818 * of the source tree.
1919 */
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>
2820
2921#include " backtrace.h"
3022
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+
3146namespace tbox {
3247
3348std::string DumpBacktrace (const unsigned int max_frames)
3449{
50+ std::ostringstream oss;
51+
52+ #if HAVE_EXECINFO_H
3553 Dl_info info;
3654
3755 void *callstack[max_frames];
38- std::ostringstream oss;
3956
4057 unsigned int number_frames = ::backtrace (callstack, max_frames);
4158 char **symbols = ::backtrace_symbols (callstack, number_frames);
@@ -68,6 +85,10 @@ std::string DumpBacktrace(const unsigned int max_frames)
6885 if (number_frames >= max_frames)
6986 oss << " [truncated]" << std::endl;
7087
88+ #else
89+ oss << " not support backtrace" << std::endl;
90+ #endif // HAVE_EXECINFO_H
91+
7192 return oss.str ();
7293}
7394
Original file line number Diff line number Diff line change 2121# TBOX版本号
2222TBOX_VERSION_MAJOR := 1
2323TBOX_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