public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][PR symtab/17855] Fix.
@ 2015-01-20  6:27 Doug Evans
  2015-01-22 11:42 ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Doug Evans @ 2015-01-20  6:27 UTC (permalink / raw)
  To: gdb-patches, brobecker

Hi.

This patch fixes symtab/17855.
Basically the issue is that breakpoint_re_set is currently being called
before observer_notify_new_objfile (NULL), and thus the ada symbol
cache (and the general symbol cache of a separate patch) aren't being
flushed first, so that when breakpoints are reset symbol lookup is being
done on a stale cache.

Regression tested on amd64-linux.

2015-01-19  Doug Evans  <xdje42@gmail.com>

	PR symtab/17855
	* symfile.c (clear_symtab_users): Notify observers of change before
	calling breakpoint_re_set.

diff --git a/gdb/symfile.c b/gdb/symfile.c
index d55e361..ad481de 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3023,6 +3023,12 @@ clear_symtab_users (int add_flags)
   /* Someday, we should do better than this, by only blowing away
      the things that really need to be blown.  */
 
+  /* Notify anyone listening that the previous loaded symtab(s) are invalid.
+     It is important to do this before calling breakpoint_re_set as the latter
+     will try to look up symbols, and for example the symbol cache needs to
+     be flushed first.  */
+  observer_notify_new_objfile (NULL);
+
   /* Clear the "current" symtab first, because it is no longer valid.
      breakpoint_re_set may try to access the current symtab.  */
   clear_current_source_symtab_and_line ();
@@ -3032,7 +3038,6 @@ clear_symtab_users (int add_flags)
     breakpoint_re_set ();
   clear_last_displayed_sal ();
   clear_pc_function_cache ();
-  observer_notify_new_objfile (NULL);
 
   /* Clear globals which might have pointed into a removed objfile.
      FIXME: It's not clear which of these are supposed to persist

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

* Re: [PATCH][PR symtab/17855] Fix.
  2015-01-20  6:27 [PATCH][PR symtab/17855] Fix Doug Evans
@ 2015-01-22 11:42 ` Pedro Alves
  2015-01-22 15:37   ` Doug Evans
  2015-01-29  8:00   ` Doug Evans
  0 siblings, 2 replies; 7+ messages in thread
From: Pedro Alves @ 2015-01-22 11:42 UTC (permalink / raw)
  To: Doug Evans, gdb-patches, brobecker

On 01/20/2015 06:26 AM, Doug Evans wrote:
> Hi.
> 
> This patch fixes symtab/17855.
> Basically the issue is that breakpoint_re_set is currently being called
> before observer_notify_new_objfile (NULL), and thus the ada symbol
> cache (and the general symbol cache of a separate patch) aren't being
> flushed first, so that when breakpoints are reset symbol lookup is being
> done on a stale cache.
> 
> Regression tested on amd64-linux.
> 
> 2015-01-19  Doug Evans  <xdje42@gmail.com>
> 
> 	PR symtab/17855
> 	* symfile.c (clear_symtab_users): Notify observers of change before
> 	calling breakpoint_re_set.
> 
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index d55e361..ad481de 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -3023,6 +3023,12 @@ clear_symtab_users (int add_flags)
>    /* Someday, we should do better than this, by only blowing away
>       the things that really need to be blown.  */
>  
> +  /* Notify anyone listening that the previous loaded symtab(s) are invalid.
> +     It is important to do this before calling breakpoint_re_set as the latter
> +     will try to look up symbols, and for example the symbol cache needs to
> +     be flushed first.  */
> +  observer_notify_new_objfile (NULL);
> +
>    /* Clear the "current" symtab first, because it is no longer valid.
>       breakpoint_re_set may try to access the current symtab.  */
>    clear_current_source_symtab_and_line ();
> @@ -3032,7 +3038,6 @@ clear_symtab_users (int add_flags)
>      breakpoint_re_set ();
>    clear_last_displayed_sal ();
>    clear_pc_function_cache ();
> -  observer_notify_new_objfile (NULL);

