From 1f87c4a732fa5175218549b4d7053112dbd57894 Mon Sep 17 00:00:00 2001 From: "ted.mielczarek@gmail.com" Date: Wed, 23 Jan 2013 18:01:28 +0000 Subject: Include the compilation directory for FILE entries, making them absolute instead of relative A=Ryan Sleevi R=mark,ted at https://breakpad.appspot.com/385001/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1106 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/common/dwarf_cu_to_module_unittest.cc | 51 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'src/common/dwarf_cu_to_module_unittest.cc') diff --git a/src/common/dwarf_cu_to_module_unittest.cc b/src/common/dwarf_cu_to_module_unittest.cc index 37061d2a..81e629b0 100644 --- a/src/common/dwarf_cu_to_module_unittest.cc +++ b/src/common/dwarf_cu_to_module_unittest.cc @@ -62,14 +62,11 @@ using ::testing::ValuesIn; // Mock classes. -class MockLineToModuleFunctor: public DwarfCUToModule::LineToModuleFunctor { +class MockLineToModuleHandler: public DwarfCUToModule::LineToModuleHandler { public: - MOCK_METHOD4(mock_apply, void(const char *program, uint64 length, - Module *module, vector *lines)); - void operator()(const char *program, uint64 length, - Module *module, vector *lines) { - mock_apply(program, length, module, lines); - } + MOCK_METHOD1(StartCompilationUnit, void(const string& compilation_dir)); + MOCK_METHOD4(ReadProgram, void(const char* program, uint64 length, + Module *module, vector *lines)); }; class MockWarningReporter: public DwarfCUToModule::WarningReporter { @@ -102,10 +99,10 @@ class CUFixtureBase { // appender(line_program, length, module, line_vector); // // will append lines to the end of line_vector. We can use this with - // MockLineToModuleFunctor like this: + // MockLineToModuleHandler like this: // - // MockLineToModuleFunctor l2m; - // EXPECT_CALL(l2m, mock_apply(_,_,_,_)) + // MockLineToModuleHandler l2m; + // EXPECT_CALL(l2m, ReadProgram(_,_,_,_)) // .WillOnce(DoAll(Invoke(appender), Return())); // // in which case calling l2m with some line vector will append lines. @@ -143,7 +140,8 @@ class CUFixtureBase { // By default, expect the line program reader not to be invoked. We // may override this in StartCU. - EXPECT_CALL(line_reader_, mock_apply(_,_,_,_)).Times(0); + EXPECT_CALL(line_reader_, StartCompilationUnit(_)).Times(0); + EXPECT_CALL(line_reader_, ReadProgram(_,_,_,_)).Times(0); // The handler will consult this section map to decide what to // pass to our line reader. @@ -153,7 +151,7 @@ class CUFixtureBase { // Add a line with the given address, size, filename, and line // number to the end of the statement list the handler will receive - // when it invokes its LineToModuleFunctor. Call this before calling + // when it invokes its LineToModuleHandler. Call this before calling // StartCU. void PushLine(Module::Address address, Module::Address size, const string &filename, int line_number); @@ -271,13 +269,17 @@ class CUFixtureBase { // report it as an unsigned value. bool language_signed_; + // If this is not empty, we'll give the CU a DW_AT_comp_dir attribute that + // indicates the path that this compilation unit was compiled in. + string compilation_dir_; + // If this is not empty, we'll give the CU a DW_AT_stmt_list // attribute that, when passed to line_reader_, adds these lines to the // provided lines array. vector lines_; // Mock line program reader. - MockLineToModuleFunctor line_reader_; + MockLineToModuleHandler line_reader_; AppendLinesFunctor appender_; static const char dummy_line_program_[]; static const size_t dummy_line_size_; @@ -311,6 +313,10 @@ void CUFixtureBase::PushLine(Module::Address address, Module::Address size, } void CUFixtureBase::StartCU() { + if (!compilation_dir_.empty()) + EXPECT_CALL(line_reader_, + StartCompilationUnit(compilation_dir_)).Times(1); + // If we have lines, make the line reader expect to be invoked at // most once. (Hey, if the handler can pass its tests without // bothering to read the line number data, that's great.) @@ -318,8 +324,8 @@ void CUFixtureBase::StartCU() { // initial expectation (no calls) in force. if (!lines_.empty()) EXPECT_CALL(line_reader_, - mock_apply(&dummy_line_program_[0], dummy_line_size_, - &module_, _)) + ReadProgram(&dummy_line_program_[0], dummy_line_size_, + &module_, _)) .Times(AtMost(1)) .WillOnce(DoAll(Invoke(appender_), Return())); @@ -333,6 +339,10 @@ void CUFixtureBase::StartCU() { root_handler_.ProcessAttributeString(dwarf2reader::DW_AT_name, dwarf2reader::DW_FORM_strp, "compilation-unit-name"); + if (!compilation_dir_.empty()) + root_handler_.ProcessAttributeString(dwarf2reader::DW_AT_comp_dir, + dwarf2reader::DW_FORM_strp, + compilation_dir_); if (!lines_.empty()) root_handler_.ProcessAttributeUnsigned(dwarf2reader::DW_AT_stmt_list, dwarf2reader::DW_FORM_ref4, @@ -626,6 +636,13 @@ void CUFixtureBase::TestLine(int i, int j, class SimpleCU: public CUFixtureBase, public Test { }; +TEST_F(SimpleCU, CompilationDir) { + compilation_dir_ = "/src/build/"; + + StartCU(); + root_handler_.Finish(); +} + TEST_F(SimpleCU, OneFunc) { PushLine(0x938cf8c07def4d34ULL, 0x55592d727f6cd01fLL, "line-file", 246571772); @@ -1414,8 +1431,8 @@ TEST_F(Specifications, InterCU) { Module m("module-name", "module-os", "module-arch", "module-id"); DwarfCUToModule::FileContext fc("dwarf-filename", &m); EXPECT_CALL(reporter_, UncoveredFunction(_)).WillOnce(Return()); - MockLineToModuleFunctor lr; - EXPECT_CALL(lr, mock_apply(_,_,_,_)).Times(0); + MockLineToModuleHandler lr; + EXPECT_CALL(lr, ReadProgram(_,_,_,_)).Times(0); // Kludge: satisfy reporter_'s expectation. reporter_.SetCUName("compilation-unit-name"); -- cgit v1.2.1