summaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorIndu Bhagat <indu.bhagat@oracle.com>2022-11-15 15:07:09 -0800
committerIndu Bhagat <indu.bhagat@oracle.com>2022-11-15 15:50:05 -0800
commit42b6953bbad652d3f7cba405c941ad9c6eab26b0 (patch)
tree7f1276452e23a847be0105dba5bf563b1f8e3457 /binutils/readelf.c
parentcf0e0a0ba91664b680dff1e310f24dbe6447bd4c (diff)
readelf/objdump: support for SFrame section
This patch adds support for SFrame in readelf and objdump. The arguments of --sframe are optional for both readelf and objdump. include/ChangeLog: * sframe-api.h (dump_sframe): New function declaration. ChangeLog: * binutils/Makefile.am: Add dependency on libsframe for readelf and objdump. * binutils/Makefile.in: Regenerate. * binutils/doc/binutils.texi: Document --sframe=[section]. * binutils/doc/sframe.options.texi: New file. * binutils/objdump.c: Add support for SFrame format. * binutils/readelf.c: Likewise. * include/sframe-api.h: Add new API for dumping .sframe section. * libsframe/Makefile.am: Add sframe-dump.c. * libsframe/Makefile.in: Regenerate. * libsframe/sframe-dump.c: New file.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index f82c3a973f2..6b2cbbcbb1b 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -63,6 +63,7 @@
#include "demanguse.h"
#include "dwarf.h"
#include "ctf-api.h"
+#include "sframe-api.h"
#include "demangle.h"
#include "elf/common.h"
@@ -190,6 +191,7 @@ typedef struct elf_section_list
#define STRING_DUMP (1 << 3) /* The -p command line switch. */
#define RELOC_DUMP (1 << 4) /* The -R command line switch. */
#define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
+#define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */
typedef unsigned char dump_type;
@@ -233,6 +235,7 @@ static bool do_version = false;
static bool do_histogram = false;
static bool do_debugging = false;
static bool do_ctf = false;
+static bool do_sframe = false;
static bool do_arch = false;
static bool do_notes = false;
static bool do_archive_index = false;
@@ -5071,6 +5074,7 @@ enum long_option_values
OPTION_CTF_PARENT,
OPTION_CTF_SYMBOLS,
OPTION_CTF_STRINGS,
+ OPTION_SFRAME_DUMP,
OPTION_WITH_SYMBOL_VERSIONS,
OPTION_RECURSE_LIMIT,
OPTION_NO_RECURSE_LIMIT,
@@ -5133,6 +5137,7 @@ static struct option options[] =
{"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
{"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
#endif
+ {"sframe", optional_argument, 0, OPTION_SFRAME_DUMP},
{"sym-base", optional_argument, 0, OPTION_SYM_BASE},
{0, no_argument, 0, 0}
@@ -5273,6 +5278,8 @@ usage (FILE * stream)
--ctf-strings=<number|name>\n\
Use section <number|name> as the CTF external strtab\n"));
#endif
+ fprintf (stream, _("\
+ --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n"));
#ifdef SUPPORT_DISASSEMBLY
fprintf (stream, _("\
@@ -5546,6 +5553,19 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
free (dump_ctf_parent_name);
dump_ctf_parent_name = strdup (optarg);
break;
+ case OPTION_SFRAME_DUMP:
+ do_sframe = true;
+ /* Providing section name is optional. request_dump (), however,
+ thrives on non NULL optarg. Handle it explicitly here. */
+ if (optarg != NULL)
+ request_dump (dumpdata, SFRAME_DUMP);
+ else
+ {
+ do_dump = true;
+ const char *sframe_sec_name = strdup (".sframe");
+ request_dump_byname (sframe_sec_name, SFRAME_DUMP);
+ }
+ break;
case OPTION_DYN_SYMS:
do_dyn_syms = true;
break;
@@ -15860,6 +15880,44 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
#endif
static bool
+dump_section_as_sframe (Elf_Internal_Shdr * section, Filedata * filedata)
+{
+ void * data = NULL;
+ sframe_decoder_ctx *sfd_ctx = NULL;
+ const char *print_name = printable_section_name (filedata, section);
+
+ bool ret = true;
+ size_t sf_size;
+ int err = 0;
+
+ if (strcmp (print_name, "") == 0)
+ {
+ error (_("Section name must be provided \n"));
+ ret = false;
+ return ret;
+ }
+
+ data = get_section_contents (section, filedata);
+ sf_size = section->sh_size;
+ /* Decode the contents of the section. */
+ sfd_ctx = sframe_decode ((const char*)data, sf_size, &err);
+ if (!sfd_ctx)
+ {
+ ret = false;
+ error (_("SFrame decode failure: %s\n"), sframe_errmsg (err));
+ goto fail;
+ }
+
+ printf (_("Contents of the SFrame section %s:"), print_name);
+ /* Dump the contents as text. */
+ dump_sframe (sfd_ctx, section->sh_addr);
+
+ fail:
+ free (data);
+ return ret;
+}
+
+static bool
load_specific_debug_section (enum dwarf_section_display_enum debug,
const Elf_Internal_Shdr * sec,
void * data)
@@ -16365,6 +16423,11 @@ process_section_contents (Filedata * filedata)
res = false;
}
#endif
+ if (dump & SFRAME_DUMP)
+ {
+ if (! dump_section_as_sframe (section, filedata))
+ res = false;
+ }
}
if (! filedata->is_separate)