Breakpad Linux Dumper: Rename structure members to follow the Google C++ Style Guide.

The Google C++ Style Guide says that members of structures needn't
have names ending in underscores. The structure types in
google_breakpad::Module don't follow this rule.

a=jimblandy, r=nealsid


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@505 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
jimblandy 2010-01-28 22:59:15 +00:00
parent 1ac84da26d
commit 3e60d65111
9 changed files with 211 additions and 211 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2009, Google Inc. // Copyright (c) 2010, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -78,10 +78,10 @@ bool DumpStabsHandler::StartFunction(const string &name,
uint64_t address) { uint64_t address) {
assert(!current_function_); assert(!current_function_);
Module::Function *f = new Module::Function; Module::Function *f = new Module::Function;
f->name_ = Demangle(name); f->name = Demangle(name);
f->address_ = address; f->address = address;
f->size_ = 0; // We compute this in DumpStabsHandler::Finalize(). f->size = 0; // We compute this in DumpStabsHandler::Finalize().
f->parameter_size_ = 0; // We don't provide this information. f->parameter_size = 0; // We don't provide this information.
current_function_ = f; current_function_ = f;
boundaries_.push_back(static_cast<Module::Address>(address)); boundaries_.push_back(static_cast<Module::Address>(address));
return true; return true;
@ -97,7 +97,7 @@ bool DumpStabsHandler::EndFunction(uint64_t address) {
// (I don't really understand the above comment; just bringing it // (I don't really understand the above comment; just bringing it
// along from the previous code, and leaving the behaivor unchanged. // along from the previous code, and leaving the behaivor unchanged.
// If you know the whole story, please patch this comment. --jimb) // If you know the whole story, please patch this comment. --jimb)
if (current_function_->address_ >= comp_unit_base_address_) if (current_function_->address >= comp_unit_base_address_)
functions_.push_back(current_function_); functions_.push_back(current_function_);
else else
delete current_function_; delete current_function_;
@ -115,11 +115,11 @@ bool DumpStabsHandler::Line(uint64_t address, const char *name, int number) {
current_source_file_name_ = name; current_source_file_name_ = name;
} }
Module::Line line; Module::Line line;
line.address_ = address; line.address = address;
line.size_ = 0; // We compute this in DumpStabsHandler::Finalize(). line.size = 0; // We compute this in DumpStabsHandler::Finalize().
line.file_ = current_source_file_; line.file = current_source_file_;
line.number_ = number; line.number = number;
current_function_->lines_.push_back(line); current_function_->lines.push_back(line);
return true; return true;
} }
@ -142,27 +142,27 @@ void DumpStabsHandler::Finalize() {
Module::Function *f = *func_it; Module::Function *f = *func_it;
// Compute the function f's size. // Compute the function f's size.
vector<Module::Address>::iterator boundary vector<Module::Address>::iterator boundary
= std::upper_bound(boundaries_.begin(), boundaries_.end(), f->address_); = std::upper_bound(boundaries_.begin(), boundaries_.end(), f->address);
if (boundary != boundaries_.end()) if (boundary != boundaries_.end())
f->size_ = *boundary - f->address_; f->size = *boundary - f->address;
else else
// If this is the last function in the module, and the STABS // If this is the last function in the module, and the STABS
// reader was unable to give us its ending address, then assign // reader was unable to give us its ending address, then assign
// it a bogus, very large value. This will happen at most once // it a bogus, very large value. This will happen at most once
// per module: since we've added all functions' addresses to the // per module: since we've added all functions' addresses to the
// boundary table, only one can be the last. // boundary table, only one can be the last.
f->size_ = kFallbackSize; f->size = kFallbackSize;
// Compute sizes for each of the function f's lines --- if it has any. // Compute sizes for each of the function f's lines --- if it has any.
if (!f->lines_.empty()) { if (!f->lines.empty()) {
stable_sort(f->lines_.begin(), f->lines_.end(), stable_sort(f->lines.begin(), f->lines.end(),
Module::Line::CompareByAddress); Module::Line::CompareByAddress);
vector<Module::Line>::iterator last_line = f->lines_.end() - 1; vector<Module::Line>::iterator last_line = f->lines.end() - 1;
for (vector<Module::Line>::iterator line_it = f->lines_.begin(); for (vector<Module::Line>::iterator line_it = f->lines.begin();
line_it != last_line; line_it++) line_it != last_line; line_it++)
line_it[0].size_ = line_it[1].address_ - line_it[0].address_; line_it[0].size = line_it[1].address - line_it[0].address;
// Compute the size of the last line from f's end address. // Compute the size of the last line from f's end address.
last_line->size_ = (f->address_ + f->size_) - last_line->address_; last_line->size = (f->address + f->size) - last_line->address;
} }
} }
// Now that everything has a size, add our functions to the module, and // Now that everything has a size, add our functions to the module, and

View file

