|
|
861f93 |
http://sourceware.org/ml/gdb-patches/2012-04/msg00058.html
|
|
|
861f93 |
Subject: [downstream patch FYI] workaround stale frame_info * (PR 13866)
|
|
|
861f93 |
|
|
|
861f93 |
Hi,
|
|
|
861f93 |
|
|
|
861f93 |
I did not look at which commit caused this regression but apparently it was
|
|
|
861f93 |
introduced at least with multi-inferiors.
|
|
|
861f93 |
|
|
|
861f93 |
I understand this fix is not right fix of the crash; but in most GDB cases one
|
|
|
861f93 |
does not use multi-inferior so why to regress single-inferior by it.
|
|
|
861f93 |
Some more simple solutions still fix the single-inferior mode but they
|
|
|
861f93 |
regressed the multi-inferior mode
|
|
|
861f93 |
gdb.threads/no-unwaited-for-left.exp
|
|
|
861f93 |
gdb.multi/base.exp
|
|
|
861f93 |
so I had to put there that sorting magic.
|
|
|
861f93 |
|
|
|
861f93 |
With proper C++ sanity check of stale live frame_info references the testcase
|
|
|
861f93 |
would be simple without the "frame_garbage_collection" reproducer below.
|
|
|
861f93 |
It is also reproducible just with valgrind but regularly running the whole
|
|
|
861f93 |
testsuite under valgrind I did not find feasible.
|
|
|
861f93 |
|
|
|
861f93 |
No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu.
|
|
|
861f93 |
|
|
|
861f93 |
|
|
|
861f93 |
Thanks,
|
|
|
861f93 |
Jan
|
|
|
861f93 |
|
|
|
861f93 |
|
|
|
861f93 |
gdb/
|
|
|
861f93 |
2012-04-04 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
861f93 |
|
|
|
861f93 |
Workaround PR backtrace/13866.
|
|
|
861f93 |
* progspace.c (switch_to_program_space_and_thread): Try not to call
|
|
|
861f93 |
switch_to_thread.
|
|
|
861f93 |
|
|
|
861f93 |
--- a/gdb/progspace.c
|
|
|
861f93 |
+++ b/gdb/progspace.c
|
|
|
861f93 |
@@ -481,17 +481,28 @@ save_current_space_and_thread (void)
|
|
|
861f93 |
void
|
|
|
861f93 |
switch_to_program_space_and_thread (struct program_space *pspace)
|
|
|
861f93 |
{
|
|
|
861f93 |
- struct inferior *inf;
|
|
|
861f93 |
+ struct inferior *inf = current_inferior ();
|
|
|
861f93 |
|
|
|
861f93 |
- inf = find_inferior_for_program_space (pspace);
|
|
|
861f93 |
+ if (inf->pspace != pspace)
|
|
|
861f93 |
+ inf = find_inferior_for_program_space (pspace);
|
|
|
861f93 |
if (inf != NULL)
|
|
|
861f93 |
{
|
|
|
861f93 |
- struct thread_info *tp;
|
|
|
861f93 |
+ struct thread_info *tp, *current_tp = NULL;
|
|
|
861f93 |
+
|
|
|
861f93 |
+ if (ptid_get_pid (inferior_ptid) == inf->pid)
|
|
|
861f93 |
+ current_tp = find_thread_ptid (inferior_ptid);
|
|
|
861f93 |
|
|
|
861f93 |
tp = any_live_thread_of_process (inf->pid);
|
|
|
861f93 |
if (tp != NULL)
|
|
|
861f93 |
{
|
|
|
861f93 |
- switch_to_thread (tp->ptid);
|
|
|
861f93 |
+ /* Prefer primarily thread not THREAD_EXITED and secondarily thread
|
|
|
861f93 |
+ not EXECUTING. */
|
|
|
861f93 |
+ if (current_tp == NULL
|
|
|
861f93 |
+ || (tp->state != THREAD_EXITED
|
|
|
861f93 |
+ && current_tp->state == THREAD_EXITED)
|
|
|
861f93 |
+ || (!tp->executing && current_tp->executing))
|
|
|
861f93 |
+ switch_to_thread (tp->ptid);
|
|
|
861f93 |
+
|
|
|
861f93 |
/* Switching thread switches pspace implicitly. We're
|
|
|
861f93 |
done. */
|
|
|
861f93 |
return;
|
|
|
861f93 |
|
|
|
861f93 |
|
|
|
861f93 |
Reproducer with:
|
|
|
861f93 |
./gdb -nx ~/t/thread -ex 'b 24' -ex r -ex 'until 25'
|
|
|
861f93 |
Breakpoint 1, main () at /home/jkratoch/t/thread.c:24
|
|
|
861f93 |
24 v++;
|
|
|
861f93 |
Segmentation fault (core dumped)
|
|
|
861f93 |
|
|
|
861f93 |
#include <pthread.h>
|
|
|
861f93 |
#include <assert.h>
|
|
|
861f93 |
#include <unistd.h>
|
|
|
861f93 |
|
|
|
861f93 |
static int v;
|
|
|
861f93 |
|
|
|
861f93 |
static void *start (void *arg)
|
|
|
861f93 |
{
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
sleep (100);
|
|
|
861f93 |
return arg;
|
|
|
861f93 |
}
|
|
|
861f93 |
|
|
|
861f93 |
int main (void)
|
|
|
861f93 |
{
|
|
|
861f93 |
pthread_t thread1;
|
|
|
861f93 |
int i;
|
|
|
861f93 |
|
|
|
861f93 |
i = pthread_create (&thread1, NULL, start, NULL);
|
|
|
861f93 |
assert (i == 0);
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
v++;
|
|
|
861f93 |
i = pthread_join (thread1, NULL);
|
|
|
861f93 |
assert (i == 0);
|
|
|
861f93 |
|
|
|
861f93 |
return 0;
|
|
|
861f93 |
}
|
|
|
861f93 |
### --- a/gdb/frame.c
|
|
|
861f93 |
### +++ b/gdb/frame.c
|
|
|
861f93 |
### @@ -1522,12 +1522,30 @@ frame_observer_target_changed (struct target_ops *target)
|
|
|
861f93 |
### reinit_frame_cache ();
|
|
|
861f93 |
### }
|
|
|
861f93 |
###
|
|
|
861f93 |
### +typedef struct obstack obstack_s;
|
|
|
861f93 |
### +DEF_VEC_O (obstack_s);
|
|
|
861f93 |
### +static VEC (obstack_s) *frame_poison_vec;
|
|
|
861f93 |
### +
|
|
|
861f93 |
### +void frame_garbage_collection (void);
|
|
|
861f93 |
### +void
|
|
|
861f93 |
### +frame_garbage_collection (void)
|
|
|
861f93 |
### +{
|
|
|
861f93 |
### + struct obstack *obstack_p;
|
|
|
861f93 |
### + int ix;
|
|
|
861f93 |
### +
|
|
|
861f93 |
### + for (ix = 0; VEC_iterate (obstack_s, frame_poison_vec, ix, obstack_p); ix++)
|
|
|
861f93 |
### + obstack_free (obstack_p, 0);
|
|
|
861f93 |
### +
|
|
|
861f93 |
### + VEC_free (obstack_s, frame_poison_vec);
|
|
|
861f93 |
### + frame_poison_vec = NULL;
|
|
|
861f93 |
### +}
|
|
|
861f93 |
### +
|
|
|
861f93 |
### /* Flush the entire frame cache. */
|
|
|
861f93 |
###
|
|
|
861f93 |
### void
|
|
|
861f93 |
### reinit_frame_cache (void)
|
|
|
861f93 |
### {
|
|
|
861f93 |
### - struct frame_info *fi;
|
|
|
861f93 |
### + struct frame_info *fi, *fi_prev;
|
|
|
861f93 |
###
|
|
|
861f93 |
### /* Tear down all frame caches. */
|
|
|
861f93 |
### for (fi = current_frame; fi != NULL; fi = fi->prev)
|
|
|
861f93 |
### @@ -1538,8 +1556,14 @@ reinit_frame_cache (void)
|
|
|
861f93 |
### fi->base->unwind->dealloc_cache (fi, fi->base_cache);
|
|
|
861f93 |
### }
|
|
|
861f93 |
###
|
|
|
861f93 |
### + for (fi = current_frame; fi != NULL; fi = fi_prev)
|
|
|
861f93 |
### + {
|
|
|
861f93 |
### + fi_prev = fi->prev;
|
|
|
861f93 |
### + memset (fi, 0, sizeof (*fi));
|
|
|
861f93 |
### + }
|
|
|
861f93 |
### + VEC_safe_push (obstack_s, frame_poison_vec, &frame_cache_obstack);
|
|
|
861f93 |
### +
|
|
|
861f93 |
### /* Since we can't really be sure what the first object allocated was. */
|
|
|
861f93 |
### - obstack_free (&frame_cache_obstack, 0);
|
|
|
861f93 |
### obstack_init (&frame_cache_obstack);
|
|
|
861f93 |
###
|
|
|
861f93 |
### if (current_frame != NULL)
|
|
|
861f93 |
### --- a/gdb/top.c
|
|
|
861f93 |
### +++ b/gdb/top.c
|
|
|
861f93 |
### @@ -359,6 +359,11 @@ prepare_execute_command (void)
|
|
|
861f93 |
### if (non_stop)
|
|
|
861f93 |
### target_dcache_invalidate ();
|
|
|
861f93 |
###
|
|
|
861f93 |
### + {
|
|
|
861f93 |
### + extern void frame_garbage_collection (void);
|
|
|
861f93 |
### + frame_garbage_collection ();
|
|
|
861f93 |
### + }
|
|
|
861f93 |
### +
|
|
|
861f93 |
### return cleanup;
|
|
|
861f93 |
### }
|
|
|
861f93 |
###
|