Looking at the whole function, ISTM that the breakpoint_re_set
call should move further down.  I can imagine that breakpoint_re_set
could well hit a stale pc function cache, cleared only after by
clear_pc_function_cache.  breakpoint.c:parse_breakpoint_sals also
references the last displayed sal.  One would hope that breakpoint
re-set is independent of that, though the existing comment about
breakpoint_re_set accessing the current symtab leaves me
wondering.  WDYT?

Thanks,
Pedro Alves

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

* Re: [PATCH][PR symtab/17855] Fix.
  2015-01-22 11:42 ` Pedro Alves
@ 2015-01-22 15:37   ` Doug Evans
  2015-01-29  8:00   ` Doug Evans
  1 sibling, 0 replies; 7+ messages in thread
From: Doug Evans @ 2015-01-22 15:37 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker

On Thu, Jan 22, 2015 at 3:41 AM, Pedro Alves <palves@redhat.com> wrote:
> Looking at the whole function, ISTM that the breakpoint_re_set
> call should move further down.  I can imagine that breakpoint_re_set
> could well hit a stale pc function cache, cleared only after by
> clear_pc_function_cache.  breakpoint.c:parse_breakpoint_sals also
> references the last displayed sal.  One would hope that breakpoint
> re-set is independent of that, though the existing comment about
> breakpoint_re_set accessing the current symtab leaves me
> wondering.  WDYT?

Fine by me.

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

* Re: [PATCH][PR symtab/17855] Fix.
  2015-01-22 11:42 ` Pedro Alves
  2015-01-22 15:37   ` Doug Evans
@ 2015-01-29  8:00   ` Doug Evans
  2015-01-29  8:12     ` Joel Brobecker
  1 sibling, 1 reply; 7+ messages in thread
From: Doug Evans @ 2015-01-29  8:00 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, brobecker

Pedro Alves <palves@redhat.com> writes:
> On 01/20/2015 06:26 AM, Doug Evans wrote:
>> Hi.
>> 
>> This patch fixes symtab/17855.
>> Basically the issue is that breakpoint_re_set is currently being called
>> before observer_notify_new_objfile (NULL), and thus the ada symbol
>> cache (and the general symbol cache of a separate patch) aren't being
>> flushed first, so that when breakpoints are reset symbol lookup is being
>> done on a stale cache.
>> 
>> Regression tested on amd64-linux.
>> 
>> 2015-01-19  Doug Evans  <xdje42@gmail.com>
>> 
>> 	PR symtab/17855
>> 	* symfile.c (clear_symtab_users): Notify observers of change before
>> 	calling breakpoint_re_set.
>> 
>> diff --git a/gdb/symfile.c b/gdb/symfile.c
>> index d55e361..ad481de 100644
>> --- a/gdb/symfile.c
>> +++ b/gdb/symfile.c
>> @@ -3023,6 +3023,12 @@ clear_symtab_users (int add_flags)
>>    /* Someday, we should do better than this, by only blowing away
>>       the things that really need to be blown.  */
>>  
>> +  /* Notify anyone listening that the previous loaded symtab(s) are invalid.
>> +     It is important to do this before calling breakpoint_re_set as the latter
>> +     will try to look up symbols, and for example the symbol cache needs to
>> +     be flushed first.  */
>> +  observer_notify_new_objfile (NULL);
>> +
>>    /* Clear the "current" symtab first, because it is no longer valid.
>>       breakpoint_re_set may try to access the current symtab.  */
>>    clear_current_source_symtab_and_line ();
>> @@ -3032,7 +3038,6 @@ clear_symtab_users (int add_flags)
>>      breakpoint_re_set ();
>>    clear_last_displayed_sal ();
>>    clear_pc_function_cache ();
>> -  observer_notify_new_objfile (NULL);
>
> Looking at the whole function, ISTM that the breakpoint_re_set
> call should move further down.  I can imagine that breakpoint_re_set
> could well hit a stale pc function cache, cleared only after by
> clear_pc_function_cache.  breakpoint.c:parse_breakpoint_sals also
> references the last displayed sal.  One would hope that breakpoint
> re-set is independent of that, though the existing comment about
> breakpoint_re_set accessing the current symtab leaves me
> wondering.  WDYT?
>
> Thanks,
> Pedro Alves

Like so?

2015-01-28  Doug Evans  <xdje42@gmail.com>

	PR symtab/17855
	* symfile.c (clear_symtab_users): Move call to breakpoint_re_set
	closer to end.

diff --git a/gdb/symfile.c b/gdb/symfile.c
index d55e361..bad244c 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3023,13 +3023,8 @@ clear_symtab_users (int add_flags)
   /* Someday, we should do better than this, by only blowing away
      the things that really need to be blown.  */
 
-  /* Clear the "current" symtab first, because it is no longer valid.
-     breakpoint_re_set may try to access the current symtab.  */
   clear_current_source_symtab_and_line ();
-
   clear_displays ();
-  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
-    breakpoint_re_set ();
   clear_last_displayed_sal ();
   clear_pc_function_cache ();
   observer_notify_new_objfile (NULL);
@@ -3040,9 +3035,19 @@ clear_symtab_users (int add_flags)
   expression_context_block = NULL;
   innermost_block = NULL;
 
+  /* Now that most everything has been reset, reset any existing breakpoints.
+     Reasons for doing this after the above are that breakpoint resetting may
+     involve:
+     - reading the current source symtab and line,
+     - reading the last displayed sal,
+     - reading the pc function cache,
+     - symbol lookup which requires, for example, invalidating any caches
+       first.  */
+  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
+    breakpoint_re_set ();
+
   /* Varobj may refer to old symbols, perform a cleanup.  */
   varobj_invalidate ();
-
 }
 
 static void




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

* Re: [PATCH][PR symtab/17855] Fix.
  2015-01-29  8:00   ` Doug Evans