@ -1,4 +1,4 @@
// Copyright (c) 2009, Google Inc. // Copyright (c) 2010, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -60,16 +60,16 @@ TEST(DumpStabsHandler, SimpleCU) {
m.GetFunctions(&functions, functions.end()); m.GetFunctions(&functions, functions.end());
ASSERT_EQ((size_t) 1, functions.size()); ASSERT_EQ((size_t) 1, functions.size());
Module::Function *function = functions[0]; Module::Function *function = functions[0];
EXPECT_STREQ("function", function->name_.c_str()); EXPECT_STREQ("function", function->name.c_str());
EXPECT_EQ(0xfde4abbed390c394LL, function->address_); EXPECT_EQ(0xfde4abbed390c394LL, function->address);
EXPECT_EQ(0x10U, function->size_); EXPECT_EQ(0x10U, function->size);
EXPECT_EQ(0U, function->parameter_size_); EXPECT_EQ(0U, function->parameter_size);
ASSERT_EQ((size_t) 1, function->lines_.size()); ASSERT_EQ((size_t) 1, function->lines.size());
Module::Line *line = &function->lines_[0]; Module::Line *line = &function->lines[0];
EXPECT_EQ(0xfde4abbed390c394LL, line->address_); EXPECT_EQ(0xfde4abbed390c394LL, line->address);
EXPECT_EQ(0x10U, line->size_); // derived from EndFunction EXPECT_EQ(0x10U, line->size); // derived from EndFunction
EXPECT_TRUE(line->file_ == file); EXPECT_TRUE(line->file == file);
EXPECT_EQ(174823314, line->number_); EXPECT_EQ(174823314, line->number);
} }
TEST(InferSizes, LineSize) { TEST(InferSizes, LineSize) {
@ -101,23 +101,23 @@ TEST(InferSizes, LineSize) {
ASSERT_EQ((size_t) 1, functions.size()); ASSERT_EQ((size_t) 1, functions.size());
Module::Function *function = functions[0]; Module::Function *function = functions[0];
EXPECT_STREQ("function", function->name_.c_str()); EXPECT_STREQ("function", function->name.c_str());
EXPECT_EQ(0xb4513962eff94e92LL, function->address_); EXPECT_EQ(0xb4513962eff94e92LL, function->address);
EXPECT_EQ(0x1000100000000ULL, function->size_); // inferred from CU end EXPECT_EQ(0x1000100000000ULL, function->size); // inferred from CU end
EXPECT_EQ(0U, function->parameter_size_); EXPECT_EQ(0U, function->parameter_size);
ASSERT_EQ((size_t) 2, function->lines_.size()); ASSERT_EQ((size_t) 2, function->lines.size());
Module::Line *line1 = &function->lines_[0]; Module::Line *line1 = &function->lines[0];
EXPECT_EQ(0xb4513962eff94e92LL, line1->address_); EXPECT_EQ(0xb4513962eff94e92LL, line1->address);
EXPECT_EQ(0x100000000ULL, line1->size_); // derived from EndFunction EXPECT_EQ(0x100000000ULL, line1->size); // derived from EndFunction
EXPECT_TRUE(line1->file_ == file1); EXPECT_TRUE(line1->file == file1);
EXPECT_EQ(77396614, line1->number_); EXPECT_EQ(77396614, line1->number);
Module::Line *line2 = &function->lines_[1]; Module::Line *line2 = &function->lines[1];
EXPECT_EQ(0xb4513963eff94e92LL, line2->address_); EXPECT_EQ(0xb4513963eff94e92LL, line2->address);
EXPECT_EQ(0x1000000000000ULL, line2->size_); // derived from EndFunction EXPECT_EQ(0x1000000000000ULL, line2->size); // derived from EndFunction
EXPECT_TRUE(line2->file_ == file2); EXPECT_TRUE(line2->file == file2);
EXPECT_EQ(87660088, line2->number_); EXPECT_EQ(87660088, line2->number);
} }
TEST(FunctionNames, Mangled) { TEST(FunctionNames, Mangled) {
@ -148,11 +148,11 @@ TEST(FunctionNames, Mangled) {
EXPECT_STREQ("std::vector<unsigned long long, " EXPECT_STREQ("std::vector<unsigned long long, "
"std::allocator<unsigned long long> >::" "std::allocator<unsigned long long> >::"
"push_back(unsigned long long const&)", "push_back(unsigned long long const&)",
function->name_.c_str()); function->name.c_str());
EXPECT_EQ(0xf2cfda63cef7f46dLL, function->address_); EXPECT_EQ(0xf2cfda63cef7f46dLL, function->address);
EXPECT_LT(0U, function->size_); // should have used dummy size EXPECT_LT(0U, function->size); // should have used dummy size
EXPECT_EQ(0U, function->parameter_size_); EXPECT_EQ(0U, function->parameter_size);
ASSERT_EQ(0U, function->lines_.size()); ASSERT_EQ(0U, function->lines.size());
} }
// TODO --- if we actually cared about STABS. Even without these we've // TODO --- if we actually cared about STABS. Even without these we've

View file

@ -316,10 +316,10 @@ void DwarfCUToModule::FuncHandler::Finish() {
// Create a Module::Function based on the data we've gathered, and // Create a Module::Function based on the data we've gathered, and
// add it to the functions_ list. // add it to the functions_ list.
Module::Function *func = new Module::Function; Module::Function *func = new Module::Function;
func->name_ = name_; func->name = name_;
func->address_ = low_pc_; func->address = low_pc_;
func->size_ = high_pc_ - low_pc_; func->size = high_pc_ - low_pc_;
func->parameter_size_ = 0; func->parameter_size = 0;
cu_context_->functions.push_back(func); cu_context_->functions.push_back(func);
} }
} }
@ -404,15 +404,15 @@ void DwarfCUToModule::WarningReporter::UncoveredFunction(
const Module::Function &function) { const Module::Function &function) {
UncoveredHeading(); UncoveredHeading();
fprintf(stderr, " function%s: %s\n", fprintf(stderr, " function%s: %s\n",
function.size_ == 0 ? " (zero-length)" : "", function.size == 0 ? " (zero-length)" : "",
function.name_.c_str()); function.name.c_str());
} }
void DwarfCUToModule::WarningReporter::UncoveredLine(const Module::Line &line) { void DwarfCUToModule::WarningReporter::UncoveredLine(const Module::Line &line) {
UncoveredHeading(); UncoveredHeading();
fprintf(stderr, " line%s: %s:%d at 0x%llx\n", fprintf(stderr, " line%s: %s:%d at 0x%llx\n",
(line.size_ == 0 ? " (zero-length)" : ""), (line.size == 0 ? " (zero-length)" : ""),
line.file_->name_.c_str(), line.number_, line.address_); line.file->name.c_str(), line.number, line.address);
} }
DwarfCUToModule::DwarfCUToModule(FileContext *file_context, DwarfCUToModule::DwarfCUToModule(FileContext *file_context,
@ -545,7 +545,7 @@ inline bool within(const T &item, Module::Address address) {
// Because Module::Address is unsigned, and unsigned arithmetic // Because Module::Address is unsigned, and unsigned arithmetic
// wraps around, this will be false if ADDRESS falls before the // wraps around, this will be false if ADDRESS falls before the
// start of ITEM, or if it falls after ITEM's end. // start of ITEM, or if it falls after ITEM's end.
return address - item.address_ < item.size_; return address - item.address < item.size;
} }
} }
@ -579,7 +579,7 @@ void DwarfCUToModule::AssignLinesToFunctions() {
const Module::Line *last_line_cited = NULL; const Module::Line *last_line_cited = NULL;
// Make a single pass through both vectors from lower to higher // Make a single pass through both vectors from lower to higher
// addresses, populating each Function's lines_ vector with lines // addresses, populating each Function's lines vector with lines
// from our lines_ vector that fall within the function's address // from our lines_ vector that fall within the function's address
// range. // range.
vector<Module::Function *>::iterator func_it = functions->begin(); vector<Module::Function *>::iterator func_it = functions->begin();
@ -597,15 +597,15 @@ void DwarfCUToModule::AssignLinesToFunctions() {
if (func_it != functions->end() && line_it != lines_.end()) { if (func_it != functions->end() && line_it != lines_.end()) {
func = *func_it; func = *func_it;
line = &*line_it; line = &*line_it;
current = std::min(func->address_, line->address_); current = std::min(func->address, line->address);
} else if (line_it != lines_.end()) { } else if (line_it != lines_.end()) {
func = NULL; func = NULL;
line = &*line_it; line = &*line_it;
current = line->address_; current = line->address;
} else if (func_it != functions->end()) { } else if (func_it != functions->end()) {
func = *func_it; func = *func_it;
line = NULL; line = NULL;
current = (*func_it)->address_; current = (*func_it)->address;
} else { } else {
return; return;
} }
@ -640,25 +640,25 @@ void DwarfCUToModule::AssignLinesToFunctions() {
// iterator. So neither iterator moves. // iterator. So neither iterator moves.
// Assert the first invariant (see above). // Assert the first invariant (see above).
assert(!func || current < func->address_ || within(*func, current)); assert(!func || current < func->address || within(*func, current));
assert(!line || current < line->address_ || within(*line, current)); assert(!line || current < line->address || within(*line, current));
// The next transition after CURRENT. // The next transition after CURRENT.
Module::Address next_transition; Module::Address next_transition;
// Figure out which state we're in, add lines or warn, and compute // Figure out which state we're in, add lines or warn, and compute
// the next transition address. // the next transition address.
if (func && current >= func->address_) { if (func && current >= func->address) {
if (line && current >= line->address_) { if (line && current >= line->address) {
// Covered by both a line and a function. // Covered by both a line and a function.
Module::Address func_left = func->size_ - (current - func->address_); Module::Address func_left = func->size - (current - func->address);
Module::Address line_left = line->size_ - (current - line->address_); Module::Address line_left = line->size - (current - line->address);
// This may overflow, but things work out. // This may overflow, but things work out.
next_transition = current + std::min(func_left, line_left); next_transition = current + std::min(func_left, line_left);
Module::Line l = *line; Module::Line l = *line;
l.address_ = current; l.address = current;
l.size_ = next_transition - current; l.size = next_transition - current;
func->lines_.push_back(l); func->lines.push_back(l);
last_line_used = line; last_line_used = line;
} else { } else {
// Covered by a function, but no line. // Covered by a function, but no line.
@ -666,14 +666,14 @@ void DwarfCUToModule::AssignLinesToFunctions() {
reporter->UncoveredFunction(*func); reporter->UncoveredFunction(*func);
last_function_cited = func; last_function_cited = func;
} }
if (line && within(*func, line->address_)) if (line && within(*func, line->address))
next_transition = line->address_; next_transition = line->address;
else else
// If this overflows, we'll catch it below. // If this overflows, we'll catch it below.
next_transition = func->address_ + func->size_; next_transition = func->address + func->size;
} }
} else { } else {
if (line && current >= line->address_) { if (line && current >= line->address) {
// Covered by a line, but no function. // Covered by a line, but no function.
// //
// If GCC emits padding after one function to align the start // If GCC emits padding after one function to align the start
@ -688,15 +688,15 @@ void DwarfCUToModule::AssignLinesToFunctions() {
if (line != last_line_cited if (line != last_line_cited
&& !(func && !(func
&& line == last_line_used && line == last_line_used
&& func->address_ - line->address_ == line->size_)) { && func->address - line->address == line->size)) {
reporter->UncoveredLine(*line); reporter->UncoveredLine(*line);
last_line_cited = line; last_line_cited = line;
} }
if (func && within(*line, func->address_)) if (func && within(*line, func->address))
next_transition = func->address_; next_transition = func->address;
else else
// If this overflows, we'll catch it below. // If this overflows, we'll catch it below.
next_transition = line->address_ + line->size_; next_transition = line->address + line->size;
} else { } else {
// Covered by neither a function nor a line. By the invariant, // Covered by neither a function nor a line. By the invariant,
// both func and line begin after CURRENT. The next transition // both func and line begin after CURRENT. The next transition
@ -704,11 +704,11 @@ void DwarfCUToModule::AssignLinesToFunctions() {
// is earliest. // is earliest.
assert (func || line); assert (func || line);
if (func && line) if (func && line)
next_transition = std::min(func->address_, line->address_); next_transition = std::min(func->address, line->address);
else if (func) else if (func)
next_transition = func->address_; next_transition = func->address;
else else
next_transition = line->address_; next_transition = line->address;
} }
} }
@ -724,12 +724,12 @@ void DwarfCUToModule::AssignLinesToFunctions() {
// about what result we produce in that case, just as long as we don't // about what result we produce in that case, just as long as we don't
// hang or crash. // hang or crash.
while (func_it != functions->end() while (func_it != functions->end()
&& current >= (*func_it)->address_ && current >= (*func_it)->address
&& !within(**func_it, next_transition)) && !within(**func_it, next_transition))
func_it++; func_it++;
func = (func_it != functions->end()) ? *func_it : NULL; func = (func_it != functions->end()) ? *func_it : NULL;
while (line_it != lines_.end() while (line_it != lines_.end()
&& current >= line_it->address_ && current >= line_it->address
&& !within(*line_it, next_transition)) && !within(*line_it, next_transition))
line_it++; line_it++;
line = (line_it != lines_.end()) ? &*line_it : NULL; line = (line_it != lines_.end()) ? &*line_it : NULL;

View file

@ -276,10 +276,10 @@ const size_t CUFixtureBase::dummy_line_size_ =
void CUFixtureBase::PushLine(Module::Address address, Module::Address size, void CUFixtureBase::PushLine(Module::Address address, Module::Address size,
const string &filename, int line_number) { const string &filename, int line_number) {
Module::Line l; Module::Line l;
l.address_ = address; l.address = address;
l.size_ = size; l.size = size;
l.file_ = module_.FindFile(filename); l.file = module_.FindFile(filename);
l.number_ = line_number; l.number = line_number;
lines_.push_back(l); lines_.push_back(l);
} }
@ -539,17 +539,17 @@ void CUFixtureBase::TestFunction(int i, const string &name,
ASSERT_LT((size_t) i, functions_.size()); ASSERT_LT((size_t) i, functions_.size());
Module::Function *function = functions_[i]; Module::Function *function = functions_[i];
EXPECT_EQ(name, function->name_); EXPECT_EQ(name, function->name);
EXPECT_EQ(address, function->address_); EXPECT_EQ(address, function->address);
EXPECT_EQ(size, function->size_); EXPECT_EQ(size, function->size);
EXPECT_EQ(0U, function->parameter_size_); EXPECT_EQ(0U, function->parameter_size);
} }
void CUFixtureBase::TestLineCount(int i, size_t expected) { void CUFixtureBase::TestLineCount(int i, size_t expected) {
FillFunctions(); FillFunctions();
ASSERT_LT((size_t) i, functions_.size()); ASSERT_LT((size_t) i, functions_.size());
ASSERT_EQ(expected, functions_[i]->lines_.size()); ASSERT_EQ(expected, functions_[i]->lines.size());
} }
void CUFixtureBase::TestLine(int i, int j, void CUFixtureBase::TestLine(int i, int j,
@ -557,13 +557,13 @@ void CUFixtureBase::TestLine(int i, int j,
const string &filename, int number) { const string &filename, int number) {
FillFunctions(); FillFunctions();
ASSERT_LT((size_t) i, functions_.size()); ASSERT_LT((size_t) i, functions_.size());
ASSERT_LT((size_t) j, functions_[i]->lines_.size()); ASSERT_LT((size_t) j, functions_[i]->lines.size());
Module::Line *line = &functions_[i]->lines_[j]; Module::Line *line = &functions_[i]->lines[j];
EXPECT_EQ(address, line->address_); EXPECT_EQ(address, line->address);
EXPECT_EQ(size, line->size_); EXPECT_EQ(size, line->size);
EXPECT_EQ(filename, line->file_->name_.c_str()); EXPECT_EQ(filename, line->file->name.c_str());
EXPECT_EQ(number, line->number_); EXPECT_EQ(number, line->number);
} }
// Include caller locations for our test subroutines. // Include caller locations for our test subroutines.
@ -1280,7 +1280,7 @@ TEST_F(Specifications, InterCU) {
vector<Module::Function *> functions; vector<Module::Function *> functions;
m.GetFunctions(&functions, functions.end()); m.GetFunctions(&functions, functions.end());
EXPECT_EQ(1U, functions.size()); EXPECT_EQ(1U, functions.size());
EXPECT_STREQ("class_A::member_func_B", functions[0]->name_.c_str()); EXPECT_STREQ("class_A::member_func_B", functions[0]->name.c_str());
} }
TEST_F(Specifications, BadOffset) { TEST_F(Specifications, BadOffset) {

View file

@ -108,11 +108,11 @@ void DwarfLineToModule::AddLine(uint64 address, uint64 length,
return; return;
} }
Module::Line line; Module::Line line;
line.address_ = address; line.address = address;
// We set the size when we get the next line or the EndSequence call. // We set the size when we get the next line or the EndSequence call.
line.size_ = length; line.size = length;
line.file_ = file; line.file = file;
line.number_ = line_num; line.number = line_num;
lines_->push_back(line); lines_->push_back(line);
} }

View file

@ -48,13 +48,13 @@ TEST(Simple, One) {
vector<Module::File *> files; vector<Module::File *> files;
m.GetFiles(&files); m.GetFiles(&files);
EXPECT_EQ(1U, files.size()); EXPECT_EQ(1U, files.size());
EXPECT_STREQ("file1", files[0]->name_.c_str()); EXPECT_STREQ("file1", files[0]->name.c_str());
EXPECT_EQ(1U, lines.size()); EXPECT_EQ(1U, lines.size());
EXPECT_EQ(0x6fd126fbf74f2680ULL, lines[0].address_); EXPECT_EQ(0x6fd126fbf74f2680ULL, lines[0].address);
EXPECT_EQ(0x63c9a14cf556712bULL, lines[0].size_); EXPECT_EQ(0x63c9a14cf556712bULL, lines[0].size);
EXPECT_TRUE(lines[0].file_ == files[0]); EXPECT_TRUE(lines[0].file == files[0]);
EXPECT_EQ(0x4c090cbf, lines[0].number_); EXPECT_EQ(0x4c090cbf, lines[0].number);
} }
TEST(Simple, Many) { TEST(Simple, Many) {
@ -83,38 +83,38 @@ TEST(Simple, Many) {
vector<Module::File *> files; vector<Module::File *> files;
m.GetFiles(&files); m.GetFiles(&files);
ASSERT_EQ(5U, files.size()); ASSERT_EQ(5U, files.size());
EXPECT_STREQ("directory1/file1", files[0]->name_.c_str()); EXPECT_STREQ("directory1/file1", files[0]->name.c_str());
EXPECT_STREQ("directory1/file2", files[1]->name_.c_str()); EXPECT_STREQ("directory1/file2", files[1]->name.c_str());
EXPECT_STREQ("directory2/file1", files[2]->name_.c_str()); EXPECT_STREQ("directory2/file1", files[2]->name.c_str());
EXPECT_STREQ("directory2/file2", files[3]->name_.c_str()); EXPECT_STREQ("directory2/file2", files[3]->name.c_str());
EXPECT_STREQ("file3", files[4]->name_.c_str()); EXPECT_STREQ("file3", files[4]->name.c_str());
ASSERT_EQ(5U, lines.size()); ASSERT_EQ(5U, lines.size());
EXPECT_EQ(0x69900c5d553b7274ULL, lines[0].address_); EXPECT_EQ(0x69900c5d553b7274ULL, lines[0].address);
EXPECT_EQ(0x90fded183f0d0d3cULL, lines[0].size_); EXPECT_EQ(0x90fded183f0d0d3cULL, lines[0].size);
EXPECT_TRUE(lines[0].file_ == files[0]); EXPECT_TRUE(lines[0].file == files[0]);
EXPECT_EQ(0x15b0f0a9, lines[0].number_); EXPECT_EQ(0x15b0f0a9, lines[0].number);
EXPECT_EQ(0x45811219a39b7101ULL, lines[1].address_); EXPECT_EQ(0x45811219a39b7101ULL, lines[1].address);
EXPECT_EQ(0x25a5e6a924afc41fULL, lines[1].size_); EXPECT_EQ(0x25a5e6a924afc41fULL, lines[1].size);
EXPECT_TRUE(lines[1].file_ == files[2]); EXPECT_TRUE(lines[1].file == files[2]);
EXPECT_EQ(0x4d259ce9, lines[1].number_); EXPECT_EQ(0x4d259ce9, lines[1].number);
EXPECT_EQ(0xfa90514c1dc9704bULL, lines[2].address_); EXPECT_EQ(0xfa90514c1dc9704bULL, lines[2].address);
EXPECT_EQ(0x0063efeabc02f313ULL, lines[2].size_); EXPECT_EQ(0x0063efeabc02f313ULL, lines[2].size);
EXPECT_TRUE(lines[2].file_ == files[1]); EXPECT_TRUE(lines[2].file == files[1]);
EXPECT_EQ(0x1ee9fa4f, lines[2].number_); EXPECT_EQ(0x1ee9fa4f, lines[2].number);
EXPECT_EQ(0x556b55fb6a647b10ULL, lines[3].address_); EXPECT_EQ(0x556b55fb6a647b10ULL, lines[3].address);
EXPECT_EQ(0x3f3089ca2bfd80f5ULL, lines[3].size_); EXPECT_EQ(0x3f3089ca2bfd80f5ULL, lines[3].size);
EXPECT_TRUE(lines[3].file_ == files[3]); EXPECT_TRUE(lines[3].file == files[3]);
EXPECT_EQ(0x77fc280e, lines[3].number_); EXPECT_EQ(0x77fc280e, lines[3].number);
EXPECT_EQ(0xe2d72a37f8d9403aULL, lines[4].address_); EXPECT_EQ(0xe2d72a37f8d9403aULL, lines[4].address);
EXPECT_EQ(0x034dfab5b0d4d236ULL, lines[4].size_); EXPECT_EQ(0x034dfab5b0d4d236ULL, lines[4].size);
EXPECT_TRUE(lines[4].file_ == files[4]); EXPECT_TRUE(lines[4].file == files[4]);
EXPECT_EQ(0x75047044, lines[4].number_); EXPECT_EQ(0x75047044, lines[4].number);
} }
TEST(Filenames, Absolute) { TEST(Filenames, Absolute) {
@ -130,9 +130,9 @@ TEST(Filenames, Absolute) {
vector<Module::File *> files; vector<Module::File *> files;
m.GetFiles(&files); m.GetFiles(&files);
ASSERT_EQ(1U, files.size()); ASSERT_EQ(1U, files.size());
EXPECT_STREQ("/absolute", files[0]->name_.c_str()); EXPECT_STREQ("/absolute", files[0]->name.c_str());
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_TRUE(lines[0].file_ == files[0]); EXPECT_TRUE(lines[0].file == files[0]);
} }
TEST(Filenames, Relative) { TEST(Filenames, Relative) {
@ -148,9 +148,9 @@ TEST(Filenames, Relative) {
vector<Module::File *> files; vector<Module::File *> files;
m.GetFiles(&files); m.GetFiles(&files);
ASSERT_EQ(1U, files.size()); ASSERT_EQ(1U, files.size());
EXPECT_STREQ("directory1/relative", files[0]->name_.c_str()); EXPECT_STREQ("directory1/relative", files[0]->name.c_str());
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_TRUE(lines[0].file_ == files[0]); EXPECT_TRUE(lines[0].file == files[0]);
} }
TEST(Filenames, StrangeFile) { TEST(Filenames, StrangeFile) {
@ -163,7 +163,7 @@ TEST(Filenames, StrangeFile) {
h.AddLine(1, 1, 1, 0, 0); h.AddLine(1, 1, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_STREQ("directory1/", lines[0].file_->name_.c_str()); EXPECT_STREQ("directory1/", lines[0].file->name.c_str());
} }
TEST(Filenames, StrangeDirectory) { TEST(Filenames, StrangeDirectory) {
@ -176,7 +176,7 @@ TEST(Filenames, StrangeDirectory) {
h.AddLine(1, 1, 1, 0, 0); h.AddLine(1, 1, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_STREQ("/file1", lines[0].file_->name_.c_str()); EXPECT_STREQ("/file1", lines[0].file->name.c_str());
} }
TEST(Filenames, StrangeDirectoryAndFile) { TEST(Filenames, StrangeDirectoryAndFile) {
@ -189,7 +189,7 @@ TEST(Filenames, StrangeDirectoryAndFile) {
h.AddLine(1, 1, 1, 0, 0); h.AddLine(1, 1, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_STREQ("/", lines[0].file_->name_.c_str()); EXPECT_STREQ("/", lines[0].file->name.c_str());
} }
// We should silently ignore attempts to define directory number zero, // We should silently ignore attempts to define directory number zero,
@ -205,7 +205,7 @@ TEST(Errors, DirectoryZero) {
h.AddLine(1, 1, 1, 0, 0); h.AddLine(1, 1, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_STREQ("relative", lines[0].file_->name_.c_str()); EXPECT_STREQ("relative", lines[0].file->name.c_str());
} }
// We should refuse to add lines with bogus file numbers. We should // We should refuse to add lines with bogus file numbers. We should
@ -235,7 +235,7 @@ TEST(Errors, BadDirectoryNumber) {
h.AddLine(1, 1, 1, 0, 0); h.AddLine(1, 1, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_STREQ("baddirnumber1", lines[0].file_->name_.c_str()); EXPECT_STREQ("baddirnumber1", lines[0].file->name.c_str());
} }
// We promise not to report empty lines. // We promise not to report empty lines.
@ -261,5 +261,5 @@ TEST(Errors, BigLine) {
h.AddLine(0xffffffffffffffffULL, 2, 1, 0, 0); h.AddLine(0xffffffffffffffffULL, 2, 1, 0, 0);
ASSERT_EQ(1U, lines.size()); ASSERT_EQ(1U, lines.size());
EXPECT_EQ(1U, lines[0].size_); EXPECT_EQ(1U, lines[0].size);
} }

View file

@ -1,4 +1,4 @@
// Copyright (c) 2009, Google Inc. // Copyright (c) 2010, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -83,10 +83,10 @@ Module::File *Module::FindFile(const string &name) {
if (destiny == files_.end() if (destiny == files_.end()
|| *destiny->first != name) { // Repeated string comparison, boo hoo. || *destiny->first != name) { // Repeated string comparison, boo hoo.
File *file = new File; File *file = new File;
file->name_ = name; file->name = name;
file->source_id_ = -1; file->source_id = -1;
destiny = files_.insert(destiny, destiny = files_.insert(destiny,
FileByNameMap::value_type(&file->name_, file)); FileByNameMap::value_type(&file->name, file));
} }
return destiny->second; return destiny->second;
} }
@ -111,16 +111,16 @@ void Module::AssignSourceIds() {
// First, give every source file an id of -1. // First, give every source file an id of -1.
for (FileByNameMap::iterator file_it = files_.begin(); for (FileByNameMap::iterator file_it = files_.begin();
file_it != files_.end(); file_it++) file_it != files_.end(); file_it++)
file_it->second->source_id_ = -1; file_it->second->source_id = -1;
// Next, mark all files actually cited by our functions' line number // Next, mark all files actually cited by our functions' line number
// info, by setting each one's source id to zero. // info, by setting each one's source id to zero.
for (vector<Function *>::const_iterator func_it = functions_.begin(); for (vector<Function *>::const_iterator func_it = functions_.begin();
func_it != functions_.end(); func_it++) { func_it != functions_.end(); func_it++) {
Function *func = *func_it; Function *func = *func_it;
for (vector<Line>::iterator line_it = func->lines_.begin(); for (vector<Line>::iterator line_it = func->lines.begin();
line_it != func->lines_.end(); line_it++) line_it != func->lines.end(); line_it++)
line_it->file_->source_id_ = 0; line_it->file->source_id = 0;
} }
// Finally, assign source ids to those files that have been marked. // Finally, assign source ids to those files that have been marked.
@ -130,8 +130,8 @@ void Module::AssignSourceIds() {
int next_source_id = 0; int next_source_id = 0;
for (FileByNameMap::iterator file_it = files_.begin(); for (FileByNameMap::iterator file_it = files_.begin();
file_it != files_.end(); file_it++) file_it != files_.end(); file_it++)
if (! file_it->second->source_id_) if (! file_it->second->source_id)
file_it->second->source_id_ = next_source_id++; file_it->second->source_id = next_source_id++;
} }
bool Module::ReportError() { bool Module::ReportError() {
@ -152,9 +152,9 @@ bool Module::Write(FILE *stream) {
for (FileByNameMap::iterator file_it = files_.begin(); for (FileByNameMap::iterator file_it = files_.begin();
file_it != files_.end(); file_it++) { file_it != files_.end(); file_it++) {
File *file = file_it->second; File *file = file_it->second;
if (file->source_id_ >= 0) { if (file->source_id >= 0) {
if (0 > fprintf(stream, "FILE %d %s\n", if (0 > fprintf(stream, "FILE %d %s\n",
file->source_id_, file->name_.c_str())) file->source_id, file->name.c_str()))
return ReportError(); return ReportError();
} }
} }
@ -164,18 +164,18 @@ bool Module::Write(FILE *stream) {
func_it != functions_.end(); func_it++) { func_it != functions_.end(); func_it++) {
Function *func = *func_it; Function *func = *func_it;
if (0 > fprintf(stream, "FUNC %llx %llx %llx %s\n", if (0 > fprintf(stream, "FUNC %llx %llx %llx %s\n",
(unsigned long long) (func->address_ - load_address_), (unsigned long long) (func->address - load_address_),
(unsigned long long) func->size_, (unsigned long long) func->size,
(unsigned long long) func->parameter_size_, (unsigned long long) func->parameter_size,
func->name_.c_str())) func->name.c_str()))
return ReportError(); return ReportError();
for (vector<Line>::iterator line_it = func->lines_.begin(); for (vector<Line>::iterator line_it = func->lines.begin();
line_it != func->lines_.end(); line_it++) line_it != func->lines.end(); line_it++)
if (0 > fprintf(stream, "%llx %llx %d %d\n", if (0 > fprintf(stream, "%llx %llx %d %d\n",
(unsigned long long) (line_it->address_ - load_address_), (unsigned long long) (line_it->address - load_address_),
(unsigned long long) line_it->size_, (unsigned long long) line_it->size,
line_it->number_, line_it->number,
line_it->file_->source_id_)) line_it->file->source_id))
return ReportError(); return ReportError();
} }

View file

@ -67,12 +67,12 @@ class Module {
// A source file. // A source file.
struct File { struct File {
// The name of the source file. // The name of the source file.
string name_; string name;
// The file's source id. The Write member function clears this // The file's source id. The Write member function clears this
// field and assigns source ids a fresh, so any value placed here // field and assigns source ids a fresh, so any value placed here
// before calling Write will be lost. // before calling Write will be lost.
int source_id_; int source_id;
}; };
// A function. // A function.
@ -80,21 +80,21 @@ class Module {
// For sorting by address. (Not style-guide compliant, but it's // For sorting by address. (Not style-guide compliant, but it's
// stupid not to put this in the struct.) // stupid not to put this in the struct.)
static bool CompareByAddress(const Function *x, const Function *y) { static bool CompareByAddress(const Function *x, const Function *y) {
return x->address_ < y->address_; return x->address < y->address;
} }
// The function's name. // The function's name.
string name_; string name;
// The start address and length of the function's code. // The start address and length of the function's code.
Address address_, size_; Address address, size;
// The function's parameter size. // The function's parameter size.
Address parameter_size_; Address parameter_size;
// Source lines belonging to this function, sorted by increasing // Source lines belonging to this function, sorted by increasing
// address. // address.
vector<Line> lines_; vector<Line> lines;
}; };
// A source line. // A source line.
@ -102,12 +102,12 @@ class Module {
// For sorting by address. (Not style-guide compliant, but it's // For sorting by address. (Not style-guide compliant, but it's
// stupid not to put this in the struct.) // stupid not to put this in the struct.)
static bool CompareByAddress(const Module::Line &x, const Module::Line &y) { static bool CompareByAddress(const Module::Line &x, const Module::Line &y) {
return x.address_ < y.address_; return x.address < y.address;
} }
Address address_, size_; // The address and size of the line's code. Address address, size; // The address and size of the line's code.
File *file_; // The source file. File *file; // The source file.
int number_; // The source line number. int number; // The source line number.
}; };
// Create a new module with the given name, operating system, // Create a new module with the given name, operating system,

View file

@ -1,4 +1,4 @@
// Copyright (c) 2009, Google Inc. // Copyright (c) 2010, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -111,13 +111,13 @@ TEST(Write, OneLineFunc) {
Module::File *file = m.FindFile("file_name.cc"); Module::File *file = m.FindFile("file_name.cc");
Module::Function *function = new(Module::Function); Module::Function *function = new(Module::Function);
function->name_ = "function_name"; function->name = "function_name";
function->address_ = 0xe165bf8023b9d9abLL; function->address = 0xe165bf8023b9d9abLL;
function->size_ = 0x1e4bb0eb1cbf5b09LL; function->size = 0x1e4bb0eb1cbf5b09LL;
function->parameter_size_ = 0x772beee89114358aLL; function->parameter_size = 0x772beee89114358aLL;
Module::Line line = { 0xe165bf8023b9d9abLL, 0x1e4bb0eb1cbf5b09LL, Module::Line line = { 0xe165bf8023b9d9abLL, 0x1e4bb0eb1cbf5b09LL,
file, 67519080 }; file, 67519080 };
function->lines_.push_back(line); function->lines.push_back(line);
m.AddFunction(function); m.AddFunction(function);
m.Write(f); m.Write(f);
@ -145,18 +145,18 @@ TEST(Write, RelativeLoadAddress) {
// A function. // A function.
Module::Function *function = new(Module::Function); Module::Function *function = new(Module::Function);
function->name_ = "A_FLIBBERTIJIBBET::a_will_o_the_wisp(a clown)"; function->name = "A_FLIBBERTIJIBBET::a_will_o_the_wisp(a clown)";
function->address_ = 0xbec774ea5dd935f3LL; function->address = 0xbec774ea5dd935f3LL;
function->size_ = 0x2922088f98d3f6fcLL; function->size = 0x2922088f98d3f6fcLL;
function->parameter_size_ = 0xe5e9aa008bd5f0d0LL; function->parameter_size = 0xe5e9aa008bd5f0d0LL;
// Some source lines. The module should not sort these. // Some source lines. The module should not sort these.
Module::Line line1 = { 0xbec774ea5dd935f3LL, 0x1c2be6d6c5af2611LL, Module::Line line1 = { 0xbec774ea5dd935f3LL, 0x1c2be6d6c5af2611LL,
file1, 41676901 }; file1, 41676901 };
Module::Line line2 = { 0xdaf35bc123885c04LL, 0xcf621b8d324d0ebLL, Module::Line line2 = { 0xdaf35bc123885c04LL, 0xcf621b8d324d0ebLL,
file2, 67519080 }; file2, 67519080 };
function->lines_.push_back(line2); function->lines.push_back(line2);
function->lines_.push_back(line1); function->lines.push_back(line1);
m.AddFunction(function); m.AddFunction(function);
@ -185,18 +185,18 @@ TEST(Write, OmitUnusedFiles) {
// Create a function. // Create a function.
Module::Function *function = new(Module::Function); Module::Function *function = new(Module::Function);
function->name_ = "function_name"; function->name = "function_name";
function->address_ = 0x9b926d464f0b9384LL; function->address = 0x9b926d464f0b9384LL;
function->size_ = 0x4f524a4ba795e6a6LL; function->size = 0x4f524a4ba795e6a6LL;
function->parameter_size_ = 0xbbe8133a6641c9b7LL; function->parameter_size = 0xbbe8133a6641c9b7LL;
// Source files that refer to some files, but not others. // Source files that refer to some files, but not others.
Module::Line line1 = { 0x595fa44ebacc1086LL, 0x1e1e0191b066c5b3LL, Module::Line line1 = { 0x595fa44ebacc1086LL, 0x1e1e0191b066c5b3LL,
file1, 137850127 }; file1, 137850127 };
Module::Line line2 = { 0x401ce8c8a12d25e3LL, 0x895751c41b8d2ce2LL, Module::Line line2 = { 0x401ce8c8a12d25e3LL, 0x895751c41b8d2ce2LL,
file3, 28113549 }; file3, 28113549 };
function->lines_.push_back(line1); function->lines.push_back(line1);
function->lines_.push_back(line2); function->lines.push_back(line2);
m.AddFunction(function); m.AddFunction(function);
m.AssignSourceIds(); m.AssignSourceIds();
@ -204,13 +204,13 @@ TEST(Write, OmitUnusedFiles) {
vector<Module::File *> vec; vector<Module::File *> vec;
m.GetFiles(&vec); m.GetFiles(&vec);
EXPECT_EQ((size_t) 3, vec.size()); EXPECT_EQ((size_t) 3, vec.size());
EXPECT_STREQ("filename1", vec[0]->name_.c_str()); EXPECT_STREQ("filename1", vec[0]->name.c_str());
EXPECT_NE(-1, vec[0]->source_id_); EXPECT_NE(-1, vec[0]->source_id);
// Expect filename2 not to be used. // Expect filename2 not to be used.
EXPECT_STREQ("filename2", vec[1]->name_.c_str()); EXPECT_STREQ("filename2", vec[1]->name.c_str());
EXPECT_EQ(-1, vec[1]->source_id_); EXPECT_EQ(-1, vec[1]->source_id);
EXPECT_STREQ("filename3", vec[2]->name_.c_str()); EXPECT_STREQ("filename3", vec[2]->name.c_str());
EXPECT_NE(-1, vec[2]->source_id_); EXPECT_NE(-1, vec[2]->source_id);
FILE *f = checked_tmpfile(); FILE *f = checked_tmpfile();
m.Write(f); m.Write(f);
@ -234,16 +234,16 @@ TEST(Construct, AddFunctions) {
// Two functions. // Two functions.
Module::Function *function1 = new(Module::Function); Module::Function *function1 = new(Module::Function);
function1->name_ = "_without_form"; function1->name = "_without_form";
function1->address_ = 0xd35024aa7ca7da5cLL; function1->address = 0xd35024aa7ca7da5cLL;
function1->size_ = 0x200b26e605f99071LL; function1->size = 0x200b26e605f99071LL;
function1->parameter_size_ = 0xf14ac4fed48c4a99LL; function1->parameter_size = 0xf14ac4fed48c4a99LL;
Module::Function *function2 = new(Module::Function); Module::Function *function2 = new(Module::Function);
function2->name_ = "_and_void"; function2->name = "_and_void";
function2->address_ = 0x2987743d0b35b13fLL; function2->address = 0x2987743d0b35b13fLL;
function2->size_ = 0xb369db048deb3010LL; function2->size = 0xb369db048deb3010LL;
function2->parameter_size_ = 0x938e556cb5a79988LL; function2->parameter_size = 0x938e556cb5a79988LL;
// Put them in a vector. // Put them in a vector.
vector<Module::Function *> vec; vector<Module::Function *> vec;