OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // GetStack{Trace,Frames}WithContext() | 283 // GetStack{Trace,Frames}WithContext() |
284 // | 284 // |
285 // These functions take the following args: | 285 // These functions take the following args: |
286 // void** result: the stack-trace, as an array | 286 // void** result: the stack-trace, as an array |
287 // int* sizes: the size of each stack frame, as an array | 287 // int* sizes: the size of each stack frame, as an array |
288 // (GetStackFrames* only) | 288 // (GetStackFrames* only) |
289 // int max_depth: the size of the result (and sizes) array(s) | 289 // int max_depth: the size of the result (and sizes) array(s) |
290 // int skip_count: how many stack pointers to skip before storing in result | 290 // int skip_count: how many stack pointers to skip before storing in result |
291 // void* ucp: a ucontext_t* (GetStack{Trace,Frames}WithContext only) | 291 // void* ucp: a ucontext_t* (GetStack{Trace,Frames}WithContext only) |
292 | 292 |
| 293 //typedef int PseudoStackFunction(void** stack); |
| 294 //extern PseudoStackFunction* pseudo_stack_function; |
| 295 //int GET_STACK_TRACE_OR_FRAMES { |
| 296 // int n = pseudo_stack_function(result); |
| 297 //#if IS_STACK_FRAMES |
| 298 // // TODO(jamescook): Can we just skip this? |
| 299 // memset(sizes, 0, n * sizeof(void*)); // Report unknown size. |
| 300 //#endif |
| 301 // return n; |
| 302 //} |
| 303 |
293 int GET_STACK_TRACE_OR_FRAMES { | 304 int GET_STACK_TRACE_OR_FRAMES { |
294 void **sp; | 305 void **sp; |
295 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) || __llvm__ | 306 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) || __llvm__ |
296 // __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8. | 307 // __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8. |
297 // It's always correct on llvm, and the techniques below aren't (in | 308 // It's always correct on llvm, and the techniques below aren't (in |
298 // particular, llvm-gcc will make a copy of pcs, so it's not in sp[2]), | 309 // particular, llvm-gcc will make a copy of pcs, so it's not in sp[2]), |
299 // so we also prefer __builtin_frame_address when running under llvm. | 310 // so we also prefer __builtin_frame_address when running under llvm. |
300 sp = reinterpret_cast<void**>(__builtin_frame_address(0)); | 311 sp = reinterpret_cast<void**>(__builtin_frame_address(0)); |
301 #elif defined(__i386__) | 312 #elif defined(__i386__) |
302 // Stack frame format: | 313 // Stack frame format: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 n++; | 398 n++; |
388 continue; | 399 continue; |
389 } | 400 } |
390 } | 401 } |
391 break; | 402 break; |
392 } | 403 } |
393 } | 404 } |
394 #endif // KEEP_SHADOW_STACKS | 405 #endif // KEEP_SHADOW_STACKS |
395 return n; | 406 return n; |
396 } | 407 } |
OLD | NEW |