[patch] [i386] Put hlt at the ON_STACK breakpoint [Re: GDB 7.4.91 available for testing]

Jan Kratochvil jan.kratochvil@redhat.com
Mon Jul 23 07:22:00 GMT 2012


On Sun, 22 Jul 2012 21:00:55 +0200, Philippe Waroquiers wrote:
> The problem with the above technique is that there is no valid
> instruction at the ON_STACK breakpoint address, and the valgrind
> translator does not like this.

Therefore is it enough for valgrind to fix it by the patch below?
It would be a good GDB user convenience fix anyway.

Former:
(gdb) up
#1  <function called from gdb>
(gdb) x/i $pc
=> 0x455210 <_start>:	xor    %ebp,%ebp

Current:
(gdb) up
#1  <function called from gdb>
(gdb) x/i $pc
=> 0x7fffffffda8f:	add    %al,(%rax)

Current patched:
(gdb) up
#1  <function called from gdb>
(gdb) x/i $pc
=> 0x7fffffffda0f:	hlt    
(gdb) 


Thanks,
Jan


gdb/
2012-07-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* i386-tdep.c (i386_push_dummy_code): New variable hlt.  Call
	write_memoryg for it.

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 84e9794..712f0ff 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2340,10 +2340,17 @@ i386_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
 		      CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
 		      struct regcache *regcache)
 {
+  /* This hlt instruction is never executed.  */
+  static const bfd_byte hlt = 0xf4;
+
   /* Use 0xcc breakpoint - 1 byte.  */
   *bp_addr = sp - 1;
   *real_pc = funaddr;
 
+  /* While inferior execution will trap on the 0xcc int3 instruction user
+     investigating the memory from GDB could see uninitialized bytes.  */
+  write_memory (*bp_addr, &hlt, sizeof (hlt));
+
   /* Keep the stack aligned.  */
   return sp - 16;
 }



More information about the Gdb-patches mailing list