• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006, 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 // on_demand_symbol_supplier.h: Provides a Symbol Supplier that will create
31 // a breakpad symbol file on demand.
32 
33 #ifndef TOOLS_MAC_CRASH_REPORT_ON_DEMAND_SYMBOL_SUPPLIER_H__
34 #define TOOLS_MAC_CRASH_REPORT_ON_DEMAND_SYMBOL_SUPPLIER_H__
35 
36 #include <map>
37 #include <string>
38 #include "google_breakpad/processor/symbol_supplier.h"
39 
40 namespace google_breakpad {
41 
42 using std::map;
43 using std::string;
44 class MinidumpModule;
45 
46 class OnDemandSymbolSupplier : public SymbolSupplier {
47  public:
48   // |search_dir| is the directory to search for alternative symbols with
49   // the same name as the module in the minidump
50   OnDemandSymbolSupplier(const string &search_dir,
51                          const string &symbol_search_dir);
~OnDemandSymbolSupplier()52   virtual ~OnDemandSymbolSupplier() {}
53 
54   // Returns the path to the symbol file for the given module.
55   virtual SymbolResult GetSymbolFile(const CodeModule *module,
56                                      const SystemInfo *system_info,
57                                      string *symbol_file);
58 
59   // Returns the path to the symbol file for the given module.
60   virtual SymbolResult GetSymbolFile(const CodeModule *module,
61                                      const SystemInfo *system_info,
62                                      string *symbol_file,
63                                      string *symbol_data);
64   // Allocates data buffer on heap, and takes the ownership of
65   // the data buffer.
66   virtual SymbolResult GetCStringSymbolData(const CodeModule *module,
67                                             const SystemInfo *system_info,
68                                             string *symbol_file,
69                                             char **symbol_data,
70                                             size_t *symbol_data_size);
71 
72   // Delete the data buffer allocated for module in GetCStringSymbolData().
73   virtual void FreeSymbolData(const CodeModule *module);
74 
75  protected:
76   // Search directory
77   string search_dir_;
78   string symbol_search_dir_;
79 
80   // When we create a symbol file for a module, save the name of the module
81   // and the path to that module's symbol file.
82   map<string, string> module_file_map_;
83 
84   // Map of allocated data buffers, keyed by module->code_file().
85   map<string, char *> memory_buffers_;
86 
87   // Return the name for |module|  This will be the value used as the key
88   // to the |module_file_map_|.
89   string GetNameForModule(const CodeModule *module);
90 
91   // Find the module on local system.  If the module resides in a different
92   // location than the full path in the minidump, this will be the location
93   // used.
94   string GetLocalModulePath(const CodeModule *module);
95 
96   // Return the full path for |module|.
97   string GetModulePath(const CodeModule *module);
98 
99   // Return the path to the symbol file for |module|.  If an empty string is
100   // returned, then |module| doesn't have a symbol file.
101   string GetModuleSymbolFile(const CodeModule *module);
102 
103   // Generate the breakpad symbol file for |module|.  Return true if successful.
104   // File is generated in /tmp.
105   bool GenerateSymbolFile(const CodeModule *module,
106                           const SystemInfo *system_info);
107 };
108 
109 }  // namespace google_breakpad
110 
111 #endif  // TOOLS_MAC_CRASH_REPORT_ON_DEMAND_SYMBOL_SUPPLIER_H__
112