stack.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. /*
  22. ==================
  23. Sys_ShutdownSymbols
  24. ==================
  25. */
  26. void Sys_ShutdownSymbols( void ) {
  27. }
  28. #ifdef ID_BT_STUB
  29. /*
  30. ==================
  31. Sys_GetCallStack
  32. ==================
  33. */
  34. void Sys_GetCallStack( address_t *callStack, const int callStackSize ) {
  35. for ( int i = 0; i < callStackSize; i++ ) {
  36. callStack[i] = 0;
  37. }
  38. }
  39. /*
  40. ==================
  41. Sys_GetCallStackStr
  42. ==================
  43. */
  44. const char * Sys_GetCallStackStr( const address_t *callStack, const int callStackSize ) {
  45. return "";
  46. }
  47. /*
  48. ==================
  49. Sys_GetCallStackStr
  50. ==================
  51. */
  52. const char * Sys_GetCallStackCurStr( int depth ) {
  53. return "";
  54. }
  55. /*
  56. ==================
  57. Sys_GetCallStackCurAddressStr
  58. ==================
  59. */
  60. const char * Sys_GetCallStackCurAddressStr( int depth ) {
  61. return "";
  62. }
  63. #else
  64. #include <execinfo.h>
  65. /*
  66. ==================
  67. Sys_GetCallStack
  68. ==================
  69. */
  70. void Sys_GetCallStack( address_t *callStack, const int callStackSize ) {
  71. int i;
  72. i = backtrace( (void **)callStack, callStackSize );
  73. while( i < callStackSize ) {
  74. callStack[i++] = 0;
  75. }
  76. }
  77. /*
  78. ==================
  79. Sys_GetCallStackStr
  80. ==================
  81. */
  82. const char * Sys_GetCallStackStr( const address_t *callStack, int callStackSize ) {
  83. static char string[MAX_STRING_CHARS*2];
  84. char **strings;
  85. int i;
  86. strings = backtrace_symbols( (void **)callStack, callStackSize );
  87. string[ 0 ] = '\0';
  88. for ( i = 0; i < callStackSize; i++ ) {
  89. idStr::snPrintf( string + strlen( string ), MAX_STRING_CHARS*2 - strlen( string ) - 1, "%s\n", strings[ i ] );
  90. }
  91. free( strings );
  92. return string;
  93. }
  94. /*
  95. ==================
  96. Sys_GetCallStackStr
  97. ==================
  98. */
  99. const char * Sys_GetCallStackCurStr( int depth ) {
  100. address_t array[ 32 ];
  101. size_t size;
  102. size = backtrace( (void **)array, Min( 32, depth ) );
  103. return Sys_GetCallStackStr( array, (int)size );
  104. }
  105. /*
  106. ==================
  107. Sys_GetCallStackCurAddressStr
  108. ==================
  109. */
  110. const char * Sys_GetCallStackCurAddressStr( int depth ) {
  111. return Sys_GetCallStackCurStr( depth );
  112. }
  113. #endif