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// The caller may implement the SymbolSupplier abstract base class
31// to provide symbols for a given module.
32
33#ifndef GOOGLE_BREAKPAD_PROCESSOR_SYMBOL_SUPPLIER_H__
34#define GOOGLE_BREAKPAD_PROCESSOR_SYMBOL_SUPPLIER_H__
35
36#include <string>
37#include "common/using_std_string.h"
38
39namespace google_breakpad {
40
41class CodeModule;
42struct SystemInfo;
43
44class SymbolSupplier {
45 public:
46  // Result type for GetSymbolFile
47  enum SymbolResult {
48    // no symbols were found, but continue processing
49    NOT_FOUND,
50
51    // symbols were found, and the path has been placed in symbol_file
52    FOUND,
53
54    // stops processing the minidump immediately
55    INTERRUPT
56  };
57
58  virtual ~SymbolSupplier() {}
59
60  // Retrieves the symbol file for the given CodeModule, placing the
61  // path in symbol_file if successful.  system_info contains strings
62  // identifying the operating system and CPU; SymbolSupplier may use
63  // to help locate the symbol file.  system_info may be NULL or its
64  // fields may be empty if these values are unknown.  symbol_file
65  // must be a pointer to a valid string
66  virtual SymbolResult GetSymbolFile(const CodeModule *module,
67                                     const SystemInfo *system_info,
68                                     string *symbol_file) = 0;
69  // Same as above, except also places symbol data into symbol_data.
70  // If symbol_data is NULL, the data is not returned.
71  // TODO(nealsid) Once we have symbol data caching behavior implemented
72  // investigate making all symbol suppliers implement all methods,
73  // and make this pure virtual
74  virtual SymbolResult GetSymbolFile(const CodeModule *module,
75                                     const SystemInfo *system_info,
76                                     string *symbol_file,
77                                     string *symbol_data) = 0;
78
79  // Same as above, except allocates data buffer on heap and then places the
80  // symbol data into the buffer as C-string.
81  // SymbolSupplier is responsible for deleting the data buffer. After the call
82  // to GetCStringSymbolData(), the caller should call FreeSymbolData(const
83  // Module *module) once the data buffer is no longer needed.
84  // If symbol_data is not NULL, symbol supplier won't return FOUND unless it
85  // returns a valid buffer in symbol_data, e.g., returns INTERRUPT on memory
86  // allocation failure.
87  virtual SymbolResult GetCStringSymbolData(const CodeModule *module,
88                                            const SystemInfo *system_info,
89                                            string *symbol_file,
90                                            char **symbol_data,
91                                            size_t *symbol_data_size) = 0;
92
93  // Frees the data buffer allocated for the module in GetCStringSymbolData.
94  virtual void FreeSymbolData(const CodeModule *module) = 0;
95};
96
97}  // namespace google_breakpad
98
99#endif  // GOOGLE_BREAKPAD_PROCESSOR_SYMBOL_SUPPLIER_H__
100