mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-09-28 01:47:19 +08:00

As mentioned in commit bf93d7ba9931 ("Add thread after updating gdbarch when exec'ing"), we should avoid doing register reads after a process does an exec and before we've updated that inferior's gdbarch. Otherwise, we may interpret the registers using the wrong architecture. There's still (at least) one case where we still read registers post-exec with the pre-exec architecture. That's when infrun decides it needs to switch context to the exec'ing thread. I.e., if the exec event is processed at a time when the current thread is not already the exec'ing thread, then we get (with the test added by this commit): continue Continuing. Truncated register 50 in remote 'g' packet Truncated register 50 in remote 'g' packet (gdb) FAIL: gdb.multi/multi-arch-exec.exp: selected_thread=2: follow_exec_mode=same: continue across exec that changes architecture The fix is to avoid reading registers when switching context in this case. (I'd be nice to get rid of the constant stop_pc reading when switching threads, but that'd be a deeper change.) gdb/ChangeLog: 2017-10-09 Pedro Alves <palves@redhat.com> * infrun.c (handle_inferior_event_1) <TARGET_WAITKIND_EXECD>: Skip reading registers when switching context. gdb/testsuite/ChangeLog: 2017-10-09 Pedro Alves <palves@redhat.com> * gdb.multi/multi-arch-exec.c: Include <pthread.h> and <assert.h>. (barrier): New. (thread_start, all_started): New functions. (main): Spawn new thread and wait until it is scheduled. * gdb.multi/multi-arch-exec.exp: Build $srcfile1 with the pthreads option. (do_test): Add 'selected_thread' parameter. Run to all_started instead of main. Explicitly set the breakpoint at main. Switch to the SELECTED_THREAD thread. (top level): Test handling the exec event with either the main thread or the second thread selected.
69 lines
1.6 KiB
C
69 lines
1.6 KiB
C
/* This testcase is part of GDB, the GNU debugger.
|
|
|
|
Copyright 2012-2017 Free Software Foundation, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <limits.h>
|
|
#include <string.h>
|
|
#include <pthread.h>
|
|
|
|
#define NUM_THREADS 1
|
|
|
|
static pthread_barrier_t barrier;
|
|
|
|
static void *
|
|
thread_start (void *arg)
|
|
{
|
|
pthread_barrier_wait (&barrier);
|
|
|
|
while (1)
|
|
sleep (1);
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
all_started (void)
|
|
{
|
|
}
|
|
|
|
int
|
|
main (int argc, char ** argv)
|
|
{
|
|
char prog[PATH_MAX];
|
|
pthread_t thread;
|
|
int len;
|
|
|
|
strcpy (prog, argv[0]);
|
|
len = strlen (prog);
|
|
/* Replace "multi-arch-exec" with "multi-arch-exec-hello". */
|
|
memcpy (prog + len - 15, "multi-arch-exec-hello", 21);
|
|
prog[len + 6] = 0;
|
|
|
|
pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1);
|
|
pthread_create (&thread, NULL, thread_start, NULL);
|
|
|
|
pthread_barrier_wait (&barrier);
|
|
all_started ();
|
|
|
|
execl (prog,
|
|
prog,
|
|
(char *) NULL);
|
|
perror ("execl failed");
|
|
exit (1);
|
|
}
|