doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stack.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #include "../../idlib/precompiled.h"
29 
30 /*
31 ==================
32 Sys_ShutdownSymbols
33 ==================
34 */
35 void Sys_ShutdownSymbols( void ) {
36 }
37 
38 #ifdef ID_BT_STUB
39 
40 /*
41 ==================
42 Sys_GetCallStack
43 ==================
44 */
45 void Sys_GetCallStack( address_t *callStack, const int callStackSize ) {
46  for ( int i = 0; i < callStackSize; i++ ) {
47  callStack[i] = 0;
48  }
49 }
50 
51 /*
52 ==================
53 Sys_GetCallStackStr
54 ==================
55 */
56 const char * Sys_GetCallStackStr( const address_t *callStack, const int callStackSize ) {
57  return "";
58 }
59 
60 /*
61 ==================
62 Sys_GetCallStackStr
63 ==================
64 */
65 const char * Sys_GetCallStackCurStr( int depth ) {
66  return "";
67 }
68 
69 /*
70 ==================
71 Sys_GetCallStackCurAddressStr
72 ==================
73 */
74 const char * Sys_GetCallStackCurAddressStr( int depth ) {
75  return "";
76 }
77 
78 #else
79 
80 #include <execinfo.h>
81 
82 /*
83 ==================
84 Sys_GetCallStack
85 ==================
86 */
87 void Sys_GetCallStack( address_t *callStack, const int callStackSize ) {
88  int i;
89  i = backtrace( (void **)callStack, callStackSize );
90  while( i < callStackSize ) {
91  callStack[i++] = 0;
92  }
93 }
94 
95 /*
96 ==================
97 Sys_GetCallStackStr
98 ==================
99 */
100 const char * Sys_GetCallStackStr( const address_t *callStack, int callStackSize ) {
101  static char string[MAX_STRING_CHARS*2];
102  char **strings;
103  int i;
104 
105  strings = backtrace_symbols( (void **)callStack, callStackSize );
106  string[ 0 ] = '\0';
107  for ( i = 0; i < callStackSize; i++ ) {
108  idStr::snPrintf( string + strlen( string ), MAX_STRING_CHARS*2 - strlen( string ) - 1, "%s\n", strings[ i ] );
109  }
110  free( strings );
111  return string;
112 }
113 
114 
115 /*
116 ==================
117 Sys_GetCallStackStr
118 ==================
119 */
120 const char * Sys_GetCallStackCurStr( int depth ) {
121  address_t array[ 32 ];
122  size_t size;
123 
124  size = backtrace( (void **)array, Min( 32, depth ) );
125  return Sys_GetCallStackStr( array, (int)size );
126 }
127 
128 /*
129 ==================
130 Sys_GetCallStackCurAddressStr
131 ==================
132 */
134  return Sys_GetCallStackCurStr( depth );
135 }
136 
137 #endif
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
Definition: Str.cpp:1465
const char * Sys_GetCallStackStr(const address_t *callStack, int callStackSize)
Definition: stack.cpp:100
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:2878
GLenum GLsizei const GLvoid * string
Definition: glext.h:3472
int i
Definition: process.py:33
#define MAX_STRING_CHARS
Definition: Lib.h:95
void Sys_GetCallStack(address_t *callStack, const int callStackSize)
Definition: stack.cpp:87
void Sys_ShutdownSymbols(void)
Definition: stack.cpp:35
GLsizeiptr size
Definition: glext.h:3112
const char * Sys_GetCallStackCurStr(int depth)
Definition: stack.cpp:120
unsigned long address_t
Definition: sys_public.h:234
ID_INLINE T Min(T x, T y)
Definition: Lib.h:159
const char * Sys_GetCallStackCurAddressStr(int depth)
Definition: stack.cpp:133