michael@0: // Copyright (c) 2010, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: // michael@0: // module_comparer.h: ModuleComparer reads a string format of symbol file, and michael@0: // loads the symbol into both BasicSourceLineResolver::Module and michael@0: // FastSourceLineResolve::Module. It then traverses both Modules and compare michael@0: // the content of data to verify the correctness of new fast module. michael@0: // ModuleCompare class is a tool to verify correctness of a loaded michael@0: // FastSourceLineResolver::Module instance, i.e., in-memory representation of michael@0: // parsed symbol. ModuleComparer class should be used for testing purpose only, michael@0: // e.g., in fast_source_line_resolver_unittest. michael@0: // michael@0: // Author: lambxsy@google.com (Siyang Xie) michael@0: michael@0: #ifndef PROCESSOR_MODULE_COMPARER_H__ michael@0: #define PROCESSOR_MODULE_COMPARER_H__ michael@0: michael@0: #include michael@0: michael@0: #include "processor/basic_source_line_resolver_types.h" michael@0: #include "processor/fast_source_line_resolver_types.h" michael@0: #include "processor/module_serializer.h" michael@0: #include "processor/windows_frame_info.h" michael@0: michael@0: namespace google_breakpad { michael@0: michael@0: class ModuleComparer { michael@0: public: michael@0: ModuleComparer(): fast_resolver_(new FastSourceLineResolver), michael@0: basic_resolver_(new BasicSourceLineResolver) { } michael@0: ~ModuleComparer() { michael@0: delete fast_resolver_; michael@0: delete basic_resolver_; michael@0: } michael@0: michael@0: // BasicSourceLineResolver loads its module using the symbol data, michael@0: // ModuleSerializer serialize the loaded module into a memory chunk, michael@0: // FastSourceLineResolver loads its module using the serialized memory chunk, michael@0: // Then, traverse both modules together and compare underlying data michael@0: // return true if both modules contain exactly same data. michael@0: bool Compare(const string &symbol_data); michael@0: michael@0: private: michael@0: typedef BasicSourceLineResolver::Module BasicModule; michael@0: typedef FastSourceLineResolver::Module FastModule; michael@0: typedef BasicSourceLineResolver::Function BasicFunc; michael@0: typedef FastSourceLineResolver::Function FastFunc; michael@0: typedef BasicSourceLineResolver::Line BasicLine; michael@0: typedef FastSourceLineResolver::Line FastLine; michael@0: typedef BasicSourceLineResolver::PublicSymbol BasicPubSymbol; michael@0: typedef FastSourceLineResolver::PublicSymbol FastPubSymbol; michael@0: typedef WindowsFrameInfo WFI; michael@0: michael@0: bool CompareModule(const BasicModule *oldmodule, michael@0: const FastModule *newmodule) const; michael@0: bool CompareFunction(const BasicFunc *oldfunc, const FastFunc *newfunc) const; michael@0: bool CompareLine(const BasicLine *oldline, const FastLine *newline) const; michael@0: bool ComparePubSymbol(const BasicPubSymbol*, const FastPubSymbol*) const; michael@0: bool CompareWFI(const WindowsFrameInfo&, const WindowsFrameInfo&) const; michael@0: michael@0: // Compare ContainedRangeMap michael@0: bool CompareCRM(const ContainedRangeMap >*, michael@0: const StaticContainedRangeMap*) const; michael@0: michael@0: FastSourceLineResolver *fast_resolver_; michael@0: BasicSourceLineResolver *basic_resolver_; michael@0: ModuleSerializer serializer_; michael@0: }; michael@0: michael@0: } // namespace google_breakpad michael@0: michael@0: #endif // PROCESSOR_MODULE_COMPARER_H__