Initial import, which includes the Windows client-side dump_syms tool, and

part of the server-side dump processor.



git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@4 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
bryner
2006-08-25 21:14:45 +00:00
parent 684d6764fe
commit cb91a2f879
35 changed files with 42327 additions and 17 deletions

70
src/config.h.in Normal file
View File

@@ -0,0 +1,70 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
/* Namespace for Google classes */
#undef GOOGLE_NAMESPACE
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* define if the compiler implements namespaces */
#undef HAVE_NAMESPACES
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* the namespace where STL code like vector<> is defined */
#undef STL_NAMESPACE
/* Version number of package */
#undef VERSION
/* Stops putting the code inside the Google namespace */
#undef _END_GOOGLE_NAMESPACE_
/* Puts following code inside the Google namespace */
#undef _START_GOOGLE_NAMESPACE_

View File

@@ -0,0 +1,275 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <map>
#include <string.h>
#include <vector>
#include <utility>
#include "source_line_resolver.h"
using STL_NAMESPACE::map;
using STL_NAMESPACE::vector;
using STL_NAMESPACE::make_pair;
using __gnu_cxx::hash;
_START_GOOGLE_NAMESPACE_
void SourceLineResolver::SourceLineInfo::Reset() {
function_name.clear();
source_file.clear();
source_line = 0;
}
// MemAddrMap is a map subclass which has the following properties:
// - stores pointers to an "entry" type, which are deleted on destruction
// - suitable for address lookup via FindContainingEntry
template<class T>
class SourceLineResolver::MemAddrMap : public map<MemAddr, T*> {
public:
~MemAddrMap();
// Find the entry which "contains" a given relative address, that is,
// the entry with the highest address not greater than the given address.
// Returns NULL if there is no such entry.
T* FindContainingEntry(MemAddr address) const;
private:
typedef map<MemAddr, T*> MapType;
};
template<class T>
SourceLineResolver::MemAddrMap<T>::~MemAddrMap() {
typename MapType::iterator it;
for (it = MapType::begin(); it != MapType::end(); ++it) {
delete it->second;
}
}
template<class T>
T* SourceLineResolver::MemAddrMap<T>::FindContainingEntry(
MemAddr address) const {
typename MapType::const_iterator it = MapType::lower_bound(address);
if (it->first != address) {
if (it == MapType::begin()) {
// Nowhere to go, so no entry contains the address
return NULL;
}
--it; // back up to the entry before address
}
return it->second;
}
struct SourceLineResolver::Line {
Line(MemAddr addr, int file_id, int source_line)
: address(addr), source_file_id(file_id), line(source_line) { }
MemAddr address;
int source_file_id;
int line;
};
struct SourceLineResolver::Function {
Function(const string &function_name, MemAddr function_address)
: name(function_name), address(function_address) { }
string name;
MemAddr address;
MemAddrMap<Line> lines;
};
class SourceLineResolver::Module {
public:
Module(const string &name) : name_(name) { }
// Loads the given map file, returning true on success.
bool LoadMap(const string &map_file);
// Looks up the given relative address, and fills the SourceLineInfo struct
// with the result.
void LookupAddress(MemAddr address, SourceLineInfo *info) const;
private:
friend class SourceLineResolver;
typedef hash_map<int, string> FileMap;
// Parses a file declaration
void ParseFile(char *file_line);
// Parses a function declaration, returning a new Function object.
Function* ParseFunction(char *function_line);
// Parses a line declaration, returning a new Line object.
Line* ParseLine(char *line_line);
string name_;
FileMap files_;
MemAddrMap<Function> functions_;
};
SourceLineResolver::SourceLineResolver() : modules_(new ModuleMap) {
}
SourceLineResolver::~SourceLineResolver() {
ModuleMap::iterator it;
for (it = modules_->begin(); it != modules_->end(); ++it) {
delete it->second;
}
delete modules_;
}
bool SourceLineResolver::LoadModule(const string &module_name,
const string &map_file) {
// Make sure we don't already have a module with the given name.
if (modules_->find(module_name) != modules_->end()) {
return false;
}
Module *module = new Module(module_name);
if (!module->LoadMap(map_file)) {
delete module;
return false;
}
modules_->insert(make_pair(module_name, module));
return true;
}
void SourceLineResolver::LookupAddress(MemAddr address,
const string &module_name,
SourceLineInfo *info) const {
info->Reset();
ModuleMap::const_iterator it = modules_->find(module_name);
if (it != modules_->end()) {
it->second->LookupAddress(address, info);
}
}
bool SourceLineResolver::Module::LoadMap(const string &map_file) {
FILE *f = fopen(map_file.c_str(), "r");
if (!f) {
return false;
}
char buffer[1024];
Function *cur_func = NULL;
while (fgets(buffer, sizeof(buffer), f)) {
if (strncmp(buffer, "FILE ", 5) == 0) {
ParseFile(buffer);
} else if (strncmp(buffer, "FUNC ", 5) == 0) {
cur_func = ParseFunction(buffer);
if (!cur_func) {
return false;
}
functions_.insert(make_pair(cur_func->address, cur_func));
} else {
if (!cur_func) {
return false;
}
Line *line = ParseLine(buffer);
if (!line) {
return false;
}
cur_func->lines.insert(make_pair(line->address, line));
}
}
fclose(f);
return true;
}
void SourceLineResolver::Module::LookupAddress(MemAddr address,
SourceLineInfo *info) const {
Function *func = functions_.FindContainingEntry(address);
if (!func) {
return;
}
info->function_name = func->name;
Line *line = func->lines.FindContainingEntry(address);
if (!line) {
return;
}
FileMap::const_iterator it = files_.find(line->source_file_id);
if (it != files_.end()) {
info->source_file = files_.find(line->source_file_id)->second;
}
info->source_line = line->line;
}
void SourceLineResolver::Module::ParseFile(char *file_line) {
// FILE <id> <filename>
file_line += 5; // skip prefix
char *id = strtok(file_line, " ");
if (!id) {
return;
}
int index = atoi(id);
if (index < 0) {
return;
}
char *filename = strtok(NULL, "\r\n");
if (filename) {
files_.insert(make_pair(index, string(filename)));
}
}
SourceLineResolver::Function* SourceLineResolver::Module::ParseFunction(
char *function_line) {
// FUNC <address> <name>
function_line += 5; // skip prefix
char *addr = strtok(function_line, " ");
if (!addr) {
return NULL;
}
char *name = strtok(NULL, "\r\n");
if (!name) {
return NULL;
}
return new Function(name, strtoull(addr, NULL, 16));
}
SourceLineResolver::Line* SourceLineResolver::Module::ParseLine(
char *line_line) {
// <address> <line number> <source file id>
char *addr = strtok(line_line, " ");
if (!addr) {
return NULL;
}
char *line_num_str = strtok(NULL, "\r\n");
if (!line_num_str) {
return NULL;
}
int line_number, source_file;
if (sscanf(line_num_str, "%d %d", &line_number, &source_file) != 2) {
return NULL;
}
return new Line(strtoull(addr, NULL, 16), source_file, line_number);
}
size_t SourceLineResolver::HashString::operator()(const string &s) const {
return hash<const char*>()(s.c_str());
}
_END_GOOGLE_NAMESPACE_

