This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Backtrace prints wrong argument value
- From: Luis Machado <luisgpm at linux dot vnet dot ibm dot com>
- To: Daniel Jacobowitz <drow at false dot org>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Thu, 13 Sep 2007 11:46:05 -0300
- Subject: Re: [patch] Backtrace prints wrong argument value
- References: <1177527233.12599.42.camel@localhost> <20070425191304.GA1283@caradoc.them.org> <1179293640.4323.16.camel@localhost> <20070516144250.GD24682@caradoc.them.org>
- Reply-to: luisgpm at linux dot vnet dot ibm dot com
:ADDPATCH PowerPC-64:
Hi,
Bringing back this topic, i've written a patch to address this issue on
ppc's side, providing a function to specify call-clobbered registers
based on the ABI, similar to the S390's.
Looking forward to suggestions/corrections.
Best regards
> There is simply not enough information in the debug info to handle
> this correctly. Let me give you another example:
>
> move var to r3
> test something
> if true, branch to Lfoo
> call abort, which clobbers r3
> Lfoo:
> do something with r3
>
> At every instruction after the move, the debug info should say that
> var is in r3. Right? No matter which location we pick here, while
> backtracing from abort, we'll print the wrong value for var and
> there's no point where the debug info will say it is undefined.
>
> If you want us to get this right using DWARF info, I believe your only
> choice is to approach the DWARF working group about it.
>
> Now, in GDB we may have other options. We might be able to get the
> list of call clobbered registers based on the ABI. Compare with s390,
> which already does this (dwarf2_frame_set_init_reg). Does adding
> this to PowerPC help your example any?
>
--
Luis Machado
IBM Linux Technology Center
e-mail: luisgpm@linux.vnet.ibm.com
2007-09-13 Luis Machado <luisgpm@br.ibm.com>
* rs6000-tdep.c (ppc_dwarf2_frame_init_reg): New function.
(rs6000_gdbarch_init): Install ppc_dwarf2_frame_init_reg as
default dwarf2_frame_set_init_reg function.
Index: gdb/rs6000-tdep.c
===================================================================
--- gdb.orig/rs6000-tdep.c 2007-09-13 07:26:12.000000000 -0700
+++ gdb/rs6000-tdep.c 2007-09-13 07:41:10.000000000 -0700
@@ -3468,6 +3468,68 @@
return &rs6000_frame_base;
}
+/* DWARF-2 frame support. Used to handle the detection of
+ clobbered registers during function calls. */
+
+ static void
+ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
+ struct dwarf2_frame_state_reg *reg,
+ struct frame_info *next_frame)
+{
+
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ /* PPC32 and PPC64 ABI's are the same regarding volatile and
+ non-volatile registers. We will use the same code for both. */
+
+ /* Call-saved GP registers. */
+ if ((regnum >= (tdep->ppc_gp0_regnum + 14)
+ && regnum <= (tdep->ppc_gp0_regnum + 31))
+ || (regnum == (tdep->ppc_gp0_regnum + 1)))
+ reg->how = DWARF2_FRAME_REG_SAME_VALUE;
+
+ /* Call-clobbered GP registers. */
+ if ((regnum >= (tdep->ppc_gp0_regnum + 3)
+ && regnum <= (tdep->ppc_gp0_regnum + 12))
+ || (regnum == tdep->ppc_gp0_regnum))
+ reg->how = DWARF2_FRAME_REG_UNDEFINED;
+
+ /* Deal with FP registers, if supported. */
+ if (tdep->ppc_fp0_regnum >= 0)
+ {
+ /* Call-saved FP registers. */
+ if ((regnum >= (tdep->ppc_fp0_regnum + 14)
+ && regnum <= (tdep->ppc_fp0_regnum + 31)))
+ reg->how = DWARF2_FRAME_REG_SAME_VALUE;
+
+ /* Call-clobbered FP registers. */
+ if ((regnum >= (tdep->ppc_fp0_regnum)
+ && regnum <= (tdep->ppc_fp0_regnum + 13)))
+ reg->how = DWARF2_FRAME_REG_UNDEFINED;
+ }
+
+ /* Deal with ALTIVEC registers, if supported. */
+ if (tdep->ppc_vr0_regnum > 0 && tdep->ppc_vrsave_regnum > 0)
+ {
+ /* Call-saved Altivec registers. */
+ if ((regnum >= (tdep->ppc_vr0_regnum + 20)
+ && regnum <= (tdep->ppc_vr0_regnum + 31))
+ || regnum == tdep->ppc_vrsave_regnum)
+ reg->how = DWARF2_FRAME_REG_SAME_VALUE;
+
+ /* Call-clobbered Altivec registers. */
+ if ((regnum >= (tdep->ppc_vr0_regnum)
+ && regnum <= (tdep->ppc_vr0_regnum + 19)))
+ reg->how = DWARF2_FRAME_REG_UNDEFINED;
+ }
+
+ if (regnum == gdbarch_pc_regnum (current_gdbarch))
+ reg->how = DWARF2_FRAME_REG_RA;
+ else if (regnum == gdbarch_sp_regnum (current_gdbarch))
+ reg->how = DWARF2_FRAME_REG_CFA;
+}
+
+
/* Initialize the current architecture based on INFO. If possible, re-use an
architecture from ARCHES, which is a list of architectures already created
during this debugging session.
@@ -3790,6 +3852,10 @@
tdep->ppc_vr0_regnum = 71;
tdep->ppc_vrsave_regnum = 104;
}
+
+ /* Frame handling. */
+ dwarf2_frame_set_init_reg (gdbarch, ppc_dwarf2_frame_init_reg);
+
/* Fall Thru */
case GDB_OSABI_NETBSD_AOUT:
case GDB_OSABI_NETBSD_ELF: