1
// Copyright (c) 2006, Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
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
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.
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.
30
// PDBSourceLineWriter uses a pdb file produced by Visual C++ to output
31
// a line/address map for use with BasicSourceLineResolver.
33
#ifndef _PDB_SOURCE_LINE_WRITER_H__
34
#define _PDB_SOURCE_LINE_WRITER_H__
36
#include <atlcomcli.h>
40
struct IDiaEnumLineNumbers;
44
namespace google_breakpad {
48
// A structure that carries information that identifies a pdb file.
49
struct PDBModuleInfo {
51
// The basename of the pdb file from which information was loaded.
54
// The pdb's identifier. For recent pdb files, the identifier consists
55
// of the pdb's guid, in uppercase hexadecimal form without any dashes
56
// or separators, followed immediately by the pdb's age, also in
57
// uppercase hexadecimal form. For older pdb files which have no guid,
58
// the identifier is the pdb's 32-bit signature value, in zero-padded
59
// hexadecimal form, followed immediately by the pdb's age, in lowercase
61
wstring debug_identifier;
63
// A string identifying the cpu that the pdb is associated with.
64
// Currently, this may be "x86" or "unknown".
68
class PDBSourceLineWriter {
71
PDB_FILE, // a .pdb file containing debug symbols
72
EXE_FILE, // a .exe or .dll file
73
ANY_FILE // try PDB_FILE and then EXE_FILE
76
explicit PDBSourceLineWriter();
77
~PDBSourceLineWriter();
79
// Opens the given file. For executable files, the corresponding pdb
80
// file must be available; Open will be if it is not.
81
// If there is already a pdb file open, it is automatically closed.
82
// Returns true on success.
83
bool Open(const wstring &file, FileFormat format);
85
// Locates the pdb file for the given executable (exe or dll) file,
86
// and opens it. If there is already a pdb file open, it is automatically
87
// closed. Returns true on success.
88
bool OpenExecutable(const wstring &exe_file);
90
// Writes a map file from the current pdb file to the given file stream.
91
// Returns true on success.
92
bool WriteMap(FILE *map_file);
94
// Closes the current pdb file and its associated resources.
97
// Retrieves information about the module's debugging file. Returns
98
// true on success and false on failure.
99
bool GetModuleInfo(PDBModuleInfo *info);
101
// Sets uses_guid to true if the opened file uses a new-style CodeView
102
// record with a 128-bit GUID, or false if the opened file uses an old-style
103
// CodeView record. When no GUID is available, a 32-bit signature should be
104
// used to identify the module instead. If the information cannot be
105
// determined, this method returns false.
106
bool UsesGUID(bool *uses_guid);
109
// Outputs the line/address pairs for each line in the enumerator.
110
// Returns true on success.
111
bool PrintLines(IDiaEnumLineNumbers *lines);
113
// Outputs a function address and name, followed by its source line list.
114
// Returns true on success.
115
bool PrintFunction(IDiaSymbol *function);
117
// Outputs all functions as described above. Returns true on success.
118
bool PrintFunctions();
120
// Outputs all of the source files in the session's pdb file.
121
// Returns true on success.
122
bool PrintSourceFiles();
124
// Outputs all of the frame information necessary to construct stack
125
// backtraces in the absence of frame pointers. Returns true on success.
126
bool PrintFrameData();
128
// Outputs a single public symbol address and name, if the symbol corresponds
129
// to a code address. Returns true on success. If symbol is does not
130
// correspond to code, returns true without outputting anything.
131
bool PrintCodePublicSymbol(IDiaSymbol *symbol);
133
// Outputs a line identifying the PDB file that is being dumped, along with
137
// Returns the function name for a symbol. If possible, the name is
138
// undecorated. If the symbol's decorated form indicates the size of
139
// parameters on the stack, this information is returned in stack_param_size.
140
// Returns true on success. If the symbol doesn't encode parameter size
141
// information, stack_param_size is set to -1.
142
static bool GetSymbolFunctionName(IDiaSymbol *function, BSTR *name,
143
int *stack_param_size);
145
// Returns the number of bytes of stack space used for a function's
146
// parameters. function must have the tag SymTagFunction. In the event of
147
// a failure, returns 0, which is also a valid number of bytes.
148
static int GetFunctionStackParamSize(IDiaSymbol *function);
150
// The session for the currently-open pdb file.
151
CComPtr<IDiaSession> session_;
153
// The current output file for this WriteMap invocation.
156
// Disallow copy ctor and operator=
157
PDBSourceLineWriter(const PDBSourceLineWriter&);
158
void operator=(const PDBSourceLineWriter&);
161
} // namespace google_breakpad
163
#endif // _PDB_SOURCE_LINE_WRITER_H__