View File

@@ -0,0 +1,88 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SourceLineResolver returns function/file/line info for a memory address.
// It uses address map files produced by a compatible writer, e.g.
// PDBSourceLineWriter.
#ifndef _SOURCE_LINE_RESOLVER_H__
#define _SOURCE_LINE_RESOLVER_H__
#include "config.h"
#include <string>
#include <ext/hash_map>
_START_GOOGLE_NAMESPACE_
using STL_NAMESPACE::string;
using __gnu_cxx::hash_map;
class SourceLineResolver {
public:
typedef unsigned long long MemAddr;
// A struct that gives source file information for a memory address.
struct SourceLineInfo {
// Resets all fields to their default empty values
void Reset();
// The function name, for example Foo::Foo()
string function_name;
// The source file, for example C:\foo\bar.cc
string source_file;
// The line number within the source file (1-based)
int source_line;
};
SourceLineResolver();
~SourceLineResolver();
// Adds a module to this resolver, returning true on success.
//
// module_name may be an arbitrary string. Typically, it will be the
// filename of the module, optionally with version identifiers.
//
// map_file should contain line/address mappings for this module.
bool LoadModule(const string &module_name, const string &map_file);
// Determines the source line for the given address, and fills info
// with the result. module_name must match a module name that was
// passed to LoadModule(). The address should be module-relative.
void LookupAddress(MemAddr address, const string &module_name,
SourceLineInfo *info) const;
private:
template<class T> class MemAddrMap;
struct Line;
struct Function;
struct File;
struct HashString {
size_t operator()(const string &s) const;
};
class Module;
// All of the modules we've loaded
typedef hash_map<string, Module*, HashString> ModuleMap;
ModuleMap *modules_;
// Disallow unwanted copy ctor and assignment operator
SourceLineResolver(const SourceLineResolver&);
void operator=(const SourceLineResolver&);
};
_END_GOOGLE_NAMESPACE_
#endif // _SOLURCE_LINE_RESOLVER_H__

