You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

symbolize.h 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2018 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // -----------------------------------------------------------------------------
  16. // File: symbolize.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This file configures the Abseil symbolizer for use in converting instruction
  20. // pointer addresses (program counters) into human-readable names (function
  21. // calls, etc.) within Abseil code.
  22. //
  23. // The symbolizer may be invoked from several sources:
  24. //
  25. // * Implicitly, through the installation of an Abseil failure signal handler.
  26. // (See failure_signal_handler.h for more information.)
  27. // * By calling `Symbolize()` directly on a program counter you obtain through
  28. // `absl::GetStackTrace()` or `absl::GetStackFrames()`. (See stacktrace.h
  29. // for more information.
  30. // * By calling `Symbolize()` directly on a program counter you obtain through
  31. // other means (which would be platform-dependent).
  32. //
  33. // In all of the above cases, the symbolizer must first be initialized before
  34. // any program counter values can be symbolized. If you are installing a failure
  35. // signal handler, initialize the symbolizer before you do so.
  36. //
  37. // Example:
  38. //
  39. // int main(int argc, char** argv) {
  40. // // Initialize the Symbolizer before installing the failure signal handler
  41. // absl::InitializeSymbolizer(argv[0]);
  42. //
  43. // // Now you may install the failure signal handler
  44. // absl::FailureSignalHandlerOptions options;
  45. // absl::InstallFailureSignalHandler(options);
  46. //
  47. // // Start running your main program
  48. // ...
  49. // return 0;
  50. // }
  51. //
  52. #ifndef ABSL_DEBUGGING_SYMBOLIZE_H_
  53. #define ABSL_DEBUGGING_SYMBOLIZE_H_
  54. #include "absl/debugging/internal/symbolize.h"
  55. namespace absl
  56. {
  57. ABSL_NAMESPACE_BEGIN
  58. // InitializeSymbolizer()
  59. //
  60. // Initializes the program counter symbolizer, given the path of the program
  61. // (typically obtained through `main()`s `argv[0]`). The Abseil symbolizer
  62. // allows you to read program counters (instruction pointer values) using their
  63. // human-readable names within output such as stack traces.
  64. //
  65. // Example:
  66. //
  67. // int main(int argc, char *argv[]) {
  68. // absl::InitializeSymbolizer(argv[0]);
  69. // // Now you can use the symbolizer
  70. // }
  71. void InitializeSymbolizer(const char* argv0);
  72. //
  73. // Symbolize()
  74. //
  75. // Symbolizes a program counter (instruction pointer value) `pc` and, on
  76. // success, writes the name to `out`. The symbol name is demangled, if possible.
  77. // Note that the symbolized name may be truncated and will be NUL-terminated.
  78. // Demangling is supported for symbols generated by GCC 3.x or newer). Returns
  79. // `false` on failure.
  80. //
  81. // Example:
  82. //
  83. // // Print a program counter and its symbol name.
  84. // static void DumpPCAndSymbol(void *pc) {
  85. // char tmp[1024];
  86. // const char *symbol = "(unknown)";
  87. // if (absl::Symbolize(pc, tmp, sizeof(tmp))) {
  88. // symbol = tmp;
  89. // }
  90. // absl::PrintF("%p %s\n", pc, symbol);
  91. // }
  92. bool Symbolize(const void* pc, char* out, int out_size);
  93. ABSL_NAMESPACE_END
  94. } // namespace absl
  95. #endif // ABSL_DEBUGGING_SYMBOLIZE_H_