aboutsummaryrefslogtreecommitdiff
path: root/gold/incremental-dump.cc
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <respindola@mozilla.com>2009-12-07 21:36:52 +0000
committerRafael Ávila de Espíndola <respindola@mozilla.com>2009-12-07 21:36:52 +0000
commit20b52f1af3b2af9c63bb1e11742f75da71802057 (patch)
treeab777a7bb1053f92546bbefa0f1ac0f582cd5773 /gold/incremental-dump.cc
parentd9b76ff95d9cc3471b46fdae062c5a1d302f5ee7 (diff)
downloadgdb-20b52f1af3b2af9c63bb1e11742f75da71802057.zip
gdb-20b52f1af3b2af9c63bb1e11742f75da71802057.tar.gz
gdb-20b52f1af3b2af9c63bb1e11742f75da71802057.tar.bz2
2009-12-07 Rafael Avila de Espindola <espindola@google.com>
PR gold/11055 * incremental-dump.cc (dump_incremental_inputs): New. (main): Use dump_incremental_inputs.
Diffstat (limited to 'gold/incremental-dump.cc')
-rw-r--r--gold/incremental-dump.cc160
1 files changed, 97 insertions, 63 deletions
diff --git a/gold/incremental-dump.cc b/gold/incremental-dump.cc
index 9e750cb..e174b99 100644
--- a/gold/incremental-dump.cc
+++ b/gold/incremental-dump.cc
@@ -42,72 +42,47 @@ namespace gold
using namespace gold;
-int
-main(int argc, char** argv)
+template<int size, bool big_endian>
+static void
+dump_incremental_inputs(const char* argv0,
+ const char* filename, Incremental_binary* inc)
{
- if (argc != 2)
- {
- fprintf(stderr, "Usage: %s <file>\n", argv[0]);
- return 1;
- }
- const char* filename = argv[1];
-
- Output_file* file = new Output_file(filename);
-
- bool t = file->open_for_modification();
- if (!t)
- {
- fprintf(stderr, "%s: open_for_modification(%s): %s\n", argv[0], filename,
- strerror(errno));
- return 1;
- }
-
- Incremental_binary* inc = open_incremental_binary(file);
-
- if (inc == NULL)
- {
- fprintf(stderr, "%s: open_incremental_binary(%s): %s\n", argv[0],
- filename, strerror(errno));
- return 1;
- }
-
+ bool t;
unsigned int strtab_shndx;
Incremental_binary::Location location;
t = inc->find_incremental_inputs_section(&location, &strtab_shndx);
if (!t)
{
- fprintf(stderr, "%s: %s: no .gnu_incremental_inputs section\n", argv[0],
+ fprintf(stderr, "%s: %s: no .gnu_incremental_inputs section\n", argv0,
filename);
- return 1;
+ exit (1);
}
Incremental_binary::View inputs_view(inc->view(location));
- const unsigned char *p = inputs_view.data();
+ const unsigned char* p = inputs_view.data();
- const Incremental_inputs_header_data* incremental_header =
- reinterpret_cast<const Incremental_inputs_header_data*> (p);
+ Incremental_inputs_header<size, big_endian> incremental_header(p);
- const Incremental_inputs_entry_data* incremental_inputs =
- reinterpret_cast<const Incremental_inputs_entry_data*>
+ const unsigned char* incremental_inputs_base =
(p + sizeof(Incremental_inputs_header_data));
- if (incremental_header->version != 1)
+ if (incremental_header.get_version() != 1)
{
- fprintf(stderr, "%s: %s: unknown incremental version %d\n", argv[0],
- filename, incremental_header->version);
- return 1;
+ fprintf(stderr, "%s: %s: unknown incremental version %d\n", argv0,
+ filename, incremental_header.get_version());
+ exit(1);
}
- elfcpp::Elf_file<64, false, Incremental_binary> elf_file(inc);
+ elfcpp::Elf_file<size, big_endian, Incremental_binary> elf_file(inc);
if (elf_file.section_type(strtab_shndx) != elfcpp::SHT_STRTAB)
{
fprintf(stderr,
"%s: %s: invalid string table section %u (type %d != %d)\n",
- argv[0], filename, strtab_shndx,
+ argv0, filename, strtab_shndx,
elf_file.section_type(strtab_shndx), elfcpp::SHT_STRTAB);
- return 1;
+ exit(1);
}
Incremental_binary::Location
@@ -118,42 +93,45 @@ main(int argc, char** argv)
elfcpp::Elf_strtab strtab(strtab_view.data(), strtab_location.data_size);
const char* command_line;
- t = strtab.get_c_string(incremental_header->command_line_offset,
- &command_line);
+ elfcpp::Elf_Word command_line_offset =
+ incremental_header.get_command_line_offset();
+ t = strtab.get_c_string(command_line_offset, &command_line);
if (!t)
{
fprintf(stderr,
"%s: %s: failed to get link command line: %zu out of range\n",
- argv[0], filename,
- static_cast<size_t>(incremental_header->command_line_offset));
- return 1;
+ argv0, filename,
+ static_cast<size_t>(command_line_offset));
+ exit(1);
}
printf("Link command line: %s\n", command_line);
printf("Input files:\n");
- for (unsigned i = 0; i < incremental_header->input_file_count; ++i)
+ for (unsigned i = 0; i < incremental_header.get_input_file_count(); ++i)
{
- const Incremental_inputs_entry_data* input =
- &incremental_inputs[i];
- const char *objname;
+ const unsigned char* input_p = incremental_inputs_base +
+ i * sizeof(Incremental_inputs_entry_data);
+ Incremental_inputs_entry<size, big_endian> input(input_p);
+ const char* objname;
- t = strtab.get_c_string(input->filename_offset, &objname);
+ t = strtab.get_c_string(input.get_filename_offset(), &objname);
if (!t)
{
fprintf(stderr,"%s: %s: failed to get file name for object %u:"
- " %zu out of range\n", argv[0], filename, i,
- static_cast<size_t>(input->filename_offset));
- return 1;
+ " %zu out of range\n", argv0, filename, i,
+ static_cast<size_t>(input.get_filename_offset()));
+ exit(1);
}
printf(" %s\n", objname);
printf(" Timestamp sec = %llu\n",
- static_cast<unsigned long long>(input->timestamp_sec));
- printf(" Timestamp nsec = %d\n", input->timestamp_nsec);
+ static_cast<unsigned long long>(input.get_timestamp_sec()));
+ printf(" Timestamp nsec = %d\n", input.get_timestamp_nsec());
printf(" Type = ");
// TODO: print the data at input->data_offset once we have it.
- switch (input->input_type)
+ elfcpp::Elf_Word input_type = input.get_input_type();
+ switch (input_type)
{
case INCREMENTAL_INPUT_OBJECT:
printf("Object\n");
@@ -166,20 +144,76 @@ main(int argc, char** argv)
break;
case INCREMENTAL_INPUT_SCRIPT:
printf("Linker script\n");
- if (input->data_offset != 0)
+ if (input.get_data_offset() != 0)
{
fprintf(stderr,"%s: %s: %u is a script but offset is not zero",
- argv[0], filename, i);
- return 1;
+ argv0, filename, i);
+ exit(1);
}
break;
case INCREMENTAL_INPUT_INVALID:
default:
fprintf(stderr, "%s: invalid file type for object %u: %d\n",
- argv[0], i, input->input_type);
- return 1;
+ argv0, i, input_type);
+ exit(1);
}
}
+}
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2)
+ {
+ fprintf(stderr, "Usage: %s <file>\n", argv[0]);
+ return 1;
+ }
+ const char* filename = argv[1];
+
+ Output_file* file = new Output_file(filename);
+
+ bool t = file->open_for_modification();
+ if (!t)
+ {
+ fprintf(stderr, "%s: open_for_modification(%s): %s\n", argv[0], filename,
+ strerror(errno));
+ return 1;
+ }
+
+ Incremental_binary* inc = open_incremental_binary(file);
+
+ if (inc == NULL)
+ {
+ fprintf(stderr, "%s: open_incremental_binary(%s): %s\n", argv[0],
+ filename, strerror(errno));
+ return 1;
+ }
+
+ switch (parameters->size_and_endianness())
+ {
+#ifdef HAVE_TARGET_32_LITTLE
+ case Parameters::TARGET_32_LITTLE:
+ dump_incremental_inputs<32, false>(argv[0], filename, inc);
+ break;
+#endif
+#ifdef HAVE_TARGET_32_BIG
+ case Parameters::TARGET_32_BIG:
+ dump_incremental_inputs<32, true>(argv[0], filename, inc);
+ break;
+#endif
+#ifdef HAVE_TARGET_64_LITTLE
+ case Parameters::TARGET_64_LITTLE:
+ dump_incremental_inputs<64, false>(argv[0], filename, inc);
+ break;
+#endif
+#ifdef HAVE_TARGET_64_BIG
+ case Parameters::TARGET_64_BIG:
+ dump_incremental_inputs<64, true>(argv[0], filename, inc);
+ break;
+#endif
+ default:
+ gold_unreachable();
+ }
return 0;
}