@ 2015-01-29  8:12     ` Joel Brobecker
  2015-01-29 10:01       ` Doug Evans
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2015-01-29  8:12 UTC (permalink / raw)
  To: Doug Evans; +Cc: Pedro Alves, gdb-patches

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

Aargh - I was working on it just now because I wasn't sure if anyone
felt they "had the ball on their court".

> Like so?
> 
> 2015-01-28  Doug Evans  <xdje42@gmail.com>
> 
> 	PR symtab/17855
> 	* symfile.c (clear_symtab_users): Move call to breakpoint_re_set
> 	closer to end.

What I've tested is moving the call last, as shown in the attached
diff.  Not technically necessarily better, but as the comment explains,
I move it last so that it's after we've purged all relevant caches.
That way, the function is organized in two rough sections:
  - do purges first;
  - do updates next.
Your comment is a lot more detailed, I like it.

> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index d55e361..bad244c 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -3023,13 +3023,8 @@ clear_symtab_users (int add_flags)
>    /* Someday, we should do better than this, by only blowing away
>       the things that really need to be blown.  */
>  
> -  /* Clear the "current" symtab first, because it is no longer valid.
> -     breakpoint_re_set may try to access the current symtab.  */
>    clear_current_source_symtab_and_line ();
> -
>    clear_displays ();
> -  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
> -    breakpoint_re_set ();
>    clear_last_displayed_sal ();
>    clear_pc_function_cache ();
>    observer_notify_new_objfile (NULL);
> @@ -3040,9 +3035,19 @@ clear_symtab_users (int add_flags)
>    expression_context_block = NULL;
>    innermost_block = NULL;
>  
> +  /* Now that most everything has been reset, reset any existing breakpoints.
> +     Reasons for doing this after the above are that breakpoint resetting may
> +     involve:
> +     - reading the current source symtab and line,
> +     - reading the last displayed sal,
> +     - reading the pc function cache,
> +     - symbol lookup which requires, for example, invalidating any caches
> +       first.  */
> +  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
> +    breakpoint_re_set ();
> +
>    /* Varobj may refer to old symbols, perform a cleanup.  */
>    varobj_invalidate ();
> -
>  }
>  
>  static void
> 
> 
> 

