* [RFA/RFC] Improve hppa PC reading/unwinding
@ 2004-12-05 21:34 Mark Kettenis
2004-12-07 11:04 ` Joel Brobecker
0 siblings, 1 reply; 3+ messages in thread
From: Mark Kettenis @ 2004-12-05 21:34 UTC (permalink / raw)
To: randolph, brobecker; +Cc: gdb-patches
Here is an improved version of the patch I posted yesterday. This
splits out the HP-UX specific bits and puts them in hppa-hpux-tdep.c.
It also treats addresses as unsigned. See
http://sources.redhat.com/ml/gdb-patches/2004-12/msg00105.html
for a motivation. Comments?
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* hppa-tdep.h (hppa_read_pc, hppa_write_pc, hppa_unwind_pc): New
prototypes.
* hppa-tdep.c (hppa_read_pc): Rename from hppa_target_read_pc.
Make global. Remove HP-UX specific code.
(hppa_write_pc): Rename from hppa_target_write_pc. Make global.
Remove HP-UX specific code.
(hppa_unwind_pc): Make global. Remove HP-UX specific code.
(hppa_frame_prev_register_helper): Set "flags" register to zero
for all unwound frames.
(hppa_gdbarch_init): Adjust.
* hppa-hpux-tdep.c (HPPA_HPUX_SS_INSYSCALL): New define.
(hppa_hpux_read_pc, hppa_hpux_write_pc)
(hppa_hpux_unwind_pc): New functions.
(hppa_hpux_init_abi): Set read_pc, write_pc and unwind_pc.
Index: hppa-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.184
diff -u -p -r1.184 hppa-tdep.c
--- hppa-tdep.c 3 Dec 2004 23:59:52 -0000 1.184
+++ hppa-tdep.c 5 Dec 2004 19:58:31 -0000
@@ -1034,54 +1034,31 @@ hppa64_frame_align (struct gdbarch *gdba
return align_up (addr, 16);
}
-
-/* Get the PC from %r31 if currently in a syscall. Also mask out privilege
- bits. */
-
-static CORE_ADDR
-hppa_target_read_pc (ptid_t ptid)
+CORE_ADDR
+hppa_read_pc (ptid_t ptid)
{
- int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
- ULONGEST ipsw = read_register_pid (HPPA_IPSW_REGNUM, ptid);
+ ULONGEST ipsw;
CORE_ADDR pc;
- /* The following test does not belong here. It is OS-specific, and belongs
- in native code. */
- /* Test SS_INSYSCALL */
- if (flags & 2)
- return read_register_pid (31, ptid) & ~0x3;
-
- pc = read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid) & ~0x3;
+ ipsw = read_register_pid (HPPA_IPSW_REGNUM, ptid);
+ pc = read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid);
/* If the current instruction is nullified, then we are effectively
still executing the previous instruction. Pretend we are still
- there. This is needed when single stepping; if the nullified instruction
- is on a different line, we don't want gdb to think we've stepped onto
- that line. */
+ there. This is needed when single stepping; if the nullified
+ instruction is on a different line, we don't want GDB to think
+ we've stepped onto that line. */
if (ipsw & 0x00200000)
pc -= 4;
- return pc;
+ return pc & ~0x3;
}
-/* Write out the PC. If currently in a syscall, then also write the new
- PC value into %r31. */
-
-static void
-hppa_target_write_pc (CORE_ADDR v, ptid_t ptid)
+void
+hppa_write_pc (CORE_ADDR pc, ptid_t ptid)
{
- int flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
-
- /* The following test does not belong here. It is OS-specific, and belongs
- in native code. */
- /* If in a syscall, then set %r31. Also make sure to get the
- privilege bits set correctly. */
- /* Test SS_INSYSCALL */
- if (flags & 2)
- write_register_pid (31, v | 0x3, ptid);
-
- write_register_pid (HPPA_PCOQ_HEAD_REGNUM, v, ptid);
- write_register_pid (HPPA_PCOQ_TAIL_REGNUM, v + 4, ptid);
+ write_register_pid (HPPA_PCOQ_HEAD_REGNUM, pc, ptid);
+ write_register_pid (HPPA_PCOQ_TAIL_REGNUM, pc + 4, ptid);
}
/* return the alignment of a type in bytes. Structures have the maximum
@@ -2194,24 +2171,24 @@ hppa_unwind_dummy_id (struct gdbarch *gd
frame_pc_unwind (next_frame));
}
-static CORE_ADDR
+CORE_ADDR
hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
{
ULONGEST ipsw;
CORE_ADDR pc;
- ipsw = frame_unwind_register_signed (next_frame, HPPA_IPSW_REGNUM);
- pc = frame_unwind_register_signed (next_frame, HPPA_PCOQ_HEAD_REGNUM) & ~3;
+ ipsw = frame_unwind_register_unsigned (next_frame, HPPA_IPSW_REGNUM);
+ pc = frame_unwind_register_unsigned (next_frame, HPPA_PCOQ_HEAD_REGNUM);
/* If the current instruction is nullified, then we are effectively
still executing the previous instruction. Pretend we are still
- there. This is needed when single stepping; if the nullified instruction
- is on a different line, we don't want gdb to think we've stepped onto
- that line. */
+ there. This is needed when single stepping; if the nullified
+ instruction is on a different line, we don't want GDB to think
+ we've stepped onto that line. */
if (ipsw & 0x00200000)
pc -= 4;
- return pc;
+ return pc & ~0x3;
}
/* Instead of this nasty cast, add a method pvoid() that prints out a
@@ -2424,6 +2401,24 @@ hppa_frame_prev_register_helper (struct
return;
}
+ /* Make sure the "flags" register is zero in all unwound frames.
+ The "flags" registers is a HP-UX specific wart, and only the code
+ in hppa-hpux-tdep.c depends on it. However, it is easier to deal
+ with it here. This shouldn't affect other systems since those
+ should provide zero for the "flags" register anyway. */
+ if (regnum == HPPA_FLAGS_REGNUM)
+ {
+ if (valuep)
+ store_unsigned_integer (valuep, 4, 0);
+
+ /* It's a computed value. */
+ *optimizedp = 0;
+ *lvalp = not_lval;
+ *addrp = 0;
+ *realnump = -1;
+ return;
+ }
+
trad_frame_get_prev_register (next_frame, saved_regs, regnum,
optimizedp, lvalp, addrp, realnump, valuep);
}
@@ -2537,8 +2532,8 @@ hppa_gdbarch_init (struct gdbarch_info i
set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address);
set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address);
set_gdbarch_believe_pcc_promotion (gdbarch, 1);
- set_gdbarch_read_pc (gdbarch, hppa_target_read_pc);
- set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
+ set_gdbarch_read_pc (gdbarch, hppa_read_pc);
+ set_gdbarch_write_pc (gdbarch, hppa_write_pc);
/* Helper for function argument information. */
set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
Index: hppa-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.h,v
retrieving revision 1.14
diff -u -p -r1.14 hppa-tdep.h
--- hppa-tdep.h 31 Oct 2004 21:09:28 -0000 1.14
+++ hppa-tdep.h 5 Dec 2004 19:58:31 -0000
@@ -209,4 +209,9 @@ hppa_frame_prev_register_helper (struct
enum lval_type *lvalp, CORE_ADDR *addrp,
int *realnump, void *valuep);
+extern CORE_ADDR hppa_read_pc (ptid_t ptid);
+extern void hppa_write_pc (CORE_ADDR pc, ptid_t ptid);
+extern CORE_ADDR hppa_unwind_pc (struct gdbarch *gdbarch,
+ struct frame_info *next_frame);
+
#endif /* HPPA_TDEP_H */
Index: hppa-hpux-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/hppa-hpux-tdep.c,v
retrieving revision 1.27
diff -u -p -r1.27 hppa-hpux-tdep.c
--- hppa-hpux-tdep.c 5 Dec 2004 15:48:14 -0000 1.27
+++ hppa-hpux-tdep.c 5 Dec 2004 19:58:32 -0000
@@ -1415,6 +1415,52 @@ hppa_hpux_push_dummy_code (struct gdbarc
return sp;
}
+\f
+
+/* Bit in the `ss_flag' member of `struct save_state' that indicates
+ the state was saved from a system call. From
+ <machine/save_state.h>. */
+#define HPPA_HPUX_SS_INSYSCALL 0x02
+
+static CORE_ADDR
+hppa_hpux_read_pc (ptid_t ptid)
+{
+ ULONGEST flags;
+
+ /* If we're currently in a system call return the contents of %r31. */
+ flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
+ if (flags & HPPA_HPUX_SS_INSYSCALL)
+ return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3;
+
+ return hppa_read_pc (ptid);
+}
+
+static void
+hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid)
+{
+ ULONGEST flags;
+
+ /* If we're currently in a system call also write PC into %r31. */
+ flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
+ if (flags & HPPA_HPUX_SS_INSYSCALL)
+ write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid);
+
+ return hppa_write_pc (pc, ptid);
+}
+
+static CORE_ADDR
+hppa_hpux_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+ ULONGEST flags;
+
+ /* If we're currently in a system call return the contents of %r31. */
+ flags = frame_unwind_register_unsigned (next_frame, HPPA_FLAGS_REGNUM);
+ if (flags & HPPA_HPUX_SS_INSYSCALL)
+ return frame_unwind_register_unsigned (next_frame, HPPA_R31_REGNUM) & ~0x3;
+
+ return hppa_unwind_pc (gdbarch, next_frame);
+}
+\f
static void
hppa_hpux_inferior_created (struct target_ops *objfile, int from_tty)
@@ -1442,6 +1488,10 @@ hppa_hpux_init_abi (struct gdbarch_info
set_gdbarch_push_dummy_code (gdbarch, hppa_hpux_push_dummy_code);
set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
+ set_gdbarch_read_pc (gdbarch, hppa_hpux_read_pc);
+ set_gdbarch_write_pc (gdbarch, hppa_hpux_write_pc);
+ set_gdbarch_unwind_pc (gdbarch, hppa_hpux_unwind_pc);
+
frame_unwind_append_sniffer (gdbarch, hppa_hpux_sigtramp_unwind_sniffer);
observer_attach_inferior_created (hppa_hpux_inferior_created);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA/RFC] Improve hppa PC reading/unwinding
2004-12-05 21:34 [RFA/RFC] Improve hppa PC reading/unwinding Mark Kettenis
@ 2004-12-07 11:04 ` Joel Brobecker
2004-12-07 18:24 ` Mark Kettenis
0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2004-12-07 11:04 UTC (permalink / raw)
To: Mark Kettenis; +Cc: randolph, gdb-patches
Hello Mark from Europe!
> Index: ChangeLog
> from Mark Kettenis <kettenis@gnu.org>
>
> * hppa-tdep.h (hppa_read_pc, hppa_write_pc, hppa_unwind_pc): New
> prototypes.
> * hppa-tdep.c (hppa_read_pc): Rename from hppa_target_read_pc.
> Make global. Remove HP-UX specific code.
> (hppa_write_pc): Rename from hppa_target_write_pc. Make global.
> Remove HP-UX specific code.
> (hppa_unwind_pc): Make global. Remove HP-UX specific code.
> (hppa_frame_prev_register_helper): Set "flags" register to zero
> for all unwound frames.
> (hppa_gdbarch_init): Adjust.
> * hppa-hpux-tdep.c (HPPA_HPUX_SS_INSYSCALL): New define.
> (hppa_hpux_read_pc, hppa_hpux_write_pc)
> (hppa_hpux_unwind_pc): New functions.
> (hppa_hpux_init_abi): Set read_pc, write_pc and unwind_pc.
I read the patch, and also tested it with the little example I posted
in the thread you mentioned, and found that it fixed the problem. I
also did a bit of sanity checking and it looks good. I can also test
this change against the testsuite if necessary.
(I really like the fact that the HP/UX part is moved to the hpux tdep).
--
Joel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA/RFC] Improve hppa PC reading/unwinding
2004-12-07 11:04 ` Joel Brobecker
@ 2004-12-07 18:24 ` Mark Kettenis
0 siblings, 0 replies; 3+ messages in thread
From: Mark Kettenis @ 2004-12-07 18:24 UTC (permalink / raw)
To: brobecker; +Cc: randolph, gdb-patches
Date: Tue, 7 Dec 2004 11:07:49 +0100
From: Joel Brobecker <brobecker@adacore.com>
> Index: ChangeLog
> from Mark Kettenis <kettenis@gnu.org>
>
> * hppa-tdep.h (hppa_read_pc, hppa_write_pc, hppa_unwind_pc): New
> prototypes.
> * hppa-tdep.c (hppa_read_pc): Rename from hppa_target_read_pc.
> Make global. Remove HP-UX specific code.
> (hppa_write_pc): Rename from hppa_target_write_pc. Make global.
> Remove HP-UX specific code.
> (hppa_unwind_pc): Make global. Remove HP-UX specific code.
> (hppa_frame_prev_register_helper): Set "flags" register to zero
> for all unwound frames.
> (hppa_gdbarch_init): Adjust.
> * hppa-hpux-tdep.c (HPPA_HPUX_SS_INSYSCALL): New define.
> (hppa_hpux_read_pc, hppa_hpux_write_pc)
> (hppa_hpux_unwind_pc): New functions.
> (hppa_hpux_init_abi): Set read_pc, write_pc and unwind_pc.
I read the patch, and also tested it with the little example I posted
in the thread you mentioned, and found that it fixed the problem. I
also did a bit of sanity checking and it looks good. I can also test
this change against the testsuite if necessary.
Nah, I ran the testsuite myself. Went ahead and committed it.
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-12-07 18:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-05 21:34 [RFA/RFC] Improve hppa PC reading/unwinding Mark Kettenis
2004-12-07 11:04 ` Joel Brobecker
2004-12-07 18:24 ` Mark Kettenis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox