mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 01:07:52 +00:00
libsframe: refactor code for dumping section flags
To prepare code for accommodating new flag additions easily as the
format evolves.
libsframe/
* sframe-dump.c (SFRAME_HEADER_FLAGS_STR_MAX_LEN): Remove.
(dump_sframe_header_flags): .. to here. New definition.
(PRINT_FLAG): New definition.
(dump_sframe_header): Move some implementation from here ..
This commit is contained in:
@@ -23,8 +23,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "sframe-impl.h"
|
#include "sframe-impl.h"
|
||||||
|
|
||||||
#define SFRAME_HEADER_FLAGS_STR_MAX_LEN 50
|
|
||||||
|
|
||||||
/* Return TRUE if the SFrame section is associated with the aarch64 ABIs. */
|
/* Return TRUE if the SFrame section is associated with the aarch64 ABIs. */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -40,12 +38,40 @@ is_sframe_abi_arch_aarch64 (sframe_decoder_ctx *sfd_ctx)
|
|||||||
return aarch64_p;
|
return aarch64_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_sframe_header_flags (sframe_decoder_ctx *sfd_ctx)
|
||||||
|
{
|
||||||
|
uint8_t flags;
|
||||||
|
const char *prefix = "Flags: ";
|
||||||
|
|
||||||
|
flags = sframe_decoder_get_flags (sfd_ctx);
|
||||||
|
if (!flags)
|
||||||
|
{
|
||||||
|
printf ("%11sNONE\n", prefix);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PRINT_FLAG(x) \
|
||||||
|
if (flags & (x)) \
|
||||||
|
{ flags = (flags & ~(x)); \
|
||||||
|
printf ("%11s%s%s\n", prefix, #x, flags ? "," : ""); \
|
||||||
|
prefix = " "; \
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINT_FLAG (SFRAME_F_FDE_SORTED);
|
||||||
|
PRINT_FLAG (SFRAME_F_FRAME_POINTER);
|
||||||
|
#undef PRINT_FLAG
|
||||||
|
|
||||||
|
/* Print any residual flags, should this implementation be out of sync when
|
||||||
|
new flags are added. */
|
||||||
|
if (flags)
|
||||||
|
printf ("%11s%d\n", prefix, flags);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
|
dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
|
||||||
{
|
{
|
||||||
uint8_t ver;
|
uint8_t ver;
|
||||||
uint8_t flags;
|
|
||||||
char *flags_str;
|
|
||||||
const char *ver_str = NULL;
|
const char *ver_str = NULL;
|
||||||
int8_t cfa_fixed_fp_offset;
|
int8_t cfa_fixed_fp_offset;
|
||||||
int8_t cfa_fixed_ra_offset;
|
int8_t cfa_fixed_ra_offset;
|
||||||
@@ -57,33 +83,10 @@ dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
|
|||||||
"SFRAME_VERSION_1",
|
"SFRAME_VERSION_1",
|
||||||
"SFRAME_VERSION_2" };
|
"SFRAME_VERSION_2" };
|
||||||
|
|
||||||
/* PS: Keep SFRAME_HEADER_FLAGS_STR_MAX_LEN in sync if adding more members to
|
|
||||||
this array. */
|
|
||||||
const char *flag_names[]
|
|
||||||
= { "SFRAME_F_FDE_SORTED",
|
|
||||||
"SFRAME_F_FRAME_POINTER" };
|
|
||||||
|
|
||||||
ver = sframe_decoder_get_version (sfd_ctx);
|
ver = sframe_decoder_get_version (sfd_ctx);
|
||||||
if (ver <= SFRAME_VERSION)
|
if (ver <= SFRAME_VERSION)
|
||||||
ver_str = version_names[ver];
|
ver_str = version_names[ver];
|
||||||
|
|
||||||
/* Prepare SFrame section flags string. */
|
|
||||||
flags = header->sfh_preamble.sfp_flags;
|
|
||||||
flags_str = (char*) calloc (SFRAME_HEADER_FLAGS_STR_MAX_LEN, sizeof (char));
|
|
||||||
if (flags)
|
|
||||||
{
|
|
||||||
if (flags & SFRAME_F_FDE_SORTED)
|
|
||||||
strcpy (flags_str, flag_names[0]);
|
|
||||||
if (flags & SFRAME_F_FRAME_POINTER)
|
|
||||||
{
|
|
||||||
if (strlen (flags_str) > 0)
|
|
||||||
strcpy (flags_str, ",");
|
|
||||||
strcpy (flags_str, flag_names[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy (flags_str, "NONE");
|
|
||||||
|
|
||||||
/* CFA fixed FP and RA offsets. */
|
/* CFA fixed FP and RA offsets. */
|
||||||
cfa_fixed_fp_offset = header->sfh_cfa_fixed_fp_offset;
|
cfa_fixed_fp_offset = header->sfh_cfa_fixed_fp_offset;
|
||||||
cfa_fixed_ra_offset = header->sfh_cfa_fixed_ra_offset;
|
cfa_fixed_ra_offset = header->sfh_cfa_fixed_ra_offset;
|
||||||
@@ -93,15 +96,15 @@ dump_sframe_header (sframe_decoder_ctx *sfd_ctx)
|
|||||||
printf (" %s :\n", subsec_name);
|
printf (" %s :\n", subsec_name);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
printf (" Version: %s\n", ver_str);
|
printf (" Version: %s\n", ver_str);
|
||||||
printf (" Flags: %s\n", flags_str);
|
|
||||||
|
dump_sframe_header_flags (sfd_ctx);
|
||||||
|
|
||||||
if (cfa_fixed_fp_offset != SFRAME_CFA_FIXED_FP_INVALID)
|
if (cfa_fixed_fp_offset != SFRAME_CFA_FIXED_FP_INVALID)
|
||||||
printf (" CFA fixed FP offset: %d\n", cfa_fixed_fp_offset);
|
printf (" CFA fixed FP offset: %d\n", cfa_fixed_fp_offset);
|
||||||
if (cfa_fixed_ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
|
if (cfa_fixed_ra_offset != SFRAME_CFA_FIXED_RA_INVALID)
|
||||||
printf (" CFA fixed RA offset: %d\n", cfa_fixed_ra_offset);
|
printf (" CFA fixed RA offset: %d\n", cfa_fixed_ra_offset);
|
||||||
printf (" Num FDEs: %d\n", sframe_decoder_get_num_fidx (sfd_ctx));
|
printf (" Num FDEs: %d\n", sframe_decoder_get_num_fidx (sfd_ctx));
|
||||||
printf (" Num FREs: %d\n", header->sfh_num_fres);
|
printf (" Num FREs: %d\n", header->sfh_num_fres);
|
||||||
|
|
||||||
free (flags_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user