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