examine_stack.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright 2018 The Abseil Authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // https://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_
  17. #define ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_
  18. #include "absl/base/config.h"
  19. namespace absl {
  20. ABSL_NAMESPACE_BEGIN
  21. namespace debugging_internal {
  22. // Type of function used for printing in stack trace dumping, etc.
  23. // We avoid closures to keep things simple.
  24. typedef void OutputWriter(const char*, void*);
  25. // RegisterDebugStackTraceHook() allows to register a single routine
  26. // `hook` that is called each time DumpStackTrace() is called.
  27. // `hook` may be called from a signal handler.
  28. typedef void (*SymbolizeUrlEmitter)(void* const stack[], int depth,
  29. OutputWriter* writer, void* writer_arg);
  30. // Registration of SymbolizeUrlEmitter for use inside of a signal handler.
  31. // This is inherently unsafe and must be signal safe code.
  32. void RegisterDebugStackTraceHook(SymbolizeUrlEmitter hook);
  33. SymbolizeUrlEmitter GetDebugStackTraceHook();
  34. // Returns the program counter from signal context, or nullptr if
  35. // unknown. `vuc` is a ucontext_t*. We use void* to avoid the use of
  36. // ucontext_t on non-POSIX systems.
  37. void* GetProgramCounter(void* const vuc);
  38. // Uses `writer` to dump the program counter, stack trace, and stack
  39. // frame sizes.
  40. void DumpPCAndFrameSizesAndStackTrace(void* const pc, void* const stack[],
  41. int frame_sizes[], int depth,
  42. int min_dropped_frames,
  43. bool symbolize_stacktrace,
  44. OutputWriter* writer, void* writer_arg);
  45. // Dump current stack trace omitting the topmost `min_dropped_frames` stack
  46. // frames.
  47. void DumpStackTrace(int min_dropped_frames, int max_num_frames,
  48. bool symbolize_stacktrace, OutputWriter* writer,
  49. void* writer_arg);
  50. } // namespace debugging_internal
  51. ABSL_NAMESPACE_END
  52. } // namespace absl
  53. #endif // ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_