public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make dcache multi-target-safe
@ 2021-09-24 15:50 Pedro Alves
  2021-09-24 16:54 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2021-09-24 15:50 UTC (permalink / raw)
  To: gdb-patches

By inspection, I noticed that this code in dcache.c is not
multi-target-aware:

  /* If this is a different inferior from what we've recorded,
     flush the cache.  */

  if (inferior_ptid != dcache->ptid)

This doesn't take into account that threads of different targets may
have the same ptid.

Fixed by also storing/comparing the process_stratum_target.

Tested on x86-64-linux-gnu, native and gdbserver.

Change-Id: I4d9d74052c696b72d28cb1c77b697b911725c8d3
---
 gdb/dcache.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gdb/dcache.c b/gdb/dcache.c
index 50b3854fe69..98365fee3b1 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -116,6 +116,10 @@ struct dcache_struct
 
   /* The ptid of last inferior to use cache or null_ptid.  */
   ptid_t ptid;
+
+  /* The process target of last inferior to use the cache or
+     nullptr.  */
+  process_stratum_target *proc_target;
 };
 
 typedef void (block_func) (struct dcache_block *block, void *param);
@@ -249,6 +253,7 @@ dcache_invalidate (DCACHE *dcache)
   dcache->oldest = NULL;
   dcache->size = 0;
   dcache->ptid = null_ptid;
+  dcache->proc_target = nullptr;
 
   if (dcache->line_size != dcache_line_size)
     {
@@ -453,6 +458,7 @@ dcache_init (void)
   dcache->size = 0;
   dcache->line_size = dcache_line_size;
   dcache->ptid = null_ptid;
+  dcache->proc_target = nullptr;
 
   return dcache;
 }
@@ -470,13 +476,15 @@ dcache_read_memory_partial (struct target_ops *ops, DCACHE *dcache,
 {
   ULONGEST i;
 
-  /* If this is a different inferior from what we've recorded,
-     flush the cache.  */
+  /* If this is a different thread from what we've recorded, flush the
+     cache.  */
 
-  if (inferior_ptid != dcache->ptid)
+  process_stratum_target *proc_target = current_inferior ()->process_target ();
+  if (proc_target != dcache->proc_target || inferior_ptid != dcache->ptid)
     {
       dcache_invalidate (dcache);
       dcache->ptid = inferior_ptid;
+      dcache->proc_target = proc_target;
     }
 
   for (i = 0; i < len; i++)

base-commit: 62df62b23032bb33ae7d7dc7ec7039a25794907b
-- 
2.26.2


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

* Re: [PATCH] Make dcache multi-target-safe
  2021-09-24 15:50 [PATCH] Make dcache multi-target-safe Pedro Alves
@ 2021-09-24 16:54 ` Andrew Burgess
  2021-09-24 17:55   ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2021-09-24 16:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

* Pedro Alves <pedro@palves.net> [2021-09-24 16:50:11 +0100]:

> By inspection, I noticed that this code in dcache.c is not
> multi-target-aware:
> 
>   /* If this is a different inferior from what we've recorded,
>      flush the cache.  */
> 
>   if (inferior_ptid != dcache->ptid)
> 
> This doesn't take into account that threads of different targets may
> have the same ptid.
> 
> Fixed by also storing/comparing the process_stratum_target.
> 
> Tested on x86-64-linux-gnu, native and gdbserver.

LGTM.

Thanks,
Andrew

> 
> Change-Id: I4d9d74052c696b72d28cb1c77b697b911725c8d3
> ---
>  gdb/dcache.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/dcache.c b/gdb/dcache.c
> index 50b3854fe69..98365fee3b1 100644
> --- a/gdb/dcache.c
> +++ b/gdb/dcache.c
> @@ -116,6 +116,10 @@ struct dcache_struct
>  
>    /* The ptid of last inferior to use cache or null_ptid.  */
>    ptid_t ptid;
> +
> +  /* The process target of last inferior to use the cache or
> +     nullptr.  */
> +  process_stratum_target *proc_target;
>  };
>  
>  typedef void (block_func) (struct dcache_block *block, void *param);
> @@ -249,6 +253,7 @@ dcache_invalidate (DCACHE *dcache)
>    dcache->oldest = NULL;
>    dcache->size = 0;
>    dcache->ptid = null_ptid;
> +  dcache->proc_target = nullptr;
>  
>    if (dcache->line_size != dcache_line_size)
>      {
> @@ -453,6 +458,7 @@ dcache_init (void)
>    dcache->size = 0;
>    dcache->line_size = dcache_line_size;
>    dcache->ptid = null_ptid;
> +  dcache->proc_target = nullptr;
>  
>    return dcache;
>  }
> @@ -470,13 +476,15 @@ dcache_read_memory_partial (struct target_ops *ops, DCACHE *dcache,
>  {
>    ULONGEST i;
>  
> -  /* If this is a different inferior from what we've recorded,
> -     flush the cache.  */
> +  /* If this is a different thread from what we've recorded, flush the
> +     cache.  */
>  
> -  if (inferior_ptid != dcache->ptid)
> +  process_stratum_target *proc_target = current_inferior ()->process_target ();
> +  if (proc_target != dcache->proc_target || inferior_ptid != dcache->ptid)
>      {
>        dcache_invalidate (dcache);
>        dcache->ptid = inferior_ptid;
> +      dcache->proc_target = proc_target;
>      }
>  
>    for (i = 0; i < len; i++)
> 
> base-commit: 62df62b23032bb33ae7d7dc7ec7039a25794907b
> -- 
> 2.26.2
> 

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

* Re: [PATCH] Make dcache multi-target-safe
  2021-09-24 16:54 ` Andrew Burgess
@ 2021-09-24 17:55   ` Pedro Alves
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2021-09-24 17:55 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On 2021-09-24 5:54 p.m., Andrew Burgess wrote:
> * Pedro Alves <pedro@palves.net> [2021-09-24 16:50:11 +0100]:
> 
>> By inspection, I noticed that this code in dcache.c is not
>> multi-target-aware:
>>
>>   /* If this is a different inferior from what we've recorded,
>>      flush the cache.  */
>>
>>   if (inferior_ptid != dcache->ptid)
>>
>> This doesn't take into account that threads of different targets may
>> have the same ptid.
>>
>> Fixed by also storing/comparing the process_stratum_target.
>>
>> Tested on x86-64-linux-gnu, native and gdbserver.
> 
> LGTM.

Thanks Andrew.  Pushed.

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

end of thread, other threads:[~2021-09-24 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 15:50 [PATCH] Make dcache multi-target-safe Pedro Alves
2021-09-24 16:54 ` Andrew Burgess
2021-09-24 17:55   ` Pedro Alves

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).