/thirdparty/breakpad/processor/module_comparer.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 98 lines · 41 code · 12 blank · 45 comment · 0 complexity · e2c972bc419baa39f7e9318c185d1f03 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. //
  30. // module_comparer.h: ModuleComparer reads a string format of symbol file, and
  31. // loads the symbol into both BasicSourceLineResolver::Module and
  32. // FastSourceLineResolve::Module. It then traverses both Modules and compare
  33. // the content of data to verify the correctness of new fast module.
  34. // ModuleCompare class is a tool to verify correctness of a loaded
  35. // FastSourceLineResolver::Module instance, i.e., in-memory representation of
  36. // parsed symbol. ModuleComparer class should be used for testing purpose only,
  37. // e.g., in fast_source_line_resolver_unittest.
  38. //
  39. // Author: lambxsy@google.com (Siyang Xie)
  40. #ifndef PROCESSOR_MODULE_COMPARER_H__
  41. #define PROCESSOR_MODULE_COMPARER_H__
  42. #include <string>
  43. #include "processor/basic_source_line_resolver_types.h"
  44. #include "processor/fast_source_line_resolver_types.h"
  45. #include "processor/module_serializer.h"
  46. #include "processor/windows_frame_info.h"
  47. namespace google_breakpad {
  48. class ModuleComparer {
  49. public:
  50. ModuleComparer(): fast_resolver_(new FastSourceLineResolver),
  51. basic_resolver_(new BasicSourceLineResolver) { }
  52. ~ModuleComparer() {
  53. delete fast_resolver_;
  54. delete basic_resolver_;
  55. }
  56. // BasicSourceLineResolver loads its module using the symbol data,
  57. // ModuleSerializer serialize the loaded module into a memory chunk,
  58. // FastSourceLineResolver loads its module using the serialized memory chunk,
  59. // Then, traverse both modules together and compare underlying data
  60. // return true if both modules contain exactly same data.
  61. bool Compare(const string &symbol_data);
  62. private:
  63. typedef BasicSourceLineResolver::Module BasicModule;
  64. typedef FastSourceLineResolver::Module FastModule;
  65. typedef BasicSourceLineResolver::Function BasicFunc;
  66. typedef FastSourceLineResolver::Function FastFunc;
  67. typedef BasicSourceLineResolver::Line BasicLine;
  68. typedef FastSourceLineResolver::Line FastLine;
  69. typedef BasicSourceLineResolver::PublicSymbol BasicPubSymbol;
  70. typedef FastSourceLineResolver::PublicSymbol FastPubSymbol;
  71. typedef WindowsFrameInfo WFI;
  72. bool CompareModule(const BasicModule *oldmodule,
  73. const FastModule *newmodule) const;
  74. bool CompareFunction(const BasicFunc *oldfunc, const FastFunc *newfunc) const;
  75. bool CompareLine(const BasicLine *oldline, const FastLine *newline) const;
  76. bool ComparePubSymbol(const BasicPubSymbol*, const FastPubSymbol*) const;
  77. bool CompareWFI(const WindowsFrameInfo&, const WindowsFrameInfo&) const;
  78. // Compare ContainedRangeMap
  79. bool CompareCRM(const ContainedRangeMap<MemAddr, linked_ptr<WFI> >*,
  80. const StaticContainedRangeMap<MemAddr, char>*) const;
  81. FastSourceLineResolver *fast_resolver_;
  82. BasicSourceLineResolver *basic_resolver_;
  83. ModuleSerializer serializer_;
  84. };
  85. } // namespace google_breakpad
  86. #endif // PROCESSOR_MODULE_COMPARER_H__