-- 
Joel

[-- Attachment #2: bp-re-set.diff --]
[-- Type: text/x-diff, Size: 789 bytes --]

diff --git a/gdb/symfile.c b/gdb/symfile.c
index d55e361..04a5c58 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3028,8 +3028,6 @@ clear_symtab_users (int add_flags)
   clear_current_source_symtab_and_line ();
 
   clear_displays ();
-  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
-    breakpoint_re_set ();
   clear_last_displayed_sal ();
   clear_pc_function_cache ();
   observer_notify_new_objfile (NULL);
@@ -3043,6 +3041,10 @@ clear_symtab_users (int add_flags)
   /* Varobj may refer to old symbols, perform a cleanup.  */
   varobj_invalidate ();
 
+  /* Now that the various caches have been cleared, we can re_set
+     our breakpoints without risking it using stale data.  */
+  if ((add_flags & SYMFILE_DEFER_BP_RESET) == 0)
+    breakpoint_re_set ();
 }
 
 static void

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

* Re: [PATCH][PR symtab/17855] Fix.
  2015-01-29  8:12     ` Joel Brobecker
@ 2015-01-29 10:01       ` Doug Evans
       [not found]         ` <m3r3ualkvb.fsf@sspiff.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Doug Evans @ 2015-01-29 10:01 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Pedro Alves, gdb-patches

On Wed, Jan 28, 2015 at 11:19 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> Aargh - I was working on it just now because I wasn't sure if anyone
> felt they "had the ball on their court".
>
>> Like so?
>>
>> 2015-01-28  Doug Evans  <xdje42@gmail.com>
>>
>>       PR symtab/17855
>>       * symfile.c (clear_symtab_users): Move call to breakpoint_re_set
>>       closer to end.
>
> What I've tested is moving the call last, as shown in the attached
> diff.  Not technically necessarily better, but as the comment explains,
> I move it last so that it's after we've purged all relevant caches.
> That way, the function is organized in two rough sections:
>   - do purges first;
>   - do updates next.
> Your comment is a lot more detailed, I like it.

I think yours is fine too.
I'm ok with using it.

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

* Re: [PATCH][PR symtab/17855] Fix.
       [not found]         ` <m3r3ualkvb.fsf@sspiff.org>
@ 2015-02-03 17:02           ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2015-02-03 17:02 UTC (permalink / raw)
  To: Doug Evans, Joel Brobecker; +Cc: gdb-patches

On 01/31/2015 10:07 PM, Doug Evans wrote:
> Doug Evans <xdje42@gmail.com> writes:
>> On Wed, Jan 28, 2015 at 11:19 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>>> Your comment is a lot more detailed, I like it.
>>
>> I think yours is fine too.
>> I'm ok with using it.
> 
> Hi.
> There's value in the simplicity of your approach so I
> committed it to trunk and the branch.
> 

Thanks guys.

Pedro Alves

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

end of thread, other threads:[~2015-02-03 17:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20  6:27 [PATCH][PR symtab/17855] Fix Doug Evans
2015-01-22 11:42 ` Pedro Alves
2015-01-22 15:37   ` Doug Evans
2015-01-29  8:00   ` Doug Evans
2015-01-29  8:12     ` Joel Brobecker
2015-01-29 10:01       ` Doug Evans
     [not found]         ` <m3r3ualkvb.fsf@sspiff.org>
2015-02-03 17:02           ` 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).