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 
41 #ifndef PROCESSOR_MODULE_COMPARER_H__
42 #define PROCESSOR_MODULE_COMPARER_H__
43 
44 #include <string>
45 
46 #include "processor/basic_source_line_resolver_types.h"
47 #include "processor/fast_source_line_resolver_types.h"
48 #include "processor/module_serializer.h"
49 #include "processor/windows_frame_info.h"
50 
51 namespace google_breakpad {
52 
53 class ModuleComparer {
54  public:
ModuleComparer()55   ModuleComparer(): fast_resolver_(new FastSourceLineResolver),
56                    basic_resolver_(new BasicSourceLineResolver) { }
~ModuleComparer()57   ~ModuleComparer() {
58     delete fast_resolver_;
59     delete basic_resolver_;
60   }
61 
62   // BasicSourceLineResolver loads its module using the symbol data,
63   // ModuleSerializer serialize the loaded module into a memory chunk,
64   // FastSourceLineResolver loads its module using the serialized memory chunk,
65   // Then, traverse both modules together and compare underlying data
66   // return true if both modules contain exactly same data.
67   bool Compare(const string &symbol_data);
68 
69  private:
70   typedef BasicSourceLineResolver::Module BasicModule;
71   typedef FastSourceLineResolver::Module FastModule;
72   typedef BasicSourceLineResolver::Function BasicFunc;
73   typedef FastSourceLineResolver::Function FastFunc;
74   typedef BasicSourceLineResolver::Line BasicLine;
75   typedef FastSourceLineResolver::Line FastLine;
76   typedef BasicSourceLineResolver::PublicSymbol BasicPubSymbol;
77   typedef FastSourceLineResolver::PublicSymbol FastPubSymbol;
78   typedef WindowsFrameInfo WFI;
79 
80   bool CompareModule(const BasicModule *oldmodule,
81                      const FastModule *newmodule) const;
82   bool CompareFunction(const BasicFunc *oldfunc, const FastFunc *newfunc) const;
83   bool CompareLine(const BasicLine *oldline, const FastLine *newline) const;
84   bool ComparePubSymbol(const BasicPubSymbol*, const FastPubSymbol*) const;
85   bool CompareWFI(const WindowsFrameInfo&, const WindowsFrameInfo&) const;
86 
87   // Compare ContainedRangeMap
88   bool CompareCRM(const ContainedRangeMap<MemAddr, linked_ptr<WFI> >*,
89                   const StaticContainedRangeMap<MemAddr, char>*) const;
90 
91   FastSourceLineResolver *fast_resolver_;
92   BasicSourceLineResolver *basic_resolver_;
93   ModuleSerializer serializer_;
94 };
95 
96 }  // namespace google_breakpad
97 
98 #endif  // PROCESSOR_MODULE_COMPARER_H__
99