Skip to content

Commit 4bbd707

Browse files
committed
fix(base):1.10.22, 规避由于uclibc不支持execinfo.h导致编译出错的问题
1 parent fa1fc51 commit 4bbd707

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

modules/base/backtrace.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,42 @@
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+
3146
namespace tbox {
3247

3348
std::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

version.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
# TBOX版本号
2222
TBOX_VERSION_MAJOR := 1
2323
TBOX_VERSION_MINOR := 10
24-
TBOX_VERSION_REVISION := 21
24+
TBOX_VERSION_REVISION := 22

0 commit comments

Comments
 (0)