View File

@@ -0,0 +1,86 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <string>
#include "source_line_resolver.h"
using STL_NAMESPACE::string;
using GOOGLE_NAMESPACE::SourceLineResolver;
#define ASSERT_TRUE(cond) \
if (!(cond)) { \
fprintf(stderr, "FAILED: %s at %s:%d\n", #cond, __FILE__, __LINE__); \
return false; \
}
#define ASSERT_FALSE(cond) ASSERT_TRUE(!(cond))
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
static bool VerifyEmpty(const SourceLineResolver::SourceLineInfo &info) {
ASSERT_TRUE(info.function_name.empty());
ASSERT_TRUE(info.source_file.empty());
ASSERT_EQ(info.source_line, 0);
return true;
}
static bool RunTests() {
string testdata_dir = string(getenv("srcdir") ? getenv("srcdir") : ".") +
"/src/processor/testdata";
SourceLineResolver resolver;
ASSERT_TRUE(resolver.LoadModule("module1", testdata_dir + "/module1.out"));
ASSERT_TRUE(resolver.LoadModule("module2", testdata_dir + "/module2.out"));
SourceLineResolver::SourceLineInfo info;
resolver.LookupAddress(0x1000, "module1", &info);
ASSERT_EQ(info.function_name, "Function1_1");
ASSERT_EQ(info.source_file, "file1_1.cc");
ASSERT_EQ(info.source_line, 44);
info.Reset();
ASSERT_TRUE(VerifyEmpty(info));
resolver.LookupAddress(0x800, "module1", &info);
ASSERT_TRUE(VerifyEmpty(info));
resolver.LookupAddress(0x1280, "module1", &info);
ASSERT_EQ(info.function_name, "Function1_3");
ASSERT_TRUE(info.source_file.empty());
ASSERT_EQ(info.source_line, 0);
resolver.LookupAddress(0x1380, "module1", &info);
ASSERT_EQ(info.function_name, "Function1_4");
ASSERT_TRUE(info.source_file.empty());
ASSERT_EQ(info.source_line, 0);
resolver.LookupAddress(0x2180, "module2", &info);
ASSERT_EQ(info.function_name, "Function2_2");
ASSERT_EQ(info.source_file, "file2_2.cc");
ASSERT_EQ(info.source_line, 21);
ASSERT_FALSE(resolver.LoadModule("module3",
testdata_dir + "/module3_bad.out"));
ASSERT_FALSE(resolver.LoadModule("module4",
testdata_dir + "/invalid-filename"));
return true;
}
int main(int argc, char **argv) {
if (!RunTests()) {
return 1;
}
return 0;
}

12
src/processor/testdata/module1.out vendored Normal file
View File

@@ -0,0 +1,12 @@
FILE 1 file1_1.cc
FILE 2 file1_2.cc
FILE 3 file1_3.cc
FUNC 1000 Function1_1
1000 44 1
1004 45 1
1008 46 1
FUNC 1100 Function1_2
1100 65 2
1104 66 2
FUNC 1200 Function1_3
FUNC 1300 Function1_4

12
src/processor/testdata/module2.out vendored Normal file
View File

@@ -0,0 +1,12 @@
FILE 1 file2_1.cc
FILE 2 file2_2.cc
FILE 3 file2_3.cc
FUNC 2000 Function2_1
1000 54 1
1004 55 1
1008 56 1
FUNC 2170 Function2_2
2170 10 2
2176 12 2
217a 13 2
2180 21 2

View File

@@ -0,0 +1,2 @@
FILE 1 file1.cc
FUNC 1000

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Windows utility to dump the line number data from a pdb file to
// a text-based format that we can use from the minidump processor.
#include <stdio.h>
#include <string>
#include "pdb_source_line_writer.h"
using std::wstring;
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <pdb file>", argv[0]);
return 1;
}
wchar_t filename[_MAX_PATH];
if (mbstowcs_s(NULL, filename, argv[1], _MAX_PATH) == -1) {
fprintf(stderr, "invalid multibyte character in %s\n", argv[1]);
return 1;
}
google_airbag::PDBSourceLineWriter writer;
if (!writer.Open(wstring(filename))) {
fprintf(stderr, "Open failed\n");
return 1;
}
if (!writer.WriteMap(stdout)) {
fprintf(stderr, "WriteMap failed\n");
return 1;
}
writer.Close();
return 0;
}

