* [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache.
@ 2012-05-04 10:52 Yao Qi
2012-05-04 12:32 ` Pedro Alves
0 siblings, 1 reply; 4+ messages in thread
From: Yao Qi @ 2012-05-04 10:52 UTC (permalink / raw)
To: gdb-patches
Hi,
The current_inferior is saved and restored inside get_thread_regcache,
so it is not necessary to save and restore current_inferior out side
of it.
Regression tested on x86_64-linux. OK to apply?
gdb/gdbserver:
2012-05-04 Yao Qi <yao@codesourcery.com>
* linux-low.c (get_pc, linux_wait_for_lwp): Don't save and restore
current_inferior when call get_thread_cache.
* proc-service.c (ps_lgetregs): Likewise.
---
gdb/gdbserver/linux-low.c | 12 ++----------
gdb/gdbserver/proc-service.c | 7 +------
2 files changed, 3 insertions(+), 16 deletions(-)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 751867b..64d314c 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -503,23 +503,18 @@ handle_extended_wait (struct lwp_info *event_child, int wstat)
static CORE_ADDR
get_pc (struct lwp_info *lwp)
{
- struct thread_info *saved_inferior;
struct regcache *regcache;
CORE_ADDR pc;
if (the_low_target.get_pc == NULL)
return 0;
- saved_inferior = current_inferior;
- current_inferior = get_lwp_thread (lwp);
-
- regcache = get_thread_regcache (current_inferior, 1);
+ regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
pc = (*the_low_target.get_pc) (regcache);
if (debug_threads)
fprintf (stderr, "pc is 0x%lx\n", (long) pc);
- current_inferior = saved_inferior;
return pc;
}
@@ -1425,15 +1420,12 @@ retry:
&& WIFSTOPPED (*wstatp)
&& the_low_target.get_pc != NULL)
{
- struct thread_info *saved_inferior = current_inferior;
struct regcache *regcache;
CORE_ADDR pc;
- current_inferior = get_lwp_thread (child);
- regcache = get_thread_regcache (current_inferior, 1);
+ regcache = get_thread_regcache (get_lwp_thread (child), 1);
pc = (*the_low_target.get_pc) (regcache);
fprintf (stderr, "linux_wait_for_lwp: pc is 0x%lx\n", (long) pc);
- current_inferior = saved_inferior;
}
return child;
diff --git a/gdb/gdbserver/proc-service.c b/gdb/gdbserver/proc-service.c
index 5584dab..d4c17a2 100644
--- a/gdb/gdbserver/proc-service.c
+++ b/gdb/gdbserver/proc-service.c
@@ -99,20 +99,15 @@ ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
{
#ifdef HAVE_REGSETS
struct lwp_info *lwp;
- struct thread_info *reg_inferior, *save_inferior;
struct regcache *regcache;
lwp = find_lwp_pid (pid_to_ptid (lwpid));
if (lwp == NULL)
return PS_ERR;
- reg_inferior = get_lwp_thread (lwp);
- save_inferior = current_inferior;
- current_inferior = reg_inferior;
- regcache = get_thread_regcache (current_inferior, 1);
+ regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
gregset_info ()->fill_function (regcache, gregset);
- current_inferior = save_inferior;
return PS_OK;
#else
return PS_ERR;
--
1.7.0.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache.
2012-05-04 10:52 [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache Yao Qi
@ 2012-05-04 12:32 ` Pedro Alves
2012-05-04 13:08 ` Yao Qi
0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2012-05-04 12:32 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
On 05/04/2012 11:51 AM, Yao Qi wrote:
> Hi,
> The current_inferior is saved and restored inside get_thread_regcache,
> so it is not necessary to save and restore current_inferior out side
> of it.
>
> Regression tested on x86_64-linux. OK to apply?
>
>
> gdb/gdbserver:
>
> 2012-05-04 Yao Qi <yao@codesourcery.com>
>
> * linux-low.c (get_pc, linux_wait_for_lwp): Don't save and restore
> current_inferior when call get_thread_cache.
> * proc-service.c (ps_lgetregs): Likewise.
> ---
> gdb/gdbserver/linux-low.c | 12 ++----------
> gdb/gdbserver/proc-service.c | 7 +------
> 2 files changed, 3 insertions(+), 16 deletions(-)
>
> diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
> index 751867b..64d314c 100644
> --- a/gdb/gdbserver/linux-low.c
> +++ b/gdb/gdbserver/linux-low.c
> @@ -503,23 +503,18 @@ handle_extended_wait (struct lwp_info *event_child, int wstat)
> static CORE_ADDR
> get_pc (struct lwp_info *lwp)
> {
> - struct thread_info *saved_inferior;
> struct regcache *regcache;
> CORE_ADDR pc;
>
> if (the_low_target.get_pc == NULL)
> return 0;
>
> - saved_inferior = current_inferior;
> - current_inferior = get_lwp_thread (lwp);
> -
> - regcache = get_thread_regcache (current_inferior, 1);
> + regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
> pc = (*the_low_target.get_pc) (regcache);
No, the_low_target.get_pc also needs to go to the right inferior.
>
> if (debug_threads)
> fprintf (stderr, "pc is 0x%lx\n", (long) pc);
>
> - current_inferior = saved_inferior;
> return pc;
> }
>
> @@ -1425,15 +1420,12 @@ retry:
> && WIFSTOPPED (*wstatp)
> && the_low_target.get_pc != NULL)
> {
> - struct thread_info *saved_inferior = current_inferior;
> struct regcache *regcache;
> CORE_ADDR pc;
>
> - current_inferior = get_lwp_thread (child);
> - regcache = get_thread_regcache (current_inferior, 1);
> + regcache = get_thread_regcache (get_lwp_thread (child), 1);
> pc = (*the_low_target.get_pc) (regcache);
Ditto.
> fprintf (stderr, "linux_wait_for_lwp: pc is 0x%lx\n", (long) pc);
> - current_inferior = saved_inferior;
> }
>
> return child;
> diff --git a/gdb/gdbserver/proc-service.c b/gdb/gdbserver/proc-service.c
> index 5584dab..d4c17a2 100644
> --- a/gdb/gdbserver/proc-service.c
> +++ b/gdb/gdbserver/proc-service.c
> @@ -99,20 +99,15 @@ ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
> {
> #ifdef HAVE_REGSETS
> struct lwp_info *lwp;
> - struct thread_info *reg_inferior, *save_inferior;
> struct regcache *regcache;
>
> lwp = find_lwp_pid (pid_to_ptid (lwpid));
> if (lwp == NULL)
> return PS_ERR;
>
> - reg_inferior = get_lwp_thread (lwp);
> - save_inferior = current_inferior;
> - current_inferior = reg_inferior;
> - regcache = get_thread_regcache (current_inferior, 1);
> + regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
> gregset_info ()->fill_function (regcache, gregset);
Ditto the whole gregset_info ()->fill_function line, particularly
after my multi-process/multi-arch series, while the fill_function
depends on inferior.
>
> - current_inferior = save_inferior;
> return PS_OK;
> #else
> return PS_ERR;
--
Pedro Alves
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache.
2012-05-04 12:32 ` Pedro Alves
@ 2012-05-04 13:08 ` Yao Qi
2012-05-04 13:45 ` Pedro Alves
0 siblings, 1 reply; 4+ messages in thread
From: Yao Qi @ 2012-05-04 13:08 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 05/04/2012 08:31 PM, Pedro Alves wrote:
>> > - regcache = get_thread_regcache (current_inferior, 1);
>> > + regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
>> > pc = (*the_low_target.get_pc) (regcache);
>
> No, the_low_target.get_pc also needs to go to the right inferior.
>
I thought the_low_target.get_pc is to extract value of pc from regcache,
so inferior is not needed. I examined linux-foo-low.c files again, and
find only ppc_get_pc needs the right inferior, sigh.
>> >
>> > return child;
>> > diff --git a/gdb/gdbserver/proc-service.c b/gdb/gdbserver/proc-service.c
>> > index 5584dab..d4c17a2 100644
>> > --- a/gdb/gdbserver/proc-service.c
>> > +++ b/gdb/gdbserver/proc-service.c
>> > @@ -99,20 +99,15 @@ ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
>> > {
>> > #ifdef HAVE_REGSETS
>> > struct lwp_info *lwp;
>> > - struct thread_info *reg_inferior, *save_inferior;
>> > struct regcache *regcache;
>> >
>> > lwp = find_lwp_pid (pid_to_ptid (lwpid));
>> > if (lwp == NULL)
>> > return PS_ERR;
>> >
>> > - reg_inferior = get_lwp_thread (lwp);
>> > - save_inferior = current_inferior;
>> > - current_inferior = reg_inferior;
>> > - regcache = get_thread_regcache (current_inferior, 1);
>> > + regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
>> > gregset_info ()->fill_function (regcache, gregset);
>
> Ditto the whole gregset_info ()->fill_function line, particularly
> after my multi-process/multi-arch series, while the fill_function
> depends on inferior.
>
So any code needs inferior should be wrapped in the follow manner?
save_inferior = current_inferior;
current_inferior = reg_inferior;
....
....
current_inferior = save_inferior;
The following question is what functions need inferior? AFAICS, all the
methods in the_low_target and functions in `struct regset_info' need
inferior. Anything else?
If methods in the_low_target may need inferior, all the usage of
the_low_target methods should be wrapped by the block above. Is it
correct? I hope I am wrong :)
--
Yao (é½å°§)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache.
2012-05-04 13:08 ` Yao Qi
@ 2012-05-04 13:45 ` Pedro Alves
0 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2012-05-04 13:45 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
On 05/04/2012 02:08 PM, Yao Qi wrote:
> So any code needs inferior should be wrapped in the follow manner?
Almost. The exception is code that takes an explicit thread argument
(current_inferior is a thread pointer). So when you call:
void foo (struct thread_info *thread)
you don't have to care to swap the current_inferior global. `foo' will do
it internally if necessary.
--
Pedro Alves
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-05-04 13:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-04 10:52 [PATCH/gdbserver] Remove current_inferior's save/restore when call get_thread_regcache Yao Qi
2012-05-04 12:32 ` Pedro Alves
2012-05-04 13:08 ` Yao Qi
2012-05-04 13:45 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox