Skip to contentSkip to conversation

hppa gdb fix for printing function returns

parisc-linux Richard Hirst 1 participant 1 message May 31, 2002

lore
Share & tools
lore
#0 lore raw

package: gdb
version: 5.2.cvs20020401-6

The attached patch fixes gdb on hppa so that it will print function returns (e.g. "print foo(6)"), where previously it would crash the inferior with protection faults.

There are still some problems, for example, print strlen("foo") will fail. To evaluate that, gdb has first got to get the inferior to call malloc so there is somewhere to store the string. For a dynamically linked program, gdb is finding a symbol 'malloc' in ld-2.2.5.so and trying to call that, with a bogus dp value. If you link the program statically, gdb finds the right 'malloc' to call and it works.

Richard

gdb/pa-linux-tdep.c +6 -6
diff -ur gdb-5.2.cvs20020401.ori/gdb/pa-linux-tdep.c gdb-5.2.cvs20020401/gdb/pa-linux-tdep.c
@@ -38,8 +38,8 @@
 static void
 pa_write_pc (CORE_ADDR pc, ptid_t ptid)
 {
-  write_register_pid (PA_PCOQ_HEAD_REGNUM, pc, ptid);
-  write_register_pid (PA_PCOQ_TAIL_REGNUM, pc + 4, ptid);
+  write_register_pid (PA_PCOQ_HEAD_REGNUM, pc | 3, ptid);
+  write_register_pid (PA_PCOQ_TAIL_REGNUM, (pc + 4) | 3, ptid);
 }
 
 static CORE_ADDR
@@ -426,8 +426,8 @@
   /* We can not modify the instruction address queues directly, so we start
      up the inferior and execute a couple of instructions to set them so
      that they point to the call dummy in the stack.  */
-  pcoqh = read_register (PA_PCOQ_HEAD_REGNUM);
-  pcoqt = read_register (PA_PCOQ_TAIL_REGNUM);
+  pcoqh = read_register (PA_PCOQ_HEAD_REGNUM) & ~3;
+  pcoqt = read_register (PA_PCOQ_TAIL_REGNUM) & ~3;
 
   if (target_read_memory (pcoqh, buf, 4) != 0)
     error ("Couldn't modify instruction address queue\n");
@@ -547,8 +547,8 @@
   /* We can not modify the instruction address queues directly, so we start
      up the inferior and execute a couple of instructions to set them so
      that they point to the call dummy in the stack.  */
-  pcoqh = read_register (PA_PCOQ_HEAD_REGNUM);
-  pcoqt = read_register (PA_PCOQ_TAIL_REGNUM);
+  pcoqh = read_register (PA_PCOQ_HEAD_REGNUM) & ~3;
+  pcoqt = read_register (PA_PCOQ_TAIL_REGNUM) & ~3;
 
   if (target_read_memory (pcoqh, buf, 4) != 0)
     error ("Couldn't modify instruction address queue\n");
gdb/pa-tdep.c +1 -0
diff -ur gdb-5.2.cvs20020401.ori/gdb/pa-tdep.c gdb-5.2.cvs20020401/gdb/pa-tdep.c
@@ -2098,6 +2098,7 @@
   int reg_size = REGISTER_SIZE;
 
   fp = FRAME_FP (frame);
+  FRAME_INIT_SAVED_REGS(frame);
   fsr = frame->saved_regs;
 
 #ifndef NO_PC_SPACE_QUEUE_RESTORE