* Target-specific thread switching backend
@ 2007-12-05 14:26 Maciej W. Rozycki
2007-12-05 15:22 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Maciej W. Rozycki @ 2007-12-05 14:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Maciej W. Rozycki
Hello,
In preparation for submitting support for the MDI target I propose the
following enhancement to target_switch_to_thread(). The MDI implements a
multi-threaded target which remembers the currently selected thread within
itself. All the operations that have thread-local scope, such as
accessing of the CPU registers, use that thread identifier. Therefore I
think it is reasonable to propagate the thread-switch event down to the
target, which is what the following change implements.
Tested using the mipsisa32-sde-elf target, with the mips-sim-sde32/-EB
and mips-sim-sde32/-EL boards with no regressions.
2007-12-05 Maciej W. Rozycki <macro@mips.com>
* target.c (update_current_target): Initialize
to_switch_to_thread.
* target.h (target_switch_to_thread): New macro.
* thread.c (switch_to_thread): Call target_switch_to_thread().
OK to apply?
Maciej
13327-1.diff
Index: binutils-quilt/src/gdb/target.h
===================================================================
--- binutils-quilt.orig/src/gdb/target.h 2007-12-03 14:28:21.000000000 +0000
+++ binutils-quilt/src/gdb/target.h 2007-12-03 14:28:24.000000000 +0000
@@ -393,6 +393,7 @@
void (*to_mourn_inferior) (void);
int (*to_can_run) (void);
void (*to_notice_signals) (ptid_t ptid);
+ void (*to_switch_to_thread) (void);
int (*to_thread_alive) (ptid_t ptid);
void (*to_find_new_threads) (void);
char *(*to_pid_to_str) (ptid_t);
@@ -878,6 +879,14 @@
#define target_notice_signals(ptid) \
(*current_target.to_notice_signals) (ptid)
+/* Switch to a selected thread. */
+
+#define target_switch_to_thread() \
+ do \
+ if (current_target.to_switch_to_thread) \
+ (*current_target.to_switch_to_thread) (); \
+ while (0)
+
/* Check to see if a thread is still alive. */
#define target_thread_alive(ptid) \
Index: binutils-quilt/src/gdb/thread.c
===================================================================
--- binutils-quilt.orig/src/gdb/thread.c 2007-12-03 14:20:57.000000000 +0000
+++ binutils-quilt/src/gdb/thread.c 2007-12-03 14:28:24.000000000 +0000
@@ -462,6 +462,7 @@
inferior_ptid = ptid;
reinit_frame_cache ();
registers_changed ();
+ target_switch_to_thread ();
stop_pc = read_pc ();
}
Index: binutils-quilt/src/gdb/target.c
===================================================================
--- binutils-quilt.orig/src/gdb/target.c 2007-12-03 14:20:57.000000000 +0000
+++ binutils-quilt/src/gdb/target.c 2007-12-03 14:28:24.000000000 +0000
@@ -438,6 +438,7 @@
INHERIT (to_mourn_inferior, t);
INHERIT (to_can_run, t);
INHERIT (to_notice_signals, t);
+ INHERIT (to_switch_to_thread, t);
INHERIT (to_thread_alive, t);
INHERIT (to_find_new_threads, t);
INHERIT (to_pid_to_str, t);
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Target-specific thread switching backend
2007-12-05 14:26 Target-specific thread switching backend Maciej W. Rozycki
@ 2007-12-05 15:22 ` Daniel Jacobowitz
2007-12-05 16:07 ` Maciej W. Rozycki
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2007-12-05 15:22 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: gdb-patches, Maciej W. Rozycki
On Wed, Dec 05, 2007 at 02:13:18PM +0000, Maciej W. Rozycki wrote:
> Hello,
>
> In preparation for submitting support for the MDI target I propose the
> following enhancement to target_switch_to_thread(). The MDI implements a
> multi-threaded target which remembers the currently selected thread within
> itself. All the operations that have thread-local scope, such as
> accessing of the CPU registers, use that thread identifier. Therefore I
> think it is reasonable to propagate the thread-switch event down to the
> target, which is what the following change implements.
I don't see why this is necessary, or how it is safe. At every
operation, the requested thread should be indicated by inferior_ptid
(or a ptid_t argument in some cases). And switch_to_thread is usually
but not always called when inferior_ptid is changed, e.g.
regcache_raw_read.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Target-specific thread switching backend
2007-12-05 15:22 ` Daniel Jacobowitz
@ 2007-12-05 16:07 ` Maciej W. Rozycki
2007-12-05 18:37 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Maciej W. Rozycki @ 2007-12-05 16:07 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches, Maciej W. Rozycki
On Wed, 5 Dec 2007, Daniel Jacobowitz wrote:
> I don't see why this is necessary, or how it is safe. At every
> operation, the requested thread should be indicated by inferior_ptid
> (or a ptid_t argument in some cases). And switch_to_thread is usually
> but not always called when inferior_ptid is changed, e.g.
> regcache_raw_read.
Well, I found it cleaner for the hardware to follow what GDB thinks that
the current thread is, but I suppose I can make the switch be done in the
calls that access registers and hardware breakpoints as appropriate only
and cache the last seen value of inferior_ptid within the target code to
make it reasonably fast.
It sounds worrying though, that the notion of the current thread within
GDB is changed freely somewhere when there is a dedicated call to switch
threads, hmm...
Maciej
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Target-specific thread switching backend
2007-12-05 16:07 ` Maciej W. Rozycki
@ 2007-12-05 18:37 ` Daniel Jacobowitz
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2007-12-05 18:37 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: gdb-patches, Maciej W. Rozycki
On Wed, Dec 05, 2007 at 03:22:34PM +0000, Maciej W. Rozycki wrote:
> It sounds worrying though, that the notion of the current thread within
> GDB is changed freely somewhere when there is a dedicated call to switch
> threads, hmm...
Yes, especially when all the thread IDs should be really be arguments
to these functions. For instance, the global current_regcache is
silly; we should support more than one regcache live at a time.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-05 16:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-05 14:26 Target-specific thread switching backend Maciej W. Rozycki
2007-12-05 15:22 ` Daniel Jacobowitz
2007-12-05 16:07 ` Maciej W. Rozycki
2007-12-05 18:37 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox