From: tbaeder@redhat.com
To: elfutils-devel@sourceware.org
Subject: [PATCH 5/5] readelf: Pull advance_pc() into file scope
Date: Fri, 8 Jan 2021 09:16:33 +0100 [thread overview]
Message-ID: <20210108081633.2202592-6-tbaeder@redhat.com> (raw)
In-Reply-To: <20210108081633.2202592-1-tbaeder@redhat.com>
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
next prev parent reply other threads:[~2021-01-08 8:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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-30 19:55 ` Mark Wielaard
2021-01-08 8:16 ` [PATCH 2/5] readelf: Pull same_set() info " tbaeder
2021-01-30 20:14 ` Mark Wielaard
2021-01-08 8:16 ` [PATCH 3/5] readelf: Pull left() " tbaeder
2021-01-30 20:29 ` Mark Wielaard
2021-01-08 8:16 ` [PATCH 4/5] readelf: Pull regname() into " tbaeder
2021-01-30 20:47 ` Mark Wielaard
2021-01-08 8:16 ` tbaeder [this message]
2021-02-01 14:21 ` Remove nested functions from readelf.c Mark Wielaard
2021-02-02 10:07 ` Timm Bäder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210108081633.2202592-6-tbaeder@redhat.com \
--to=tbaeder@redhat.com \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).