View File

@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="dump_syms"
ProjectGUID="{792E1530-E2C5-4289-992E-317BA30E9D9F}"
RootNamespace="dumpsyms"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(VSInstallDir)\DIA SDK\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(VSInstallDir)\DIA SDK\lib\diaguids.lib&quot;"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(VSInstallDir)\DIA SDK\include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="&quot;$(VSInstallDir)\DIA SDK\lib\diaguids.lib&quot;"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\pdb_source_line_writer.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\dump_syms.cc"
>
</File>
<File
RelativePath=".\pdb_source_line_writer.cc"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,216 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <atlbase.h>
#include <dia2.h>
#include "pdb_source_line_writer.h"
namespace google_airbag {
PDBSourceLineWriter::PDBSourceLineWriter() : output_(NULL) {
}
PDBSourceLineWriter::~PDBSourceLineWriter() {
}
bool PDBSourceLineWriter::Open(const wstring &pdb_file) {
Close();
if (FAILED(CoInitialize(NULL))) {
fprintf(stderr, "CoInitialize failed\n");
return false;
}
CComPtr<IDiaDataSource> data_source;
if (FAILED(data_source.CoCreateInstance(CLSID_DiaSource))) {
fprintf(stderr, "CoCreateInstance CLSID_DiaSource failed "
"(msdia80.dll unregistered?)\n");
return false;
}
if (FAILED(data_source->loadDataFromPdb(pdb_file.c_str()))) {
fprintf(stderr, "loadDataFromPdb failed\n");
return false;
}
if (FAILED(data_source->openSession(&session_))) {
fprintf(stderr, "openSession failed\n");
}
return true;
}
bool PDBSourceLineWriter::PrintLines(IDiaEnumLineNumbers *lines) {
// The line number format is:
// <rva> <line number> <source file id>
CComPtr<IDiaLineNumber> line;
ULONG count;
while (SUCCEEDED(lines->Next(1, &line, &count)) && count == 1) {
DWORD rva;
if (FAILED(line->get_relativeVirtualAddress(&rva))) {
fprintf(stderr, "failed to get line rva\n");
return false;
}
DWORD source_id;
if (FAILED(line->get_sourceFileId(&source_id))) {
fprintf(stderr, "failed to get line source file id\n");
return false;
}
DWORD line_num;
if (FAILED(line->get_lineNumber(&line_num))) {
fprintf(stderr, "failed to get line number\n");
return false;
}
fprintf(output_, "%x %d %d\n", rva, line_num, source_id);
line.Release();
}
return true;
}
bool PDBSourceLineWriter::PrintFunction(IDiaSymbol *function) {
// The function format is:
// FUNC <address> <function>
CComBSTR name;
if (FAILED(function->get_name(&name))) {
fprintf(stderr, "failed to get function name\n");
return false;
}
if (name.Length() == 0) {
fprintf(stderr, "empty function name\n");
return false;
}
ULONGLONG length;
if (FAILED(function->get_length(&length))) {
fprintf(stderr, "failed to get function length\n");
return false;
}
DWORD rva;
if (FAILED(function->get_relativeVirtualAddress(&rva))) {
fprintf(stderr, "couldn't get rva\n");
return false;
}
CComPtr<IDiaEnumLineNumbers> lines;
if (FAILED(session_->findLinesByRVA(rva, DWORD(length), &lines))) {
return false;
}
fwprintf(output_, L"FUNC %x %s\n", rva, name);
if (!PrintLines(lines)) {
return false;
}
return true;
}
bool PDBSourceLineWriter::PrintSourceFiles() {
CComPtr<IDiaSymbol> global;
if (FAILED(session_->get_globalScope(&global))) {
fprintf(stderr, "get_globalScope failed\n");
return false;
}
CComPtr<IDiaEnumSymbols> compilands;
if (FAILED(global->findChildren(SymTagCompiland, NULL,
nsNone, &compilands))) {
fprintf(stderr, "findChildren failed\n");
return false;
}
CComPtr<IDiaSymbol> compiland;
ULONG count;
while (SUCCEEDED(compilands->Next(1, &compiland, &count)) && count == 1) {
CComPtr<IDiaEnumSourceFiles> source_files;
if (FAILED(session_->findFile(compiland, NULL, nsNone, &source_files))) {
return false;
}
CComPtr<IDiaSourceFile> file;
while (SUCCEEDED(source_files->Next(1, &file, &count)) && count == 1) {
DWORD file_id;
if (FAILED(file->get_uniqueId(&file_id))) {
return false;
}
CComBSTR file_name;
if (FAILED(file->get_fileName(&file_name))) {
return false;
}
fwprintf(output_, L"FILE %d %s\n", file_id, file_name);
file.Release();
}
compiland.Release();
}
return true;
}
bool PDBSourceLineWriter::PrintFunctions() {
CComPtr<IDiaEnumSymbolsByAddr> symbols;
if (FAILED(session_->getSymbolsByAddr(&symbols))) {
fprintf(stderr, "failed to get symbol enumerator\n");
return false;
}
CComPtr<IDiaSymbol> symbol;
if (FAILED(symbols->symbolByAddr(1, 0, &symbol))) {
fprintf(stderr, "failed to enumerate symbols\n");
return false;
}
DWORD rva_last = 0;
if (FAILED(symbol->get_relativeVirtualAddress(&rva_last))) {
fprintf(stderr, "failed to get symbol rva\n");
return false;
}
ULONG count;
do {
DWORD tag;
if (FAILED(symbol->get_symTag(&tag))) {
fprintf(stderr, "failed to get symbol tag\n");
return false;
}
if (tag == SymTagFunction) {
if (!PrintFunction(symbol)) {
return false;
}
}
symbol.Release();
} while (SUCCEEDED(symbols->Next(1, &symbol, &count)) && count == 1);
return true;
}
bool PDBSourceLineWriter::WriteMap(FILE *map_file) {
bool ret = false;
output_ = map_file;
if (PrintSourceFiles() && PrintFunctions()) {
ret = true;
}
output_ = NULL;
return ret;
}
void PDBSourceLineWriter::Close() {
session_.Release();
}
} // namespace google_airbag

