diff options
author | Pedro Alves <palves@redhat.com> | 2014-05-21 18:30:47 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2014-05-21 18:30:47 +0100 |
commit | 6a3cb8e88a739c967bb9b2d8774bf96b87a7fda4 (patch) | |
tree | 6d970aa7cd42ad75c1a475f4b8265b31959a709e /gdb/nto-procfs.c | |
parent | 930ee1b1bf8c36a746ea5f7456afba094aabc887 (diff) | |
download | gdb-6a3cb8e88a739c967bb9b2d8774bf96b87a7fda4.zip gdb-6a3cb8e88a739c967bb9b2d8774bf96b87a7fda4.tar.gz gdb-6a3cb8e88a739c967bb9b2d8774bf96b87a7fda4.tar.bz2 |
Allow making GDB not automatically connect to the native target.
Sometimes it's useful to be able to disable the automatic connection
to the native target. E.g., sometimes GDB disconnects from the
extended-remote target I was debugging, without me noticing it, and
then I do "run". That starts the program locally, and only after a
little head scratch session do I figure out the program is running
locally instead of remotely as intended. Same thing with "attach",
"info os", etc.
With the patch, we now can have this instead:
(gdb) set auto-connect-native-target off
(gdb) target extended-remote :9999
...
*gdb disconnects*
(gdb) run
Don't know how to run. Try "help target".
To still be able to connect to the native target with
auto-connect-native-target set to off, I've made "target native" work
instead of erroring out as today.
Before:
(gdb) target native
Use the "run" command to start a native process.
After:
(gdb) target native
Done. Use the "run" command to start a process.
(gdb) maint print target-stack
The current target stack is:
- native (Native process)
- exec (Local exec file)
- None (None)
(gdb) run
Starting program: ./a.out
...
I've also wanted this for the testsuite, when running against the
native-extended-gdbserver.exp board (runs against gdbserver in
extended-remote mode). With a non-native-target board, it's always a
bug to launch a program with the native target. Turns out we still
have one such case this patch catches:
(gdb) break main
Breakpoint 1 at 0x4009e5: file ../../../src/gdb/testsuite/gdb.base/coremaker.c, line 138.
(gdb) run
Don't know how to run. Try "help target".
(gdb) FAIL: gdb.base/corefile.exp: run: with core
On the patch itself, probably the least obvious bit is the need to go
through all targets, and move the unpush_target call to after the
generic_mourn_inferior call instead of before. This is what
inf-ptrace.c does too, ever since multi-process support was added.
The reason inf-ptrace.c does things in that order is that in the
current multi-process/single-target model, we shouldn't unpush the
target if there are still other live inferiors being debugged. The
check for that is "have_inferiors ()" (a misnomer nowadays...), which
does:
have_inferiors (void)
{
for (inf = inferior_list; inf; inf = inf->next)
if (inf->pid != 0)
return 1;
It's generic_mourn_inferior that ends up clearing inf->pid, so we need
to call it before the have_inferiors check. To make all native
targets behave the same WRT to explicit "target native", I've added an
inf_child_maybe_unpush_target function that targets call instead of
calling unpush_target directly, and as that includes the
have_inferiors check, I needed to adjust the targets.
Tested on x86_64 Fedora 20, native, and also with the
extended-gdbserver board.
Confirmed a cross build of djgpp gdb still builds.
Smoke tested a cross build of Windows gdb under Wine.
Untested otherwise.
gdb/
2014-05-21 Pedro Alves <palves@redhat.com>
* inf-child.c (inf_child_ops, inf_child_explicitly_opened): New
globals.
(inf_child_open_target): New function.
(inf_child_open): Use inf_child_open_target to push the target
instead of erroring out.
(inf_child_disconnect, inf_child_close)
(inf_child_maybe_unpush_target): New functions.
(inf_child_target): Install inf_child_disconnect and
inf_child_close. Store a pointer to the returned object.
* inf-child.h (inf_child_open_target, inf_child_maybe_unpush): New
declarations.
* target.c (auto_connect_native_target): New global.
(show_default_run_target): New function.
(find_default_run_target): Return NULL if automatically connecting
to the native target is disabled.
(_initialize_target): Install set/show auto-connect-native-target.
* NEWS: Mention "set auto-connect-native-target", and "target
native".
* linux-nat.c (super_close): New global.
(linux_nat_close): Call super_close.
(linux_nat_add_target): Store a pointer to the base class's
to_close method.
* inf-ptrace.c (inf_ptrace_mourn_inferior, inf_ptrace_detach): Use
inf_child_maybe_unpush.
* inf-ttrace.c (inf_ttrace_him): Don't push the target if it is
already pushed.
(inf_ttrace_mourn_inferior): Only unpush the target after mourning
the inferior. Use inf_child_maybe_unpush_target.
(inf_ttrace_attach): Don't push the target if it is already
pushed.
(inf_ttrace_detach): Use inf_child_maybe_unpush_target.
* darwin-nat.c (darwin_mourn_inferior): Only unpush the target
after mourning the inferior. Use inf_child_maybe_unpush_target.
(darwin_attach_pid): Don't push the target if it is already
pushed.
* gnu-nat.c (gnu_mourn_inferior): Only unpush the target after
mourning the inferior. Use inf_child_maybe_unpush_target.
(gnu_detach): Use inf_child_maybe_unpush_target.
* go32-nat.c (go32_create_inferior): Don't push the target if it
is already pushed.
(go32_mourn_inferior): Use inf_child_maybe_unpush_target.
* nto-procfs.c (procfs_is_nto_target): Adjust comment.
(procfs_open): Rename to ...
(procfs_open_1): ... this. Add target_ops parameter. Adjust
comments. Can target_preopen before changing node. Call
inf_child_open_target to push the target explicitly.
(procfs_attach): Don't push the target if it is already pushed.
(procfs_detach): Use inf_child_maybe_unpush_target.
(procfs_create_inferior): Don't push the target if it is already
pushed.
(nto_native_ops): New global.
(procfs_open): Reimplement.
(procfs_native_open): New function.
(init_procfs_targets): Install procfs_native_open as to_open of
"target native". Store a pointer to the "native" target in
nto_native_ops.
* procfs.c (procfs_attach): Don't push the target if it is already
pushed.
(procfs_detach): Use inf_child_maybe_unpush_target.
(procfs_mourn_inferior): Only unpush the target after mourning the
inferior. Use inf_child_maybe_unpush_target.
(procfs_init_inferior): Don't push the target if it is already
pushed.
* windows-nat.c (do_initial_windows_stuff): Don't push the target
if it is already pushed.
(windows_detach): Use inf_child_maybe_unpush_target.
(windows_mourn_inferior): Only unpush the target after mourning
the inferior. Use inf_child_maybe_unpush_target.
gdb/doc/
2014-05-21 Pedro Alves <palves@redhat.com>
* gdb.texinfo (Starting): Document "set/show
auto-connect-native-target".
(Target Commands): Document "target native".
gdb/testsuite/
2014-05-21 Pedro Alves <palves@redhat.com>
* boards/gdbserver-base.exp (GDBFLAGS): Set to "set
auto-connect-native-target off".
* gdb.base/auto-connect-native-target.c: New file.
* gdb.base/auto-connect-native-target.exp: New file.
Diffstat (limited to 'gdb/nto-procfs.c')
-rw-r--r-- | gdb/nto-procfs.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index b328dfa..8a241a8 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -54,8 +54,6 @@ static void (*ofunc) (); static procfs_run run; -static void procfs_open (char *, int); - static ptid_t do_attach (ptid_t ptid); static int procfs_can_use_hw_breakpoint (struct target_ops *self, @@ -71,7 +69,7 @@ static int procfs_remove_hw_watchpoint (struct target_ops *self, static int procfs_stopped_by_watchpoint (struct target_ops *ops); -/* These two globals are only ever set in procfs_open(), but are +/* These two globals are only ever set in procfs_open_1, but are referenced elsewhere. 'nto_procfs_node' is a flag used to say whether we are local, or we should get the current node descriptor for the remote QNX node. */ @@ -103,12 +101,12 @@ procfs_is_nto_target (bfd *abfd) return GDB_OSABI_QNXNTO; } -/* This is called when we call 'target procfs <arg>' from the (gdb) prompt. - For QNX6 (nto), the only valid arg will be a QNX node string, - eg: "/net/some_node". If arg is not a valid QNX node, we will - default to local. */ +/* This is called when we call 'target native' or 'target procfs + <arg>' from the (gdb) prompt. For QNX6 (nto), the only valid arg + will be a QNX node string, eg: "/net/some_node". If arg is not a + valid QNX node, we will default to local. */ static void -procfs_open (char *arg, int from_tty) +procfs_open_1 (struct target_ops *ops, char *arg, int from_tty) { char *nodestr; char *endstr; @@ -117,6 +115,9 @@ procfs_open (char *arg, int from_tty) procfs_sysinfo *sysinfo; struct cleanup *cleanups; + /* Offer to kill previous inferiors before opening this target. */ + target_preopen (from_tty); + nto_is_nto_target = procfs_is_nto_target; /* Set the default node used for spawning to this one, @@ -197,6 +198,8 @@ procfs_open (char *arg, int from_tty) } } do_cleanups (cleanups); + + inf_child_open_target (ops, arg, from_tty); printf_filtered ("Debugging using %s\n", nto_procfs_path); } @@ -628,7 +631,8 @@ procfs_attach (struct target_ops *ops, char *args, int from_tty) inferior_appeared (inf, pid); inf->attach_flag = 1; - push_target (ops); + if (!target_is_pushed (ops)) + push_target (ops); procfs_find_new_threads (ops); } @@ -904,7 +908,7 @@ procfs_detach (struct target_ops *ops, const char *args, int from_tty) inferior_ptid = null_ptid; detach_inferior (pid); init_thread_list (); - unpush_target (ops); /* Pop out of handling an inferior. */ + inf_child_maybe_unpush_target (ops); } static int @@ -1023,8 +1027,8 @@ procfs_mourn_inferior (struct target_ops *ops) } inferior_ptid = null_ptid; init_thread_list (); - unpush_target (ops); generic_mourn_inferior (); + inf_child_maybe_unpush_target (ops); } /* This function breaks up an argument string into an argument @@ -1207,7 +1211,8 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file, /* warning( "Failed to set Kill-on-Last-Close flag: errno = %d(%s)\n", errn, strerror(errn) ); */ } - push_target (ops); + if (!target_is_pushed (ops)) + push_target (ops); target_terminal_init (); if (exec_bfd != NULL @@ -1385,6 +1390,25 @@ procfs_can_run (struct target_ops *self) /* "target procfs". */ static struct target_ops nto_procfs_ops; +/* "target native". */ +static struct target_ops *nto_native_ops; + +/* to_open implementation for "target procfs". */ + +static void +procfs_open (char *arg, int from_tty) +{ + procfs_open_1 (&nto_procfs_ops, arg, from_tty); +} + +/* to_open implementation for "target native". */ + +static void +procfs_native_open (char *arg, int from_tty) +{ + procfs_open_1 (nto_native_ops, arg, from_tty); +} + /* Create the "native" and "procfs" targets. */ static void @@ -1395,7 +1419,7 @@ init_procfs_targets (void) /* Leave to_shortname as "native". */ t->to_longname = "QNX Neutrino local process"; t->to_doc = "QNX Neutrino local process (started by the \"run\" command)."; - t->to_open = procfs_open; + t->to_open = procfs_native_open; t->to_attach = procfs_attach; t->to_post_attach = procfs_post_attach; t->to_detach = procfs_detach; @@ -1424,6 +1448,8 @@ init_procfs_targets (void) t->to_have_continuable_watchpoint = 1; t->to_extra_thread_info = nto_extra_thread_info; + nto_native_ops = t; + /* Register "target native". This is the default run target. */ add_target (t); @@ -1433,6 +1459,8 @@ init_procfs_targets (void) nto_procfs_ops.to_can_run = procfs_can_run; t->to_longname = "QNX Neutrino local or remote process"; t->to_doc = "QNX Neutrino process. target procfs <node>"; + t->to_open = procfs_open; + add_target (&nto_procfs_ops); } |