VR-Vantage 2.8 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TracyCallstack.hpp
Go to the documentation of this file.
1 #ifndef __TRACYCALLSTACK_HPP__
2 #define __TRACYCALLSTACK_HPP__
3 
4 #include "../common/TracyApi.h"
5 #include "TracyCallstack.h"
6 
7 #if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5
8 # include <unwind.h>
9 #elif TRACY_HAS_CALLSTACK >= 3
10 # include <execinfo.h>
11 #endif
12 
13 
14 #ifdef TRACY_HAS_CALLSTACK
15 
16 #include <assert.h>
17 #include <stdint.h>
18 
19 #include "../common/TracyAlloc.hpp"
20 #include "../common/TracyForceInline.hpp"
21 
22 namespace tracy
23 {
24 
25 struct CallstackSymbolData
26 {
27  const char* file;
28  uint32_t line;
29  bool needFree;
30 };
31 
32 struct CallstackEntry
33 {
34  const char* name;
35  const char* file;
36  uint32_t line;
37  uint32_t symLen;
38  uint64_t symAddr;
39 };
40 
41 struct CallstackEntryData
42 {
43  const CallstackEntry* data;
44  uint8_t size;
45  const char* imageName;
46 };
47 
48 CallstackSymbolData DecodeSymbolAddress( uint64_t ptr );
49 CallstackSymbolData DecodeCodeAddress( uint64_t ptr );
50 const char* DecodeCallstackPtrFast( uint64_t ptr );
51 CallstackEntryData DecodeCallstackPtr( uint64_t ptr );
52 void InitCallstack();
53 
54 #if TRACY_HAS_CALLSTACK == 1
55 
56 TRACY_API uintptr_t* CallTrace( int depth );
57 
58 static tracy_force_inline void* Callstack( int depth )
59 {
60  assert( depth >= 1 && depth < 63 );
61  return CallTrace( depth );
62 }
63 
64 #elif TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5
65 
66 struct BacktraceState
67 {
68  void** current;
69  void** end;
70 };
71 
72 static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, void* arg )
73 {
74  auto state = (BacktraceState*)arg;
75  uintptr_t pc = _Unwind_GetIP( ctx );
76  if( pc )
77  {
78  if( state->current == state->end ) return _URC_END_OF_STACK;
79  *state->current++ = (void*)pc;
80  }
81  return _URC_NO_REASON;
82 }
83 
84 static tracy_force_inline void* Callstack( int depth )
85 {
86  assert( depth >= 1 && depth < 63 );
87 
88  auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
89  BacktraceState state = { (void**)(trace+1), (void**)(trace+1+depth) };
90  _Unwind_Backtrace( tracy_unwind_callback, &state );
91 
92  *trace = (uintptr_t*)state.current - trace + 1;
93 
94  return trace;
95 }
96 
97 #elif TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6
98 
99 static tracy_force_inline void* Callstack( int depth )
100 {
101  assert( depth >= 1 );
102 
103  auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
104  const auto num = backtrace( (void**)(trace+1), depth );
105  *trace = num;
106 
107  return trace;
108 }
109 
110 #endif
111 
112 }
113 
114 #endif
115 
116 #endif


Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)