* [PATCH 2/5] readelf: Pull same_set() info file scope
2021-01-08 8:16 Remove nested functions from readelf.c tbaeder
2021-01-08 8:16 ` [PATCH 1/5] readelf: Pull add_dump_section() into file scope tbaeder
@ 2021-01-08 8:16 ` tbaeder
2021-01-30 20:14 ` Mark Wielaard
2021-01-08 8:16 ` [PATCH 3/5] readelf: Pull left() " tbaeder
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: tbaeder @ 2021-01-08 8:16 UTC (permalink / raw)
To: elfutils-devel
From: Timm Bäder <tbaeder@redhat.com>
Get rid of a nested function this way
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
src/readelf.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index a95fc0aa..0157f8a2 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12072,6 +12072,18 @@ compare_register_sets (const void *a, const void *b)
return compare_sets_by_info (*p1, *p2);
}
+static inline bool
+same_set (const struct register_info *a,
+ const struct register_info *b,
+ const struct register_info *regs,
+ size_t maxnreg)
+{
+ return (a < ®s[maxnreg] && a->regloc != NULL
+ && b < ®s[maxnreg] && b->regloc != NULL
+ && a->bits == b->bits
+ && (a->set == b->set || !strcmp (a->set, b->set)));
+}
+
static unsigned int
handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
const Ebl_Register_Location *reglocs, size_t nregloc)
@@ -12110,19 +12122,11 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
qsort (regs, maxreg + 1, sizeof regs[0], &compare_registers);
/* Collect the unique sets and sort them. */
- inline bool same_set (const struct register_info *a,
- const struct register_info *b)
- {
- return (a < ®s[maxnreg] && a->regloc != NULL
- && b < ®s[maxnreg] && b->regloc != NULL
- && a->bits == b->bits
- && (a->set == b->set || !strcmp (a->set, b->set)));
- }
struct register_info *sets[maxreg + 1];
sets[0] = ®s[0];
size_t nsets = 1;
for (int i = 1; i <= maxreg; ++i)
- if (regs[i].regloc != NULL && !same_set (®s[i], ®s[i - 1]))
+ if (regs[i].regloc != NULL && !same_set (®s[i], ®s[i - 1], regs, maxnreg))
sets[nsets++] = ®s[i];
qsort (sets, nsets, sizeof sets[0], &compare_register_sets);
@@ -12133,7 +12137,7 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc,
/* Find the longest name of a register in this set. */
size_t maxname = 0;
const struct register_info *end;
- for (end = sets[i]; same_set (sets[i], end); ++end)
+ for (end = sets[i]; same_set (sets[i], end, regs, maxnreg); ++end)
{
size_t len = strlen (end->name);
if (len > maxname)
--
2.26.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/5] readelf: Pull regname() into file scope
2021-01-08 8:16 Remove nested functions from readelf.c tbaeder
` (2 preceding siblings ...)
2021-01-08 8:16 ` [PATCH 3/5] readelf: Pull left() " tbaeder
@ 2021-01-08 8:16 ` tbaeder
2021-01-30 20:47 ` Mark Wielaard
2021-01-08 8:16 ` [PATCH 5/5] readelf: Pull advance_pc() " tbaeder
2021-02-01 14:21 ` Remove nested functions from readelf.c Mark Wielaard
5 siblings, 1 reply; 12+ messages in thread
From: tbaeder @ 2021-01-08 8:16 UTC (permalink / raw)
To: elfutils-devel
From: Timm Bäder <tbaeder@redhat.com>
Get rid of a nested function this way.
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
src/readelf.c | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index 99e90c34..e0163891 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6206,6 +6206,13 @@ read_encoded (unsigned int encoding, const unsigned char *readp,
return readp;
}
+static const char *
+regname (Ebl *ebl, unsigned int regno, char *regnamebuf)
+{
+ register_info (ebl, regno, NULL, regnamebuf, NULL, NULL);
+
+ return regnamebuf;
+}
static void
print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
@@ -6216,11 +6223,6 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr, Dwarf *dbg)
{
char regnamebuf[REGNAMESZ];
- const char *regname (unsigned int regno)
- {
- register_info (ebl, regno, NULL, regnamebuf, NULL, NULL);
- return regnamebuf;
- }
puts ("\n Program:");
Dwarf_Word pc = vma_base;
@@ -6277,26 +6279,28 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
get_uleb128 (op2, readp, endp);
printf (" offset_extended r%" PRIu64 " (%s) at cfa%+" PRId64
"\n",
- op1, regname (op1), op2 * data_align);
+ op1, regname (ebl, op1, regnamebuf), op2 * data_align);
break;
case DW_CFA_restore_extended:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
get_uleb128 (op1, readp, endp);
printf (" restore_extended r%" PRIu64 " (%s)\n",
- op1, regname (op1));
+ op1, regname (ebl, op1, regnamebuf));
break;
case DW_CFA_undefined:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
get_uleb128 (op1, readp, endp);
- printf (" undefined r%" PRIu64 " (%s)\n", op1, regname (op1));
+ printf (" undefined r%" PRIu64 " (%s)\n", op1,
+ regname (ebl, op1, regnamebuf));
break;
case DW_CFA_same_value:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
get_uleb128 (op1, readp, endp);
- printf (" same_value r%" PRIu64 " (%s)\n", op1, regname (op1));
+ printf (" same_value r%" PRIu64 " (%s)\n", op1,
+ regname (ebl, op1, regnamebuf));
break;
case DW_CFA_register:
if ((uint64_t) (endp - readp) < 1)
@@ -6306,7 +6310,8 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_uleb128 (op2, readp, endp);
printf (" register r%" PRIu64 " (%s) in r%" PRIu64 " (%s)\n",
- op1, regname (op1), op2, regname (op2));
+ op1, regname (ebl, op1, regnamebuf), op2,
+ regname (ebl, op2, regnamebuf));
break;
case DW_CFA_remember_state:
puts (" remember_state");
@@ -6322,14 +6327,14 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_uleb128 (op2, readp, endp);
printf (" def_cfa r%" PRIu64 " (%s) at offset %" PRIu64 "\n",
- op1, regname (op1), op2);
+ op1, regname (ebl, op1, regnamebuf), op2);
break;
case DW_CFA_def_cfa_register:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
get_uleb128 (op1, readp, endp);
printf (" def_cfa_register r%" PRIu64 " (%s)\n",
- op1, regname (op1));
+ op1, regname (ebl, op1, regnamebuf));
break;
case DW_CFA_def_cfa_offset:
if ((uint64_t) (endp - readp) < 1)
@@ -6360,7 +6365,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_uleb128 (op2, readp, endp); /* Length of DW_FORM_block. */
printf (" expression r%" PRIu64 " (%s) \n",
- op1, regname (op1));
+ op1, regname (ebl, op1, regnamebuf));
if ((uint64_t) (endp - readp) < op2)
goto invalid;
print_ops (dwflmod, dbg, 10, 10, version, ptr_size, 0, NULL,
@@ -6376,7 +6381,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
get_sleb128 (sop2, readp, endp);
printf (" offset_extended_sf r%" PRIu64 " (%s) at cfa%+"
PRId64 "\n",
- op1, regname (op1), sop2 * data_align);
+ op1, regname (ebl, op1, regnamebuf), sop2 * data_align);
break;
case DW_CFA_def_cfa_sf:
if ((uint64_t) (endp - readp) < 1)
@@ -6386,7 +6391,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_sleb128 (sop2, readp, endp);
printf (" def_cfa_sf r%" PRIu64 " (%s) at offset %" PRId64 "\n",
- op1, regname (op1), sop2 * data_align);
+ op1, regname (ebl, op1, regnamebuf), sop2 * data_align);
break;
case DW_CFA_def_cfa_offset_sf:
if ((uint64_t) (endp - readp) < 1)
@@ -6422,7 +6427,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_uleb128 (op2, readp, endp); /* Length of DW_FORM_block. */
printf (" val_expression r%" PRIu64 " (%s)\n",
- op1, regname (op1));
+ op1, regname (ebl, op1, regnamebuf));
if ((uint64_t) (endp - readp) < op2)
goto invalid;
print_ops (dwflmod, dbg, 10, 10, version, ptr_size, 0,
@@ -6462,11 +6467,12 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
get_uleb128 (offset, readp, endp);
printf (" offset r%u (%s) at cfa%+" PRId64 "\n",
- opcode & 0x3f, regname (opcode & 0x3f), offset * data_align);
+ opcode & 0x3f, regname (ebl, opcode & 0x3f, regnamebuf),
+ offset * data_align);
}
else
printf (" restore r%u (%s)\n",
- opcode & 0x3f, regname (opcode & 0x3f));
+ opcode & 0x3f, regname (ebl, opcode & 0x3f, regnamebuf));
}
}
--
2.26.2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/5] readelf: Pull advance_pc() into file scope
2021-01-08 8:16 Remove nested functions from readelf.c tbaeder
` (3 preceding siblings ...)
2021-01-08 8:16 ` [PATCH 4/5] readelf: Pull regname() into " tbaeder
@ 2021-01-08 8:16 ` tbaeder
2021-02-01 14:21 ` Remove nested functions from readelf.c Mark Wielaard
5 siblings, 0 replies; 12+ messages in thread
From: tbaeder @ 2021-01-08 8:16 UTC (permalink / raw)
To: elfutils-devel
From: Timm Bäder <tbaeder@redhat.com>
Get rid of a nested function this way
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
---
src/readelf.c | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/readelf.c b/src/readelf.c
index e0163891..9758d338 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8356,6 +8356,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp,
return readp;
}
+static inline void
+advance_pc (unsigned int op_advance,
+ uint_fast8_t max_ops_per_instr,
+ uint_fast8_t minimum_instr_len,
+ Dwarf_Word *address,
+ unsigned int *op_addr_advance,
+ unsigned int *op_index,
+ bool *show_op_index)
+{
+ *op_addr_advance = minimum_instr_len * ((*op_index + op_advance)
+ / max_ops_per_instr);
+ (*address) += *op_addr_advance;
+ *show_op_index = (*op_index > 0 ||
+ (*op_index + op_advance) % max_ops_per_instr > 0);
+ *op_index = (*op_index + op_advance) % max_ops_per_instr;
+}
+
static void
print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
@@ -8747,15 +8764,6 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
or DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */
unsigned int op_addr_advance;
bool show_op_index;
- inline void advance_pc (unsigned int op_advance)
- {
- op_addr_advance = minimum_instr_len * ((op_index + op_advance)
- / max_ops_per_instr);
- address += op_addr_advance;
- show_op_index = (op_index > 0 ||
- (op_index + op_advance) % max_ops_per_instr > 0);
- op_index = (op_index + op_advance) % max_ops_per_instr;
- }
if (max_ops_per_instr == 0)
{
@@ -8792,7 +8800,9 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
/* Perform the increments. */
line += line_increment;
- advance_pc ((opcode - opcode_base) / line_range);
+ advance_pc ((opcode - opcode_base) / line_range,
+ max_ops_per_instr, minimum_instr_len, &address,
+ &op_addr_advance, &op_index, &show_op_index);
printf (_(" special opcode %u: address+%u = "),
opcode, op_addr_advance);
@@ -8910,7 +8920,9 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
if (lineendp - linep < 1)
goto invalid_unit;
get_uleb128 (u128, linep, lineendp);
- advance_pc (u128);
+ advance_pc (u128, max_ops_per_instr, minimum_instr_len,
+ &address, &op_addr_advance, &op_index,
+ &show_op_index);
{
printf (_(" advance address by %u to "),
op_addr_advance);
@@ -8971,7 +8983,10 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
if (unlikely (line_range == 0))
goto invalid_unit;
- advance_pc ((255 - opcode_base) / line_range);
+ advance_pc ((255 - opcode_base) / line_range,
+ max_ops_per_instr, minimum_instr_len,
+ &address, &op_addr_advance, &op_index,
+ &show_op_index);
{
printf (_(" advance address by constant %u to "),
op_addr_advance);
--
2.26.2
^ permalink raw reply [flat|nested] 12+ messages in thread