View File

@@ -0,0 +1,77 @@
// Copyright (C) 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// PDBSourceLineWriter uses a pdb file produced by Visual C++ to output
// a line/address map for use with SourceLineResolver.
#ifndef _PDB_SOURCE_LINE_WRITER_H__
#define _PDB_SOURCE_LINE_WRITER_H__
#include <string>
#include <atlcomcli.h>
struct IDiaEnumLineNumbers;
struct IDiaSession;
struct IDiaSymbol;
namespace google_airbag {
using std::wstring;
class PDBSourceLineWriter {
public:
explicit PDBSourceLineWriter();
~PDBSourceLineWriter();
// Opens the given pdb file. If there is already a pdb file open,
// it is automatically closed. Returns true on success.
bool Open(const wstring &pdb_file);
// Writes a map file from the current pdb file to the given file stream.
// Returns true on success.
bool WriteMap(FILE *map_file);
// Closes the current pdb file and its associated resources.
void Close();
private:
// Outputs the line/address pairs for each line in the enumerator.
// Returns true on success.
bool PrintLines(IDiaEnumLineNumbers *lines);
// Outputs a function address and name, followed by its source line list.
// Returns true on success.
bool PrintFunction(IDiaSymbol *function);
// Outputs all functions as described above. Returns true on success.
bool PrintFunctions();
// Outputs all of the source files in the session's pdb file.
// Returns true on success.
bool PrintSourceFiles();
// The session for the currently-open pdb file.
CComPtr<IDiaSession> session_;
// The current output file for this WriteMap invocation.
FILE *output_;
// Disallow copy ctor and operator=
PDBSourceLineWriter(const PDBSourceLineWriter&);
void operator=(const PDBSourceLineWriter&);
};
} // namespace google_airbag
#endif // _PDB_SOURCE_LINE_WRITER_H__

View File

@@ -0,0 +1,8 @@
#!/bin/sh
Release/dump_syms.exe testdata/dump_syms_regtest.pdb > testdata/dump_syms_regtest.new
if diff -u testdata/dump_syms_regtest.new testdata/dump_syms_regtest.out >& testdata/dump_syms_regtest.diff; then
rm testdata/dump_syms_regtest.diff testdata/dump_syms_regtest.new
echo "PASS"
else
echo "FAIL, see testdata/dump_syms_regtest.[new|diff]"
fi

File diff suppressed because it is too large Load Diff

Binary file not shown.