/thirdparty/breakpad/common/dwarf/functioninfo.h

http://github.com/tomahawk-player/tomahawk · C Header · 188 lines · 86 code · 28 blank · 74 comment · 0 complexity · d4ed5ae8aee2b9770e8df7d9471722f8 MD5 · raw file

  1. // Copyright (c) 2010 Google Inc. All Rights Reserved.
  2. //
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are
  5. // met:
  6. //
  7. // * Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. // * Redistributions in binary form must reproduce the above
  10. // copyright notice, this list of conditions and the following disclaimer
  11. // in the documentation and/or other materials provided with the
  12. // distribution.
  13. // * Neither the name of Google Inc. nor the names of its
  14. // contributors may be used to endorse or promote products derived from
  15. // this software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. // This file contains the definitions for a DWARF2/3 information
  29. // collector that uses the DWARF2/3 reader interface to build a mapping
  30. // of addresses to files, lines, and functions.
  31. #ifndef COMMON_DWARF_FUNCTIONINFO_H__
  32. #define COMMON_DWARF_FUNCTIONINFO_H__
  33. #include <map>
  34. #include <string>
  35. #include <utility>
  36. #include <vector>
  37. #include "common/dwarf/dwarf2reader.h"
  38. namespace dwarf2reader {
  39. struct FunctionInfo {
  40. // Name of the function
  41. std::string name;
  42. // Mangled name of the function
  43. std::string mangled_name;
  44. // File containing this function
  45. std::string file;
  46. // Line number for start of function.
  47. uint32 line;
  48. // Beginning address for this function
  49. uint64 lowpc;
  50. // End address for this function.
  51. uint64 highpc;
  52. };
  53. struct SourceFileInfo {
  54. // Name of the source file name
  55. std::string name;
  56. // Low address of source file name
  57. uint64 lowpc;
  58. };
  59. typedef std::map<uint64, FunctionInfo*> FunctionMap;
  60. typedef std::map<uint64, std::pair<std::string, uint32> > LineMap;
  61. // This class is a basic line info handler that fills in the dirs,
  62. // file, and linemap passed into it with the data produced from the
  63. // LineInfoHandler.
  64. class CULineInfoHandler: public LineInfoHandler {
  65. public:
  66. //
  67. CULineInfoHandler(std::vector<SourceFileInfo>* files,
  68. std::vector<std::string>* dirs,
  69. LineMap* linemap);
  70. virtual ~CULineInfoHandler() { }
  71. // Called when we define a directory. We just place NAME into dirs_
  72. // at position DIR_NUM.
  73. virtual void DefineDir(const std::string& name, uint32 dir_num);
  74. // Called when we define a filename. We just place
  75. // concat(dirs_[DIR_NUM], NAME) into files_ at position FILE_NUM.
  76. virtual void DefineFile(const std::string& name, int32 file_num,
  77. uint32 dir_num, uint64 mod_time, uint64 length);
  78. // Called when the line info reader has a new line, address pair
  79. // ready for us. ADDRESS is the address of the code, LENGTH is the
  80. // length of its machine code in bytes, FILE_NUM is the file number
  81. // containing the code, LINE_NUM is the line number in that file for
  82. // the code, and COLUMN_NUM is the column number the code starts at,
  83. // if we know it (0 otherwise).
  84. virtual void AddLine(uint64 address, uint64 length,
  85. uint32 file_num, uint32 line_num, uint32 column_num);
  86. private:
  87. LineMap* linemap_;
  88. std::vector<SourceFileInfo>* files_;
  89. std::vector<std::string>* dirs_;
  90. };
  91. class CUFunctionInfoHandler: public Dwarf2Handler {
  92. public:
  93. CUFunctionInfoHandler(std::vector<SourceFileInfo>* files,
  94. std::vector<std::string>* dirs,
  95. LineMap* linemap,
  96. FunctionMap* offset_to_funcinfo,
  97. FunctionMap* address_to_funcinfo,
  98. CULineInfoHandler* linehandler,
  99. const SectionMap& sections,
  100. ByteReader* reader)
  101. : files_(files), dirs_(dirs), linemap_(linemap),
  102. offset_to_funcinfo_(offset_to_funcinfo),
  103. address_to_funcinfo_(address_to_funcinfo),
  104. linehandler_(linehandler), sections_(sections),
  105. reader_(reader), current_function_info_(NULL) { }
  106. virtual ~CUFunctionInfoHandler() { }
  107. // Start to process a compilation unit at OFFSET from the beginning of the
  108. // .debug_info section. We want to see all compilation units, so we
  109. // always return true.
  110. virtual bool StartCompilationUnit(uint64 offset, uint8 address_size,
  111. uint8 offset_size, uint64 cu_length,
  112. uint8 dwarf_version);
  113. // Start to process a DIE at OFFSET from the beginning of the
  114. // .debug_info section. We only care about function related DIE's.
  115. virtual bool StartDIE(uint64 offset, enum DwarfTag tag,
  116. const AttributeList& attrs);
  117. // Called when we have an attribute with unsigned data to give to
  118. // our handler. The attribute is for the DIE at OFFSET from the
  119. // beginning of the .debug_info section, has a name of ATTR, a form of
  120. // FORM, and the actual data of the attribute is in DATA.
  121. virtual void ProcessAttributeUnsigned(uint64 offset,
  122. enum DwarfAttribute attr,
  123. enum DwarfForm form,
  124. uint64 data);
  125. // Called when we have an attribute with a DIE reference to give to
  126. // our handler. The attribute is for the DIE at OFFSET from the
  127. // beginning of the .debug_info section, has a name of ATTR, a form of
  128. // FORM, and the offset of the referenced DIE from the start of the
  129. // .debug_info section is in DATA.
  130. virtual void ProcessAttributeReference(uint64 offset,
  131. enum DwarfAttribute attr,
  132. enum DwarfForm form,
  133. uint64 data);
  134. // Called when we have an attribute with string data to give to
  135. // our handler. The attribute is for the DIE at OFFSET from the
  136. // beginning of the .debug_info section, has a name of ATTR, a form of
  137. // FORM, and the actual data of the attribute is in DATA.
  138. virtual void ProcessAttributeString(uint64 offset,
  139. enum DwarfAttribute attr,
  140. enum DwarfForm form,
  141. const std::string& data);
  142. // Called when finished processing the DIE at OFFSET.
  143. // Because DWARF2/3 specifies a tree of DIEs, you may get starts
  144. // before ends of the previous DIE, as we process children before
  145. // ending the parent.
  146. virtual void EndDIE(uint64 offset);
  147. private:
  148. std::vector<SourceFileInfo>* files_;
  149. std::vector<std::string>* dirs_;
  150. LineMap* linemap_;
  151. FunctionMap* offset_to_funcinfo_;
  152. FunctionMap* address_to_funcinfo_;
  153. CULineInfoHandler* linehandler_;
  154. const SectionMap& sections_;
  155. ByteReader* reader_;
  156. FunctionInfo* current_function_info_;
  157. uint64 current_compilation_unit_offset_;
  158. };
  159. } // namespace dwarf2reader
  160. #endif // COMMON_DWARF_FUNCTIONINFO_H__