Skip to content

Commit be7b116

Browse files
authored
Merge pull request #1118 from siliceum/refactor/libbacktrace-integration
Refactor libbacktrace usage with TRACY_USE_LIBBACKTRACE
2 parents 23be6a0 + 8c06fec commit be7b116

3 files changed

Lines changed: 26 additions & 24 deletions

File tree

public/TracyClient.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,8 @@
3535
#ifdef TRACY_ROCPROF
3636
# include "client/TracyRocprof.cpp"
3737
#endif
38-
39-
#if defined(TRACY_HAS_CALLSTACK)
40-
# if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
41-
# include "libbacktrace/alloc.cpp"
42-
# include "libbacktrace/dwarf.cpp"
43-
# include "libbacktrace/fileline.cpp"
44-
# include "libbacktrace/mmapio.cpp"
45-
# include "libbacktrace/posix.cpp"
46-
# include "libbacktrace/sort.cpp"
47-
# include "libbacktrace/state.cpp"
48-
# if TRACY_HAS_CALLSTACK == 4
49-
# include "libbacktrace/macho.cpp"
50-
# else
51-
# include "libbacktrace/elf.cpp"
52-
# endif
53-
# include "common/TracyStackFrames.cpp"
54-
# endif
55-
#endif
56-
5738
#ifdef _MSC_VER
5839
# pragma comment(lib, "ws2_32.lib")
59-
# pragma comment(lib, "dbghelp.lib")
6040
# pragma comment(lib, "advapi32.lib")
6141
# pragma comment(lib, "user32.lib")
6242
# pragma warning(pop)

public/client/TracyCallstack.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,33 @@
2424
# pragma warning( disable : 4091 )
2525
# endif
2626
# include <dbghelp.h>
27+
# pragma comment( lib, "dbghelp.lib" )
2728
# ifdef _MSC_VER
2829
# pragma warning( pop )
2930
# endif
30-
#elif TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
31+
#elif defined(TRACY_USE_LIBBACKTRACE)
32+
3133
# include "../libbacktrace/backtrace.hpp"
3234
# include <algorithm>
3335
# include <dlfcn.h>
3436
# include <cxxabi.h>
3537
# include <stdlib.h>
38+
39+
// Implementation files
40+
# include "../libbacktrace/alloc.cpp"
41+
# include "../libbacktrace/dwarf.cpp"
42+
# include "../libbacktrace/fileline.cpp"
43+
# include "../libbacktrace/mmapio.cpp"
44+
# include "../libbacktrace/posix.cpp"
45+
# include "../libbacktrace/sort.cpp"
46+
# include "../libbacktrace/state.cpp"
47+
# if TRACY_HAS_CALLSTACK == 4
48+
# include "../libbacktrace/macho.cpp"
49+
# else
50+
# include "../libbacktrace/elf.cpp"
51+
# endif
52+
# include "../common/TracyStackFrames.cpp"
53+
3654
#elif TRACY_HAS_CALLSTACK == 5
3755
# include <dlfcn.h>
3856
# include <cxxabi.h>
@@ -53,7 +71,7 @@ extern "C"
5371
};
5472
#endif
5573

56-
#if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 5 || TRACY_HAS_CALLSTACK == 6
74+
#if defined(TRACY_USE_LIBBACKTRACE) || TRACY_HAS_CALLSTACK == 5
5775
// If you want to use your own demangling functionality (e.g. for another language),
5876
// define TRACY_DEMANGLE and provide your own implementation of the __tracy_demangle
5977
// function. The input parameter is a function name. The demangle function must
@@ -91,7 +109,7 @@ extern "C" const char* ___tracy_demangle( const char* mangled )
91109
#endif
92110
#endif
93111

94-
#if TRACY_HAS_CALLSTACK == 3
112+
#if defined(TRACY_USE_LIBBACKTRACE) && TRACY_HAS_CALLSTACK != 4 // dl_iterate_phdr is required for the current image cache. Need to move it to libbacktrace?
95113
# define TRACY_USE_IMAGE_CACHE
96114
# include <link.h>
97115
#endif
@@ -758,7 +776,7 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
758776
return { cb_data, uint8_t( cb_num ), moduleNameAndAddress.name };
759777
}
760778

761-
#elif TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
779+
#elif defined(TRACY_USE_LIBBACKTRACE)
762780

763781
enum { MaxCbTrace = 64 };
764782

public/client/TracyCallstack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
# define TRACY_HAS_CALLSTACK 6
3131
# endif
3232

33+
#if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
34+
#define TRACY_USE_LIBBACKTRACE
35+
#endif
36+
3337
#endif
3438

3539
#endif

0 commit comments

Comments
 (0)