libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unw_get_reg vs current cursor ip (Was: [Libunwind-devel] [patch] Fixup s


From: Mark Wielaard
Subject: unw_get_reg vs current cursor ip (Was: [Libunwind-devel] [patch] Fixup start_ip in unw_get_proc_info when no dwarf info)
Date: Mon, 19 Nov 2007 13:22:43 +0100

Hi David,

On Mon, 2007-10-08 at 12:56 -0600, David Mosberger-Tang wrote: 
> I'm not sure I understand what the real issue is this patch is trying
> to solve.  Using unw_get_proc_name() will *not* give you reliably the
> starting address of the procedure.  It just gives you the address of a
> preceding (hopefully nearby) label.  Perhaps Frysk is mixing
> proc_info.start_ip and the info returned by unw_get_proc_name(), but I
> don't understand exactly what's going on and why the current libunwind
> behavior would be a problem.   Can you explain, perhaps with an
> example?

Indeed, that is what we were doing. And it took me some time to realize
why we were trying to make unw_get_proc_info more accurate. It all comes
down to wanting to have access the current IP of the cursor even though
the frame might not have accurate dwarf info itself. So in some places
we weren't using unw_get_reg(UNW_REG_IP), because that does a dwarf
lookup of the ip, but went through unw_get_proc_info() and
unw_get_proc_name() because those fell back to using the current cursor
ip if the lookup failed. The following patch does the same for
unw_get_reg() and makes things a little bit more efficient in general.

2007-11-19  Mark Wielaard  <address@hidden>

    * src/mi/Gget_reg.c (unw_get_reg): Use cached value from cursor
    when looking for UNW_REG_IP.

If it looks sane it would be nice to get this in.

Cheers,

Mark
diff --git a/src/mi/Gget_reg.c b/src/mi/Gget_reg.c
index 23b72be..5179a88 100644
--- a/src/mi/Gget_reg.c
+++ b/src/mi/Gget_reg.c
@@ -30,5 +30,12 @@ unw_get_reg (unw_cursor_t *cursor, int regnum, unw_word_t 
*valp)
 {
   struct cursor *c = (struct cursor *) cursor;
 
+  // No need to go look up the IP value since it is cached in the cursor.
+  if (regnum == UNW_REG_IP)
+    {
+      *valp = c->dwarf.ip;
+      return 0;
+    }
+
   return tdep_access_reg (c, regnum, valp, 0);
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]