summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2011-05-03 11:45:27 +0200
committerMark Wielaard <[email protected]>2011-05-03 11:45:27 +0200
commite88df500789902ffa14dbaefc9bc1daad7e6dc05 (patch)
treed1eadb45274d6260d5ef87382e7c61f4fdb70f23 /src
parent54e3eae4dc7ff5276b709f21785a30abea4a9d1a (diff)
parentbcdb09dcb97d00a1718507f64302f57f92558af0 (diff)
Merge branch 'master' into dwarf
Conflicts: tests/Makefile.am: New tests merged.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog22
-rw-r--r--src/arlib.c2
-rw-r--r--src/elf32-i386.script2
-rw-r--r--src/ld.c2
-rw-r--r--src/ldgeneric.c5
-rw-r--r--src/readelf.c239
6 files changed, 250 insertions, 22 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e2796595..a71eea82 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,25 @@
+2011-04-26 Mark Wielaard <[email protected]>
+
+ * readelf.c (handle_notes_data): Call ebl_object_note_type_name
+ with note name.
+
+2011-04-14 Mark Wielaard <[email protected]>
+
+ * readelf.c (options): Add gdb_index.
+ (section_e): Define section_gdb_index.
+ (parse_opt): Recognize gdb_index debug-dump argument.
+ (print_gdb_index_section): New function.
+ (print_debug): Add gdb_index to debug_sections.
+
+2011-03-24 Petr Machata <[email protected]>
+
+ * readelf.c (print_debug_line_section): Emit initial space for all
+ opcode lines. Print offset in front of each opcode.
+
+2011-03-22 Marek Polacek <[email protected]>
+
+ * readelf.c (handle_dynamic): Don't segfault at DT_PLTREL case.
+
2011-03-22 Mark Wielaard <[email protected]>
* readelf.c (dwarf_tag_string): Support DW_TAG_GNU_call_site
diff --git a/src/arlib.c b/src/arlib.c
index af98454c..c69a138f 100644
--- a/src/arlib.c
+++ b/src/arlib.c
@@ -61,7 +61,7 @@ arlib_init (void)
/* Using snprintf here has a problem: the call always wants to add a
NUL byte. We could use a trick whereby we specify the target
buffer size longer than it is and this would not actually fail,
- since all the fields are consecutive and we fill them in in
+ since all the fields are consecutive and we fill them in
sequence (i.e., the NUL byte gets overwritten). But
_FORTIFY_SOURCE=2 would not let us play these games. Therefore
we play it safe. */
diff --git a/src/elf32-i386.script b/src/elf32-i386.script
index a6cfffa1..2083278f 100644
--- a/src/elf32-i386.script
+++ b/src/elf32-i386.script
@@ -120,7 +120,7 @@ SEGMENT [RW]
is in. */
KEEP (*crtbegin.o(.ctors))
/* We don't want to include the .ctor section from
- from the crtend.o file until after the sorted ctors.
+ the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
diff --git a/src/ld.c b/src/ld.c
index 932496e1..a3b09349 100644
--- a/src/ld.c
+++ b/src/ld.c
@@ -1465,7 +1465,7 @@ static void
create_lscript_symbols (void)
{
/* Walk through the data from the linker script and generate all the
- symbols which are required to be present and and those marked
+ symbols which are required to be present and those marked
with PROVIDE if there is a undefined reference. */
if (ld_state.output_segments == NULL)
return;
diff --git a/src/ldgeneric.c b/src/ldgeneric.c
index d51b54fe..98bdc225 100644
--- a/src/ldgeneric.c
+++ b/src/ldgeneric.c
@@ -5854,9 +5854,8 @@ section index too large in dynamic symbol table"));
- the symbol is for a file
- it is not externally visible (internal, hidden)
- - if export_all_dynamic is not set and is only defined in
- the executable (i.e., it is defined, but not (also) in
- in DSO)
+ - export_all_dynamic is not set and the symbol is only defined
+ in the executable (i.e., it is defined, but not (also) in DSO)
Set symstrent[cnt] to NULL in case an entry is ignored. */
if (XELF_ST_TYPE (sym->st_info) == STT_FILE
diff --git a/src/readelf.c b/src/readelf.c
index d4442756..43dc5d92 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -94,8 +94,8 @@ static const struct argp_option options[] =
{ NULL, 0, NULL, 0, N_("Additional output selection:"), 0 },
{ "debug-dump", 'w', "SECTION", OPTION_ARG_OPTIONAL,
N_("Display DWARF section content. SECTION can be one of abbrev, "
- "aranges, frame, info, loc, line, ranges, pubnames, str, macinfo, "
- "or exception"), 0 },
+ "aranges, frame, gdb_index, info, loc, line, ranges, pubnames, str, "
+ "macinfo, or exception"), 0 },
{ "hex-dump", 'x', "SECTION", 0,
N_("Dump the uninterpreted contents of SECTION, by number or name"), 0 },
{ "strings", 'p', "SECTION", OPTION_ARG_OPTIONAL,
@@ -190,10 +190,11 @@ static enum section_e
section_macinfo = 256, /* .debug_macinfo */
section_ranges = 512, /* .debug_ranges */
section_exception = 1024, /* .eh_frame & al. */
+ section_gdb_index = 2048, /* .gdb_index */
section_all = (section_abbrev | section_aranges | section_frame
| section_info | section_line | section_loc
| section_pubnames | section_str | section_macinfo
- | section_ranges | section_exception)
+ | section_ranges | section_exception | section_gdb_index)
} print_debug_sections, implicit_debug_sections;
/* Select hex dumping of sections. */
@@ -404,6 +405,8 @@ parse_opt (int key, char *arg,
print_debug_sections |= section_macinfo;
else if (strcmp (arg, "exception") == 0)
print_debug_sections |= section_exception;
+ else if (strcmp (arg, "gdb_index") == 0)
+ print_debug_sections |= section_gdb_index;
else
{
fprintf (stderr, gettext ("Unknown DWARF debug section `%s'.\n"),
@@ -1446,8 +1449,10 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
printf ("%" PRId64 "\n", dyn->d_un.d_val);
break;
- case DT_PLTREL:
- puts (ebl_dynamic_tag_name (ebl, dyn->d_un.d_val, NULL, 0));
+ case DT_PLTREL:;
+ const char *tagname = ebl_dynamic_tag_name (ebl, dyn->d_un.d_val,
+ NULL, 0);
+ puts (tagname ?: "???");
break;
case DT_FLAGS:
@@ -5440,12 +5445,14 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
while (linep < lineendp)
{
+ size_t offset = linep - (const unsigned char *) data->d_buf;
unsigned int u128;
int s128;
/* Read the opcode. */
unsigned int opcode = *linep++;
+ printf (" [%6" PRIx64 "]", (uint64_t)offset);
/* Is this a special opcode? */
if (likely (opcode >= opcode_base))
{
@@ -5494,7 +5501,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
switch (opcode)
{
case DW_LNE_end_sequence:
- puts (gettext ("end of sequence"));
+ puts (gettext (" end of sequence"));
/* Reset the registers we care about. */
address = 0;
@@ -5511,7 +5518,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
address = read_8ubyte_unaligned_inc (dbg, linep);
{
char *a = format_dwarf_addr (dwflmod, 0, address);
- printf (gettext ("set address to %s\n"), a);
+ printf (gettext (" set address to %s\n"), a);
free (a);
}
break;
@@ -5533,7 +5540,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
get_uleb128 (filelength, linep);
printf (gettext ("\
-define new file: dir=%u, mtime=%" PRIu64 ", length=%" PRIu64 ", name=%s\n"),
+ define new file: dir=%u, mtime=%" PRIu64 ", length=%" PRIu64 ", name=%s\n"),
diridx, (uint64_t) mtime, (uint64_t) filelength,
fname);
}
@@ -5550,7 +5557,7 @@ define new file: dir=%u, mtime=%" PRIu64 ", length=%" PRIu64 ", name=%s\n"),
default:
/* Unknown, ignore it. */
- puts (gettext ("unknown opcode"));
+ puts (gettext (" unknown opcode"));
linep += len - 1;
break;
}
@@ -5574,10 +5581,10 @@ define new file: dir=%u, mtime=%" PRIu64 ", length=%" PRIu64 ", name=%s\n"),
char *a = format_dwarf_addr (dwflmod, 0, address);
if (show_op_index)
printf (gettext ("\
-advance address by %u to %s, op_index to %u\n"),
+ advance address by %u to %s, op_index to %u\n"),
op_addr_advance, a, op_index);
else
- printf (gettext ("advance address by %u to %s\n"),
+ printf (gettext (" advance address by %u to %s\n"),
op_addr_advance, a);
free (a);
}
@@ -5629,11 +5636,11 @@ advance address by %u to %s, op_index to %u\n"),
char *a = format_dwarf_addr (dwflmod, 0, address);
if (show_op_index)
printf (gettext ("\
-advance address by constant %u to %s, op_index to %u\n"),
+ advance address by constant %u to %s, op_index to %u\n"),
op_addr_advance, a, op_index);
else
printf (gettext ("\
-advance address by constant %u to %s\n"),
+ advance address by constant %u to %s\n"),
op_addr_advance, a);
free (a);
}
@@ -5651,7 +5658,7 @@ advance address by constant %u to %s\n"),
{
char *a = format_dwarf_addr (dwflmod, 0, address);
printf (gettext ("\
-advance address by fixed value %u to %s\n"),
+ advance address by fixed value %u to %s\n"),
u128, a);
free (a);
}
@@ -6318,6 +6325,205 @@ print_debug_exception_table (Dwfl_Module *dwflmod __attribute__ ((unused)),
}
}
+/* Print the content of the '.gdb_index' section.
+ http://sourceware.org/gdb/current/onlinedocs/gdb/Index-Section-Format.html
+*/
+static void
+print_gdb_index_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
+ Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
+{
+ printf (gettext ("\nGDB section [%2zu] '%s' at offset %#" PRIx64
+ " contains %" PRId64 " bytes :\n"),
+ elf_ndxscn (scn), section_name (ebl, ehdr, shdr),
+ (uint64_t) shdr->sh_offset, (uint64_t) shdr->sh_size);
+
+ Elf_Data *data = elf_rawdata (scn, NULL);
+
+ if (unlikely (data == NULL))
+ {
+ error (0, 0, gettext ("cannot get %s content: %s"),
+ ".gdb_index", elf_errmsg (-1));
+ return;
+ }
+
+ // .gdb_index is always in little endian.
+ Dwarf dummy_dbg = { .other_byte_order = MY_ELFDATA != ELFDATA2LSB };
+ dbg = &dummy_dbg;
+
+ const unsigned char *readp = data->d_buf;
+ const unsigned char *const dataend = readp + data->d_size;
+
+ if (unlikely (readp + 4 > dataend))
+ {
+ invalid_data:
+ error (0, 0, gettext ("invalid data"));
+ return;
+ }
+
+ int32_t vers = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" Version: %" PRId32 "\n"), vers);
+
+ // The only difference between version 4 and version 5 is the
+ // hash used for generating the table.
+ if (vers < 4 || vers > 5)
+ {
+ printf (gettext (" unknown version, cannot parse section\n"));
+ return;
+ }
+
+ readp += 4;
+ if (unlikely (readp + 4 > dataend))
+ goto invalid_data;
+
+ uint32_t cu_off = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" CU offset: %#" PRIx32 "\n"), cu_off);
+
+ readp += 4;
+ if (unlikely (readp + 4 > dataend))
+ goto invalid_data;
+
+ uint32_t tu_off = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" TU offset: %#" PRIx32 "\n"), tu_off);
+
+ readp += 4;
+ if (unlikely (readp + 4 > dataend))
+ goto invalid_data;
+
+ uint32_t addr_off = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" address offset: %#" PRIx32 "\n"), addr_off);
+
+ readp += 4;
+ if (unlikely (readp + 4 > dataend))
+ goto invalid_data;
+
+ uint32_t sym_off = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" symbol offset: %#" PRIx32 "\n"), sym_off);
+
+ readp += 4;
+ if (unlikely (readp + 4 > dataend))
+ goto invalid_data;
+
+ uint32_t const_off = read_4ubyte_unaligned (dbg, readp);
+ printf (gettext (" constant offset: %#" PRIx32 "\n"), const_off);
+
+ readp = data->d_buf + cu_off;
+
+ const unsigned char *nextp = data->d_buf + tu_off;
+ size_t nr = (nextp - readp) / 16;
+
+ printf (gettext ("\n CU list at offset %#" PRIx32
+ " contains %zu entries:\n"),
+ cu_off, nr);
+
+ size_t n = 0;
+ while (readp + 16 <= dataend && n < nr)
+ {
+ uint64_t off = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ uint64_t len = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ printf (" [%4zu] start: %0#8" PRIx64
+ ", length: %5" PRIu64 "\n", n, off, len);
+ n++;
+ }
+
+ readp = data->d_buf + tu_off;
+ nextp = data->d_buf + addr_off;
+ nr = (nextp - readp) / 24;
+
+ printf (gettext ("\n TU list at offset %#" PRIx32
+ " contains %zu entries:\n"),
+ tu_off, nr);
+
+ n = 0;
+ while (readp + 24 <= dataend && n < nr)
+ {
+ uint64_t off = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ uint64_t type = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ uint64_t sig = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ printf (" [%4zu] CU offset: %5" PRId64
+ ", type offset: %5" PRId64
+ ", signature: %0#8" PRIx64 "\n", n, off, type, sig);
+ n++;
+ }
+
+ readp = data->d_buf + addr_off;
+ nextp = data->d_buf + sym_off;
+ nr = (nextp - readp) / 20;
+
+ printf (gettext ("\n Address list at offset %#" PRIx32
+ " contains %zu entries:\n"),
+ addr_off, nr);
+
+ n = 0;
+ while (readp + 20 <= dataend && n < nr)
+ {
+ uint64_t low = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ uint64_t high = read_8ubyte_unaligned (dbg, readp);
+ readp += 8;
+
+ uint32_t idx = read_4ubyte_unaligned (dbg, readp);
+ readp += 4;
+
+ char *l = format_dwarf_addr (dwflmod, 8, low);
+ char *h = format_dwarf_addr (dwflmod, 8, high - 1);
+ printf (" [%4zu] %s..%s, CU index: %5" PRId32 "\n",
+ n, l, h, idx);
+ n++;
+ }
+
+ readp = data->d_buf + sym_off;
+ nextp = data->d_buf + const_off;
+ nr = (nextp - readp) / 8;
+
+ printf (gettext ("\n Symbol table at offset %#" PRIx32
+ " contains %zu slots:\n"),
+ addr_off, nr);
+
+ n = 0;
+ while (readp + 8 <= dataend && n < nr)
+ {
+ uint32_t name = read_4ubyte_unaligned (dbg, readp);
+ readp += 4;
+
+ uint32_t vector = read_4ubyte_unaligned (dbg, readp);
+ readp += 4;
+
+ if (name != 0 || vector != 0)
+ {
+ const unsigned char *sym = data->d_buf + const_off + name;
+ if (unlikely (sym > dataend))
+ goto invalid_data;
+
+ printf (" [%4zu] symbol: %s, CUs: ", n, sym);
+
+ const unsigned char *readcus = data->d_buf + const_off + vector;
+ if (unlikely (readcus + 8 > dataend))
+ goto invalid_data;
+
+ uint32_t cus = read_4ubyte_unaligned (dbg, readcus);
+ while (cus--)
+ {
+ uint32_t cu;
+ readcus += 4;
+ cu = read_4ubyte_unaligned (dbg, readcus);
+ printf ("%" PRId32 "%s", cu, ((cus > 0) ? ", " : ""));
+ }
+ printf ("\n");
+ }
+ n++;
+ }
+}
static void
print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
@@ -6377,7 +6583,8 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
{ ".eh_frame_hdr", section_frame | section_exception,
print_debug_frame_hdr_section },
{ ".gcc_except_table", section_frame | section_exception,
- print_debug_exception_table }
+ print_debug_exception_table },
+ { ".gdb_index", section_gdb_index, print_gdb_index_section }
};
const int ndebug_sections = (sizeof (debug_sections)
/ sizeof (debug_sections[0]));
@@ -7200,7 +7407,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
ehdr->e_type == ET_CORE
? ebl_core_note_type_name (ebl, nhdr.n_type,
buf, sizeof (buf))
- : ebl_object_note_type_name (ebl, nhdr.n_type,
+ : ebl_object_note_type_name (ebl, name, nhdr.n_type,
buf2, sizeof (buf2)));
/* Filter out invalid entries. */