PageRenderTime 70ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/thirdparty/breakpad/common/dwarf_cfi_to_module.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 196 lines | 71 code | 33 blank | 92 comment | 0 complexity | 1e6a76d93c230cf92c47dcc24b5f39f2 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, GPL-2.0
  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. // dwarf_cfi_to_module.h: Define the DwarfCFIToModule class, which
  32. // accepts parsed DWARF call frame info and adds it to a
  33. // google_breakpad::Module object, which can write that information to
  34. // a Breakpad symbol file.
  35. #ifndef COMMON_LINUX_DWARF_CFI_TO_MODULE_H
  36. #define COMMON_LINUX_DWARF_CFI_TO_MODULE_H
  37. #include <assert.h>
  38. #include <stdio.h>
  39. #include <set>
  40. #include <string>
  41. #include <vector>
  42. #include "common/module.h"
  43. #include "common/dwarf/dwarf2reader.h"
  44. namespace google_breakpad {
  45. using dwarf2reader::CallFrameInfo;
  46. using google_breakpad::Module;
  47. using std::set;
  48. using std::string;
  49. using std::vector;
  50. // A class that accepts parsed call frame information from the DWARF
  51. // CFI parser and populates a google_breakpad::Module object with the
  52. // contents.
  53. class DwarfCFIToModule: public CallFrameInfo::Handler {
  54. public:
  55. // DwarfCFIToModule uses an instance of this class to report errors
  56. // detected while converting DWARF CFI to Breakpad STACK CFI records.
  57. class Reporter {
  58. public:
  59. // Create a reporter that writes messages to the standard error
  60. // stream. FILE is the name of the file we're processing, and
  61. // SECTION is the name of the section within that file that we're
  62. // looking at (.debug_frame, .eh_frame, etc.).
  63. Reporter(const string &file, const string &section)
  64. : file_(file), section_(section) { }
  65. virtual ~Reporter() { }
  66. // The DWARF CFI entry at OFFSET cites register REG, but REG is not
  67. // covered by the vector of register names passed to the
  68. // DwarfCFIToModule constructor, nor does it match the return
  69. // address column number for this entry.
  70. virtual void UnnamedRegister(size_t offset, int reg);
  71. // The DWARF CFI entry at OFFSET says that REG is undefined, but the
  72. // Breakpad symbol file format cannot express this.
  73. virtual void UndefinedNotSupported(size_t offset, const string &reg);
  74. // The DWARF CFI entry at OFFSET says that REG uses a DWARF
  75. // expression to find its value, but DwarfCFIToModule is not
  76. // capable of translating DWARF expressions to Breakpad postfix
  77. // expressions.
  78. virtual void ExpressionsNotSupported(size_t offset, const string &reg);
  79. protected:
  80. string file_, section_;
  81. };
  82. // Register name tables. If TABLE is a vector returned by one of these
  83. // functions, then TABLE[R] is the name of the register numbered R in
  84. // DWARF call frame information.
  85. class RegisterNames {
  86. public:
  87. // Intel's "x86" or IA-32.
  88. static vector<string> I386();
  89. // AMD x86_64, AMD64, Intel EM64T, or Intel 64
  90. static vector<string> X86_64();
  91. // ARM.
  92. static vector<string> ARM();
  93. private:
  94. // Given STRINGS, an array of C strings with SIZE elements, return an
  95. // equivalent vector<string>.
  96. static vector<string> MakeVector(const char * const *strings, size_t size);
  97. };
  98. // Create a handler for the dwarf2reader::CallFrameInfo parser that
  99. // records the stack unwinding information it receives in MODULE.
  100. //
  101. // Use REGISTER_NAMES[I] as the name of register number I; *this
  102. // keeps a reference to the vector, so the vector should remain
  103. // alive for as long as the DwarfCFIToModule does.
  104. //
  105. // Use REPORTER for reporting problems encountered in the conversion
  106. // process.
  107. DwarfCFIToModule(Module *module, const vector<string> &register_names,
  108. Reporter *reporter)
  109. : module_(module), register_names_(register_names), reporter_(reporter),
  110. entry_(NULL), return_address_(-1), cfa_name_(".cfa"), ra_name_(".ra") {
  111. }
  112. virtual ~DwarfCFIToModule() { delete entry_; }
  113. virtual bool Entry(size_t offset, uint64 address, uint64 length,
  114. uint8 version, const string &augmentation,
  115. unsigned return_address);
  116. virtual bool UndefinedRule(uint64 address, int reg);
  117. virtual bool SameValueRule(uint64 address, int reg);
  118. virtual bool OffsetRule(uint64 address, int reg,
  119. int base_register, long offset);
  120. virtual bool ValOffsetRule(uint64 address, int reg,
  121. int base_register, long offset);
  122. virtual bool RegisterRule(uint64 address, int reg, int base_register);
  123. virtual bool ExpressionRule(uint64 address, int reg,
  124. const string &expression);
  125. virtual bool ValExpressionRule(uint64 address, int reg,
  126. const string &expression);
  127. virtual bool End();
  128. private:
  129. // Return the name to use for register REG.
  130. string RegisterName(int i);
  131. // Record RULE for register REG at ADDRESS.
  132. void Record(Module::Address address, int reg, const string &rule);
  133. // The module to which we should add entries.
  134. Module *module_;
  135. // Map from register numbers to register names.
  136. const vector<string> &register_names_;
  137. // The reporter to use to report problems.
  138. Reporter *reporter_;
  139. // The current entry we're constructing.
  140. Module::StackFrameEntry *entry_;
  141. // The section offset of the current frame description entry, for
  142. // use in error messages.
  143. size_t entry_offset_;
  144. // The return address column for that entry.
  145. unsigned return_address_;
  146. // The names of the return address and canonical frame address. Putting
  147. // these here instead of using string literals allows us to share their
  148. // texts in reference-counted std::string implementations (all the
  149. // popular ones). Many, many rules cite these strings.
  150. string cfa_name_, ra_name_;
  151. // A set of strings used by this CFI. Before storing a string in one of
  152. // our data structures, insert it into this set, and then use the string
  153. // from the set.
  154. //
  155. // Because std::string uses reference counting internally, simply using
  156. // strings from this set, even if passed by value, assigned, or held
  157. // directly in structures and containers (map<string, ...>, for example),
  158. // causes those strings to share a single instance of each distinct piece
  159. // of text.
  160. set<string> common_strings_;
  161. };
  162. } // namespace google_breakpad
  163. #endif // COMMON_LINUX_DWARF_CFI_TO_MODULE_H