summaryrefslogtreecommitdiff
path: root/compiler/dwarf/dwarf_test.h
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2015-10-26 10:57:09 +0000
committer David Srbecky <dsrbecky@google.com> 2015-11-08 20:17:13 +0000
commit6d8c8f0344a706df651567387ede683ab3ec1b5f (patch)
tree2c2fe153db3dd59de6b175b040d1209e2e76728e /compiler/dwarf/dwarf_test.h
parent2264f624e41acf09b17c3961bd52966e43f2b58f (diff)
Rewrite ElfBuilder to make streaming directly to file easier.
The previous design required knowing all the sections and their sizes before even the first byte of the file was written. The new design allows sections to be written one by one without any knowledge of later sections. Furthermore, as soon as section is started, its virtual memory address is known, which removes the need for the various patching passes. The new ElfBuilder essentially tries to be a thin wrapper around OutputStream which keeps track where the various sections start/end and then writes their ELF headers. Change-Id: I817e7f3b41882e4e4b9b442cfe56e4ef2e26babd
Diffstat (limited to 'compiler/dwarf/dwarf_test.h')
-rw-r--r--compiler/dwarf/dwarf_test.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/compiler/dwarf/dwarf_test.h b/compiler/dwarf/dwarf_test.h
index f819c49cee..5464ed9c49 100644
--- a/compiler/dwarf/dwarf_test.h
+++ b/compiler/dwarf/dwarf_test.h
@@ -59,38 +59,27 @@ class DwarfTest : public CommonRuntimeTest {
std::vector<std::string> Objdump(const char* args) {
// Write simple elf file with just the DWARF sections.
InstructionSet isa = (sizeof(typename ElfTypes::Addr) == 8) ? kX86_64 : kX86;
- class NoCode : public CodeOutput {
- bool Write(OutputStream*) OVERRIDE { return true; } // NOLINT
- } no_code;
- ElfBuilder<ElfTypes> builder(isa, 0, &no_code, 0, &no_code, 0);
- typedef typename ElfBuilder<ElfTypes>::RawSection RawSection;
- RawSection debug_info(".debug_info", SHT_PROGBITS, 0, nullptr, 0, 1, 0);
- RawSection debug_abbrev(".debug_abbrev", SHT_PROGBITS, 0, nullptr, 0, 1, 0);
- RawSection debug_str(".debug_str", SHT_PROGBITS, 0, nullptr, 0, 1, 0);
- RawSection debug_line(".debug_line", SHT_PROGBITS, 0, nullptr, 0, 1, 0);
- RawSection debug_frame(".debug_frame", SHT_PROGBITS, 0, nullptr, 0, 8, 0);
+ ScratchFile file;
+ FileOutputStream output_stream(file.GetFile());
+ ElfBuilder<ElfTypes> builder(isa, &output_stream);
+ builder.Start();
if (!debug_info_data_.empty()) {
- debug_info.SetBuffer(debug_info_data_);
- builder.RegisterSection(&debug_info);
+ builder.WriteSection(".debug_info", &debug_info_data_);
}
if (!debug_abbrev_data_.empty()) {
- debug_abbrev.SetBuffer(debug_abbrev_data_);
- builder.RegisterSection(&debug_abbrev);
+ builder.WriteSection(".debug_abbrev", &debug_abbrev_data_);
}
if (!debug_str_data_.empty()) {
- debug_str.SetBuffer(debug_str_data_);
- builder.RegisterSection(&debug_str);
+ builder.WriteSection(".debug_str", &debug_str_data_);
}
if (!debug_line_data_.empty()) {
- debug_line.SetBuffer(debug_line_data_);
- builder.RegisterSection(&debug_line);
+ builder.WriteSection(".debug_line", &debug_line_data_);
}
if (!debug_frame_data_.empty()) {
- debug_frame.SetBuffer(debug_frame_data_);
- builder.RegisterSection(&debug_frame);
+ builder.WriteSection(".debug_frame", &debug_frame_data_);
}
- ScratchFile file;
- builder.Write(file.GetFile());
+ builder.End();
+ EXPECT_TRUE(builder.Good());
// Read the elf file back using objdump.
std::vector<std::string> lines;