This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Get rid of previous targets in target_preopen.
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 11 Aug 2008 14:16:21 +0100
- Subject: Get rid of previous targets in target_preopen.
Here is a patch that fixes the issues I noticed here:
[usefulness of "you won't be able to access this core file until you
terminate your ..."]
http://sourceware.org/ml/gdb-patches/2008-08/msg00290.html
This patch depends on this other patch, that is pending review:
[Fix crash on "quit" + TUI + remote + async]
http://sourceware.org/ml/gdb-patches/2008-07/msg00516.html
As I somewhat mentioned in former email above, the fix is to get
rid of all targets above the exec target in target_preopen.
I tested this on OpenBSD where switching between a
multi-threaded/bsd-uthreads core, to a single-threaded core,
now behaves as expected.
On linux, the thread_db thread_stratum layer is never used when
reading cores, but I confirmed that nothing broke when
switching between several targets (running -> ST core, ST core ->
running, MT core -> ST core, etc..).
Also confirmed that on OpenSolaris, overrides the standard corelow.c
core_stratum. Behaviour didn't change.
Also confirmed that the case of going extended-remote -> core
file now doesn't throw any error, and behaves as expected.
Also ran the testsuite on x86_64-unknown-linux-gnu, and
i386-unknown-openbsd4.3, with no regressions.
This is a prerequisite patch for making the corelow target
always register at least one thread/task.
--
Pedro Alves
2008-08-11 Pedro Alves <pedro@codesourcery.com>
* corelow.c (core_open): Assume there was no upper layer left
behind from a previous inferior.
* target.c (pop_all_targets): Rename to ...
(pop_all_targets_above): ... this. Add a target stratum
parameter. Use it instead of hardcoding the dummy_stratum.
(pop_all_targets): New, defer to pop_all_targets_above.
(target_preopen): Use pop_all_targets_above.
* target.h (target_stratum): New.
(pop_all_targets_above): Declare.
---
gdb/corelow.c | 22 ++++++----------------
gdb/target.c | 16 +++++++++++-----
gdb/target.h | 6 ++++++
3 files changed, 23 insertions(+), 21 deletions(-)
Index: src/gdb/corelow.c
===================================================================
--- src.orig/gdb/corelow.c 2008-08-11 12:21:49.000000000 +0100
+++ src/gdb/corelow.c 2008-08-11 14:04:20.000000000 +0100
@@ -258,7 +258,6 @@ core_open (char *filename, int from_tty)
struct cleanup *old_chain;
char *temp;
bfd *temp_bfd;
- int ontop;
int scratch_chan;
int flags;
@@ -341,7 +340,7 @@ core_open (char *filename, int from_tty)
if (!exec_bfd)
set_gdbarch_from_file (core_bfd);
- ontop = !push_target (&core_ops);
+ push_target (&core_ops);
discard_cleanups (old_chain);
/* This is done first, before anything has a chance to query the
@@ -368,21 +367,12 @@ core_open (char *filename, int from_tty)
bfd_map_over_sections (core_bfd, add_to_thread_list,
bfd_get_section_by_name (core_bfd, ".reg"));
- if (ontop)
- {
- /* Fetch all registers from core file. */
- target_fetch_registers (get_current_regcache (), -1);
+ /* Fetch all registers from core file. */
+ target_fetch_registers (get_current_regcache (), -1);
- /* Now, set up the frame cache, and print the top of stack. */
- reinit_frame_cache ();
- print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
- }
- else
- {
- warning (
- "you won't be able to access this core file until you terminate\n\
-your %s; do ``info files''", target_longname);
- }
+ /* Now, set up the frame cache, and print the top of stack. */
+ reinit_frame_cache ();
+ print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
}
static void
Index: src/gdb/target.c
===================================================================
--- src.orig/gdb/target.c 2008-08-11 12:21:49.000000000 +0100
+++ src/gdb/target.c 2008-08-11 14:04:33.000000000 +0100
@@ -822,9 +822,9 @@ pop_target (void)
}
void
-pop_all_targets (int quitting)
+pop_all_targets_above (enum strata above_stratum, int quitting)
{
- while ((int) (current_target.to_stratum) > (int) dummy_stratum)
+ while ((int) (current_target.to_stratum) > (int) above_stratum)
{
target_close (¤t_target, quitting);
if (!unpush_target (target_stack))
@@ -839,6 +839,12 @@ pop_all_targets (int quitting)
}
}
+void
+pop_all_targets (int quitting)
+{
+ pop_all_targets_above (dummy_stratum, quitting);
+}
+
/* Using the objfile specified in OBJFILE, find the address for the
current thread's thread-local storage with offset OFFSET. */
CORE_ADDR
@@ -1778,9 +1784,9 @@ target_preopen (int from_tty)
/* Calling target_kill may remove the target from the stack. But if
it doesn't (which seems like a win for UDI), remove it now. */
-
- if (target_has_execution)
- pop_target ();
+ /* Leave the exec target, though. The user may be switching from a
+ live process to a core of the same program. */
+ pop_all_targets_above (file_stratum, 0);
target_pre_inferior (from_tty);
}
Index: src/gdb/target.h
===================================================================
--- src.orig/gdb/target.h 2008-08-11 12:21:49.000000000 +0100
+++ src/gdb/target.h 2008-08-11 12:22:14.000000000 +0100
@@ -543,6 +543,8 @@ extern struct target_ops current_target;
#define target_shortname (current_target.to_shortname)
#define target_longname (current_target.to_longname)
+#define target_stratum (current_target.to_stratum)
+
/* Does whatever cleanup is required for a target that we are no
longer going to be calling. QUITTING indicates that GDB is exiting
and should not get hung on an error (otherwise it is important to
@@ -1179,6 +1181,10 @@ extern void pop_target (void);
while). */
extern void pop_all_targets (int quitting);
+/* Like pop_all_targets, but pops only targets whose stratum is
+ strictly above ABOVE_STRATUM. */
+extern void pop_all_targets_above (enum strata above_stratum, int quitting);
+
extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
CORE_ADDR offset);