--- mi/mi-main.1.c Wed Oct 16 17:02:32 2002 +++ mi/mi-main.c Thu Oct 17 14:08:41 2002 @@ -40,6 +40,8 @@ #include "regcache.h" #include "gdb.h" #include "frame.h" +#include "command.h" /* for dont_repeat */ +#include "symfile.h" /* for symbol_file_add_main */ #include #include @@ -752,6 +754,90 @@ mi_out_rewind (uiout); fputs_unfiltered ("\n", raw_stdout); do_exec_cleanups (ALL_CLEANUPS); + return MI_CMD_QUIET; +} + +/* Attach a program either by pid or filename */ +enum mi_cmd_result +mi_cmd_target_attach (char *command, char **argv, int argc) +{ + char *exec_file; + char *full_exec_path = NULL; + + dont_repeat (); /* Not for the faint of heart */ + + if (argc == 0 || argc > 1) + error ("mi_cmd_target_attach: Usage -target-attach | "); + + if (target_has_execution) + target_kill (); /* we kill any existing program being debugged */ + + target_attach (argv[0], FROM_TTY); + + /* Set up the "saved terminal modes" of the inferior + based on what modes we are starting it with. */ + target_terminal_init (); + + /* Install inferior's terminal modes. */ + target_terminal_inferior (); + + /* Set up execution context to know that we should return from + wait_for_inferior as soon as the target reports a stop. */ + init_wait_for_inferior (); + clear_proceed_status (); + + /* No traps are generated when attaching to inferior under Mach 3 + or GNU hurd. */ +#ifndef ATTACH_NO_WAIT + stop_soon_quietly = 1; + wait_for_inferior (); +#endif + + /* + * If no exec file is yet known, try to determine it from the + * process itself. + */ + exec_file = (char *) get_exec_file (0); + if (!exec_file) + { + exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid)); + if (exec_file) + { + /* It's possible we don't have a full path, but rather just a + filename. Some targets, such as HP-UX, don't provide the + full path, sigh. + + Attempt to qualify the filename against the source path. + (If that fails, we'll just fall back on the original + filename. Not much more we can do...) + */ + if (!source_full_path_of (exec_file, &full_exec_path)) + full_exec_path = savestring (exec_file, strlen (exec_file)); + + exec_file_attach (full_exec_path, FROM_TTY); + symbol_file_add_main (full_exec_path, FROM_TTY); + } + } + +#ifdef SOLIB_ADD + /* Add shared library symbols from the newly attached process, if any. */ + SOLIB_ADD ((char *) 0, FROM_TTY, ¤t_target, auto_solib_add); + re_enable_breakpoints_in_shlibs (); +#endif + + /* Take any necessary post-attaching actions for this platform. + */ + target_post_attach (PIDGET (inferior_ptid)); + + normal_stop (); + + if (attach_hook) + attach_hook (); + + fputs_unfiltered ("^attached", raw_stdout); + mi_out_put (uiout, raw_stdout); + mi_out_rewind (uiout); + fputs_unfiltered ("\n", raw_stdout); return MI_CMD_QUIET; } --- mi/gdbmi.0.texinfo Thu Oct 17 14:23:25 2002 +++ mi/gdbmi.texinfo Thu Oct 17 14:22:49 2002 @@ -3073,8 +3073,13 @@ The corresponding @value{GDBN} command is @samp{attach}. @subsubheading Example -N.A. +@smallexample +(@value{GDBP}) +-target-attach 4567 +^attached,thread-id="0",frame={addr="0x08048365",func="main",args=[],file="infloop.c",line="12"} +(@value{GDBP}) +@end smallexample @subheading The @code{-target-compare-sections} Command @findex -target-compare-sections --- mi/mi-cmds.0.h Wed Oct 16 17:34:22 2002 +++ mi/mi-cmds.h Wed Oct 16 17:35:36 2002 @@ -84,6 +84,7 @@ extern mi_cmd_argv_ftype mi_cmd_stack_list_frames; extern mi_cmd_argv_ftype mi_cmd_stack_list_locals; extern mi_cmd_argv_ftype mi_cmd_stack_select_frame; +extern mi_cmd_argv_ftype mi_cmd_target_attach; extern mi_cmd_args_ftype mi_cmd_target_download; extern mi_cmd_args_ftype mi_cmd_target_select; extern mi_cmd_argv_ftype mi_cmd_thread_list_ids;