/thirdparty/breakpad/processor/source_line_resolver_base_types.h

http://github.com/tomahawk-player/tomahawk · C Header · 149 lines · 71 code · 22 blank · 56 comment · 1 complexity · bd1c1368a565c829c23c8121f53e46e9 MD5 · raw file

  1. // Copyright (c) 2010 Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // source_line_resolver_base_types.h: definition of nested classes/structs in
  30. // SourceLineResolverBase. It moves the definitions out of
  31. // source_line_resolver_base.cc, so that other classes may have access
  32. // to these private nested types without including source_line_resolver_base.cc
  33. // In addition, Module is defined as a pure abstract class to be implemented by
  34. // each concrete source line resolver class.
  35. //
  36. // See source_line_resolver_base.h for more documentation.
  37. //
  38. // Author: Siyang Xie (lambxsy@google.com)
  39. #include <stdio.h>
  40. #include <map>
  41. #include <string>
  42. #include "google_breakpad/processor/source_line_resolver_base.h"
  43. #include "google_breakpad/processor/stack_frame.h"
  44. #include "processor/cfi_frame_info.h"
  45. #include "processor/windows_frame_info.h"
  46. #ifndef PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
  47. #define PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
  48. namespace google_breakpad {
  49. class SourceLineResolverBase::AutoFileCloser {
  50. public:
  51. explicit AutoFileCloser(FILE *file) : file_(file) {}
  52. ~AutoFileCloser() {
  53. if (file_)
  54. fclose(file_);
  55. }
  56. private:
  57. FILE *file_;
  58. };
  59. struct SourceLineResolverBase::Line {
  60. Line() { }
  61. Line(MemAddr addr, MemAddr code_size, int file_id, int source_line)
  62. : address(addr)
  63. , size(code_size)
  64. , source_file_id(file_id)
  65. , line(source_line) { }
  66. MemAddr address;
  67. MemAddr size;
  68. int32_t source_file_id;
  69. int32_t line;
  70. };
  71. struct SourceLineResolverBase::Function {
  72. Function() { }
  73. Function(const string &function_name,
  74. MemAddr function_address,
  75. MemAddr code_size,
  76. int set_parameter_size)
  77. : name(function_name), address(function_address), size(code_size),
  78. parameter_size(set_parameter_size) { }
  79. string name;
  80. MemAddr address;
  81. MemAddr size;
  82. // The size of parameters passed to this function on the stack.
  83. int32_t parameter_size;
  84. };
  85. struct SourceLineResolverBase::PublicSymbol {
  86. PublicSymbol() { }
  87. PublicSymbol(const string& set_name,
  88. MemAddr set_address,
  89. int set_parameter_size)
  90. : name(set_name),
  91. address(set_address),
  92. parameter_size(set_parameter_size) {}
  93. string name;
  94. MemAddr address;
  95. // If the public symbol is used as a function entry point, parameter_size
  96. // is set to the size of the parameters passed to the funciton on the
  97. // stack, if known.
  98. int32_t parameter_size;
  99. };
  100. class SourceLineResolverBase::Module {
  101. public:
  102. virtual ~Module() { };
  103. // Loads a map from the given buffer in char* type.
  104. // Does NOT take ownership of memory_buffer (the caller, source line resolver,
  105. // is the owner of memory_buffer).
  106. virtual bool LoadMapFromMemory(char *memory_buffer) = 0;
  107. // Looks up the given relative address, and fills the StackFrame struct
  108. // with the result.
  109. virtual void LookupAddress(StackFrame *frame) const = 0;
  110. // If Windows stack walking information is available covering ADDRESS,
  111. // return a WindowsFrameInfo structure describing it. If the information
  112. // is not available, returns NULL. A NULL return value does not indicate
  113. // an error. The caller takes ownership of any returned WindowsFrameInfo
  114. // object.
  115. virtual WindowsFrameInfo *
  116. FindWindowsFrameInfo(const StackFrame *frame) const = 0;
  117. // If CFI stack walking information is available covering ADDRESS,
  118. // return a CFIFrameInfo structure describing it. If the information
  119. // is not available, return NULL. The caller takes ownership of any
  120. // returned CFIFrameInfo object.
  121. virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame) const = 0;
  122. protected:
  123. virtual bool ParseCFIRuleSet(const string &rule_set,
  124. CFIFrameInfo *frame_info) const;
  125. };
  126. } // namespace google_breakpad
  127. #endif // PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__