public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [rfa] Update PC without side effect in displaced stepping
@ 2010-12-20  7:50 Yao Qi
  2010-12-20  8:06 ` Mark Kettenis
  0 siblings, 1 reply; 16+ messages in thread
From: Yao Qi @ 2010-12-20  7:50 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]

During preparation of displaced stepping (in displaced_step_prepare),
regcache_write_pc is called to update PC to the address of copy area,
and gdbarch_write_pc is called subsequently.  However, gdbarch_write_pc
has some side effects besides updating PC values.

As far as I know on updating PC in displaced_step_prepare, what we need
here is to force program to execute one or some instructions in copy
area, and get the *same* effect of single-step one instruction on
original place, so we should update PC without any side effect.

Current approach may have some drawbacks in some cases.  For example, on
ARM, system library is compiled in Thumb mode, and application is
compiled in ARM mode.  The copy area for displaced stepping is in thumb
mode.  During displaced stepping, GDB copies that ARM instruction to
copy area, and using regcache_write_pc to update PC to the new address
of this instruction.  Due to the side effect of arm_write_pc, the T bit
is set in status register, so one 32-bit ARM instruction is interpreted
as two 16-bit thumb instructions by mistake.

This patch is to fix this problem.  Regression tested on x86_64-linux.
OK for mainline?

-- 
Yao (齐尧)

[-- Attachment #2: displaced_step_prepare.1220.patch --]
[-- Type: text/x-patch, Size: 836 bytes --]

2010-12-20  Yao Qi  <yao@codesourcery.com>

	* infrun.c (displaced_step_prepare): Replace regcache_write_pc by
	regcache_cooked_write_unsigned to update PC without side effect.

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 1bc00a4..2711e19 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1304,8 +1304,13 @@ displaced_step_prepare (ptid_t ptid)
 
   make_cleanup (displaced_step_clear_cleanup, displaced);
 
-  /* Resume execution at the copy.  */
-  regcache_write_pc (regcache, copy);
+  /* Resume execution at the copy.  Update PC without any side effects.  */
+  if (gdbarch_pc_regnum (gdbarch) >= 0)
+    regcache_cooked_write_unsigned (regcache,
+				    gdbarch_pc_regnum (gdbarch), copy);
+  else
+    internal_error (__FILE__, __LINE__,
+		    _("displaced: Unable to update PC"));
 
   discard_cleanups (ignore_cleanups);
 

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-02-15 21:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20  7:50 [rfa] Update PC without side effect in displaced stepping Yao Qi
2010-12-20  8:06 ` Mark Kettenis
2010-12-20 13:42   ` Yao Qi
2010-12-21 16:19     ` Yao Qi
2010-12-23  4:54       ` Joel Brobecker
2010-12-23  8:45         ` Yao Qi
2011-01-06 14:19           ` [PING : rfa] " Yao Qi
2011-01-12  5:39           ` [try 3rd] arm_pc_is_thumb takes displaced stepping into account Yao Qi
2011-01-13 15:55             ` Matthew Gretton-Dann
2011-01-13 16:34               ` Yao Qi
2011-01-19 16:09             ` [Ping 1: try " Yao Qi
2011-01-30  3:21               ` [Ping 2: " Yao Qi
2011-01-31 15:40             ` [try " Ulrich Weigand
2011-02-10  6:42               ` Yao Qi
2011-02-15 21:15                 ` Ulrich Weigand
2010-12-23 12:04         ` [rfa] Update PC without side effect in displaced stepping Mark Kettenis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).