[RFC PATCH v1 14/23] objtool: Add orc_print_dump() package

From: Youling Tang
Date: Tue Jun 20 2023 - 03:51:21 EST


There is no functional change, only operations such as orc_print_{sp,fp}
are encapsulated into orc_print_dump(). It is convenient to add LoongArch
support later (because it needs to add orc_print_ra()).

Signed-off-by: Youling Tang <tangyouling@xxxxxxxxxxx>
---
tools/objtool/arch/x86/orc.c | 23 ++++++++++++++++++-----
tools/objtool/include/objtool/orc.h | 5 +----
tools/objtool/orc_dump.c | 12 +-----------
3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/objtool/arch/x86/orc.c b/tools/objtool/arch/x86/orc.c
index a0c00e136089..cf546b274a79 100644
--- a/tools/objtool/arch/x86/orc.c
+++ b/tools/objtool/arch/x86/orc.c
@@ -114,7 +114,7 @@ static const char *reg_name(unsigned int reg)
}
}

-const char *orc_type_name(unsigned int type)
+static const char *orc_type_name(unsigned int type)
{
switch (type) {
case UNWIND_HINT_TYPE_CALL:
@@ -128,7 +128,7 @@ const char *orc_type_name(unsigned int type)
}
}

-void orc_print_reg(unsigned int reg, int offset)
+static void orc_print_reg(unsigned int reg, int offset)
{
if (reg == ORC_REG_BP_INDIRECT)
printf("(bp%+d)", offset);
@@ -140,12 +140,25 @@ void orc_print_reg(unsigned int reg, int offset)
printf("%s%+d", reg_name(reg), offset);
}

-void orc_print_sp(void)
+static void orc_print_sp(void)
{
printf(" sp:");
}
-
-void orc_print_fp(void)
+static void orc_print_fp(void)
{
printf(" bp:");
}
+
+void orc_print_dump(struct elf *dummy_elf, struct orc_entry *orc, int i)
+{
+ orc_print_sp();
+
+ orc_print_reg(orc[i].sp_reg, bswap_if_needed(dummy_elf, orc[i].sp_offset));
+
+ orc_print_fp();
+
+ orc_print_reg(orc[i].bp_reg, bswap_if_needed(dummy_elf, orc[i].bp_offset));
+
+ printf(" type:%s signal:%d end:%d\n",
+ orc_type_name(orc[i].type), orc[i].signal, orc[i].end);
+}
diff --git a/tools/objtool/include/objtool/orc.h b/tools/objtool/include/objtool/orc.h
index bf141134c56f..53a037bdfc35 100644
--- a/tools/objtool/include/objtool/orc.h
+++ b/tools/objtool/include/objtool/orc.h
@@ -10,9 +10,6 @@

int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi,
struct instruction *insn);
-const char *orc_type_name(unsigned int type);
-void orc_print_reg(unsigned int reg, int offset);
-void orc_print_sp(void);
-void orc_print_fp(void);
+void orc_print_dump(struct elf *dummy_elf, struct orc_entry *orc, int i);

#endif /* _OBJTOOL_ORC_H */
diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index 82bdd33dbc39..c274c0577427 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -151,17 +151,7 @@ int orc_dump(const char *_objname)
printf("%llx:", (unsigned long long)(orc_ip_addr + (i * sizeof(int)) + orc_ip[i]));
}

-
- orc_print_sp();
-
- orc_print_reg(orc[i].sp_reg, bswap_if_needed(&dummy_elf, orc[i].sp_offset));
-
- orc_print_fp();
-
- orc_print_reg(orc[i].bp_reg, bswap_if_needed(&dummy_elf, orc[i].bp_offset));
-
- printf(" type:%s signal:%d end:%d\n",
- orc_type_name(orc[i].type), orc[i].signal, orc[i].end);
+ orc_print_dump(&dummy_elf, orc, i);
}

elf_end(elf);
--
2.39.2