Hi,
On Fri, Jul 29, 2022 at 11:18:45PM +0800, Di Chen wrote:
> Re-pushed for fixing run-backtrace-core-sparc.sh failure which resulted
> from some wrong register number.
Thanks. Good the try check caught that copy/paste issue, I would have
probably missed it on review.
> On Fri, Jul 29, 2022 at 9:27 PM Di Chen wrote:
>
> > Thanks for the review, Mark.
> >
> > Re-pushed a patch for it.
> >
> > 1. NEWS entry added.
> > 2. __libdwfl_frame_reg_get/dwfl_frame_reg updated with return int.
> > 3. New DWFL_ERROR added: REGISTER_VAL_UNKNOWN.
Thanks, this looks good. I added ChangeLog entries while
reviewing. Not code issues found. I did change invalud -> invalid in
the comments and tweaked the comment on __libdwfl_frame_reg_get to
explain no error code is ever set. Pushed with those changes.
Cheers,
Mark
>From ccc157dc2b96e47d6d1bbb1b066ecbea4975051b Mon Sep 17 00:00:00 2001
From: Di Chen
Date: Thu, 28 Jul 2022 16:31:05 +0800
Subject: [PATCH] libdwfl: Add new function dwfl_frame_reg
Dwfl has most of the infrastructure to keep the full unwind state,
including the state of unwound registers per frame using
Dwfl_Thread_Callbacks. But there is no public API to access the state,
except for the PC (dwfl_frame_pc).
This commit adds a new function dwfl_frame_reg to get the value of the
DWARF register number in the given frame.
https://sourceware.org/bugzilla/show_bug.cgi?id=28579
Signed-off-by: Di Chen
---
ChangeLog | 4
NEWS| 1 +
libdw/ChangeLog | 4
libdw/libdw.map | 1 +
libdwfl/ChangeLog | 15 ++
libdwfl/dwfl_frame_regs.c | 12 +++
libdwfl/frame_unwind.c | 40 ++---
libdwfl/libdwfl.h | 6 ++
libdwfl/libdwflP.h | 10 +++---
libdwfl/linux-core-attach.c | 2 +-
10 files changed, 66 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index eb2a35f5..0ececcc9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-07-28 Di Chen
+
+ * NEWS: Add dwfl_frame_reg.
+
2022-07-13 Mark Wielaard
* NEWS: Add dwfl_get_debuginfod_client.
diff --git a/NEWS b/NEWS
index 392f2edc..82c86cb6 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Version 0.188 some time after 0.187
debuginfod: Add --disable-source-scan option.
libdwfl: Add new function dwfl_get_debuginfod_client.
+ Add new function dwfl_frame_reg.
Version 0.187
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 6a8f7e51..c9d94e0b 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2022-07-28 Di Chen
+
+ * libdw.map (ELFUTILS_0.188): Add dwfl_frame_reg.
+
2022-07-13 Mark Wielaard
* libdw.map (ELFUTILS_0.187): Renamed to...
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 6da25561..8f393438 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -370,4 +370,5 @@ ELFUTILS_0.186 {
ELFUTILS_0.188 {
global:
dwfl_get_debuginfod_client;
+dwfl_frame_reg;
} ELFUTILS_0.186;
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index acdaa013..30f30b14 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,18 @@
+2022-07-28 Di Chen
+
+ * libdwfl.h (dwfl_frame_reg): New function.
+ * libdwflP.h (DWFL_E_REGISTER_VAL_UNKNOWN): New error code.
+ (__libdwfl_frame_reg_get): Return an int.
+ (dwfl_frame_reg): INTDECL.
+ * dwfl_frame_regs.c (dwfl_frame_reg): New function.
+ * frame_unwind.c (__libdwfl_frame_reg_get): Return an int.
+ (state_get_reg): Removed.
+ (expr_eval): Use INTUSE (dwfl_frame_reg) instead of state_get_reg.
+ (handle_cfi): Likewise.
+ (getfunc): Likewise.
+ * linux-core-attach.c (core_set_initial_registers): Check
+ __libdwfl_frame_reg_get returns zero.
+
2022-07-28 Mark Wielaard
* core-file.c (elf_begin_rand): Replace struct ar_hdr h with
diff --git a/libdwfl/dwfl_frame_regs.c b/libdwfl/dwfl_frame_regs.c
index 83b1abef..a4bd3884 100644
--- a/libdwfl/dwfl_frame_regs.c
+++ b/libdwfl/dwfl_frame_regs.c
@@ -59,3 +59,15 @@ dwfl_thread_state_register_pc (Dwfl_Thread *thread, Dwarf_Word pc)
state->pc_state = DWFL_FRAME_STATE_PC_SET;
}
INTDEF(dwfl_thread_state_register_pc)
+
+int
+dwfl_frame_reg (Dwfl_Frame *state, unsigned regno, Dwarf_Word *val)
+{
+ int res = __libdwfl_frame_reg_get (state, regno, val);
+ if (res == -1)
+ __libdwfl_seterrno (DWFL_E_INVALID_REGISTER);
+ else if (res == 1)
+ __libdwfl_seterrno (DWFL_E_REGISTER_VAL_UNKNOWN);
+ return res;
+}
+INTDEF(dwfl_frame_reg)
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index 9ac33833..8185d84b 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -43,21 +43,21 @@
error. */
#define DWARF_EXPR_STEPS_MAX 0x1000
-bool
+int
internal_function
__libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno, Dwarf_Addr *val)
{
Ebl *ebl = state->thread->process->ebl;
if (! ebl_dwarf_to_regno (ebl, ®no))
-return false;
+return -1;
if (regno >= ebl_frame_nregs (ebl))
-ret