/thirdparty/breakpad/common/stabs_to_module.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 143 lines · 42 code · 24 blank · 77 comment · 0 complexity · 592803bc1ef3b4026289d081e75dccd8 MD5 · raw file

  1. // -*- mode: C++ -*-
  2. // Copyright (c) 2010 Google Inc.
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
  31. // dump_stabs.h: Define the StabsToModule class, which receives
  32. // STABS debugging information from a parser and adds it to a Breakpad
  33. // symbol file.
  34. #ifndef BREAKPAD_COMMON_STABS_TO_MODULE_H_
  35. #define BREAKPAD_COMMON_STABS_TO_MODULE_H_
  36. #include <stdint.h>
  37. #include <string>
  38. #include <vector>
  39. #include "common/module.h"
  40. #include "common/stabs_reader.h"
  41. namespace google_breakpad {
  42. using std::string;
  43. using std::vector;
  44. // A StabsToModule is a handler that receives parsed STABS debugging
  45. // information from a StabsReader, and uses that to populate
  46. // a Module. (All classes are in the google_breakpad namespace.) A
  47. // Module represents the contents of a Breakpad symbol file, and knows
  48. // how to write itself out as such. A StabsToModule thus acts as
  49. // the bridge between STABS and Breakpad data.
  50. // When processing Darwin Mach-O files, this also receives public linker
  51. // symbols, like those found in system libraries.
  52. class StabsToModule: public google_breakpad::StabsHandler {
  53. public:
  54. // Receive parsed debugging information from a StabsReader, and
  55. // store it all in MODULE.
  56. StabsToModule(Module *module) :
  57. module_(module),
  58. in_compilation_unit_(false),
  59. comp_unit_base_address_(0),
  60. current_function_(NULL),
  61. current_source_file_(NULL),
  62. current_source_file_name_(NULL) { }
  63. ~StabsToModule();
  64. // The standard StabsHandler virtual member functions.
  65. bool StartCompilationUnit(const char *name, uint64_t address,
  66. const char *build_directory);
  67. bool EndCompilationUnit(uint64_t address);
  68. bool StartFunction(const string &name, uint64_t address);
  69. bool EndFunction(uint64_t address);
  70. bool Line(uint64_t address, const char *name, int number);
  71. bool Extern(const string &name, uint64_t address);
  72. void Warning(const char *format, ...);
  73. // Do any final processing necessary to make module_ contain all the
  74. // data provided by the STABS reader.
  75. //
  76. // Because STABS does not provide reliable size information for
  77. // functions and lines, we need to make a pass over the data after
  78. // processing all the STABS to compute those sizes. We take care of
  79. // that here.
  80. void Finalize();
  81. private:
  82. // An arbitrary, but very large, size to use for functions whose
  83. // size we can't compute properly.
  84. static const uint64_t kFallbackSize = 0x10000000;
  85. // The module we're contributing debugging info to.
  86. Module *module_;
  87. // The functions we've generated so far. We don't add these to
  88. // module_ as we parse them. Instead, we wait until we've computed
  89. // their ending address, and their lines' ending addresses.
  90. //
  91. // We could just stick them in module_ from the outset, but if
  92. // module_ already contains data gathered from other debugging
  93. // formats, that would complicate the size computation.
  94. vector<Module::Function *> functions_;
  95. // Boundary addresses. STABS doesn't necessarily supply sizes for
  96. // functions and lines, so we need to compute them ourselves by
  97. // finding the next object.
  98. vector<Module::Address> boundaries_;
  99. // True if we are currently within a compilation unit: we have gotten a
  100. // StartCompilationUnit call, but no matching EndCompilationUnit call
  101. // yet. We use this for sanity checks.
  102. bool in_compilation_unit_;
  103. // The base address of the current compilation unit. We use this to
  104. // recognize functions we should omit from the symbol file. (If you
  105. // know the details of why we omit these, please patch this
  106. // comment.)
  107. Module::Address comp_unit_base_address_;
  108. // The function we're currently contributing lines to.
  109. Module::Function *current_function_;
  110. // The last Module::File we got a line number in.
  111. Module::File *current_source_file_;
  112. // The pointer in the .stabstr section of the name that
  113. // current_source_file_ is built from. This allows us to quickly
  114. // recognize when the current line is in the same file as the
  115. // previous one (which it usually is).
  116. const char *current_source_file_name_;
  117. };
  118. } // namespace google_breakpad
  119. #endif // BREAKPAD_COMMON_STABS_TO_MODULE_H_