This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Multiexec MI


On Wednesday 13 January 2010 20:29:30, Vladimir Prus wrote:
> This patch implements MI support for multiexec. I attach my notes on design, as well
> as patch. The patch also contains documentation updates.
> 
> The executive summary is:
> * thread groups of types 'process' are redefined to mean inferior, and therefore
> Â can exist before process is started, and outlive the process.
> * The --thread-group option, previously available for select MI commands, is now
> Â globally available. Therefore, things like:
> 
> Â Â Â Â-file-exec-and-symbols --thread-group i1 foobar
> Â 
> Â works.
> * The --all option to MI exec commands now affects threads in all inferiors.
> 
> The important caveat is that multiexec MI is only really working in non-stop.
> At least the --all option, in all-stops, runs into various core issues. It's not
> presently known how many are there and whether they are fixable.

Yeah.  I tried it on a simple test I use often, much like
schedlock.c (spawns a few threads that go busy looping), creating
a few inferiors using that program, and `-exec-run --all' didn't
behave correctly; it didn't crash, but a bunch of threads
missing.  I haven't investigated fully, but there's the
option of not supporting it until it actually works..

> 
> - Volodya
> multiexec-mi.diff
>   commit 8fb18657cf8d53b951c84e76002e5a57dc75a944
> Author: Vladimir Prus <vladimir@codesourcery.com>
> Date: Â Sat Dec 19 17:38:00 2009 +0300
> 
> Â Â Multiexec MI
> Â Â 
> Â Â ÂÂÂÂgdb/
> Â Â ÂÂÂÂ* breakpoint.c (clear_syscall_counts): Take struct inferior*.
> Â Â 
> Â Â ÂÂÂÂgdb/doc/
> Â Â ÂÂÂÂ* gdb.texinfo (GDB/MI Command Syntax): Document notification
> Â Â ÂÂÂÂchanges.
> Â Â ÂÂÂÂ(GDB/MI Program Execution): Document current behaviour of
> Â Â ÂÂÂÂ--all and --thread-group.
> Â Â ÂÂÂÂ(GDB/MI Miscellaneous Commands): Document -add-inferior and
> Â Â ÂÂÂÂ-remove-inferior.
> Â Â ÂÂÂÂ* observer.texi (inferior_added, inferior_removed): New
> Â Â ÂÂÂÂobservers.
> Â Â 
> Â Â ÂÂÂÂ* inferior.c (add_inferior_silent): Notify inferior_added
> Â Â ÂÂÂÂobserver.
> Â Â ÂÂÂÂ(delete_inferior_1): Notify inferior_removed observer.
> Â Â ÂÂÂÂ(exit_inferior_1): Pass inferior, not pid, to observer.
> Â Â ÂÂÂÂ(inferior_appeared): Likewise.
> Â Â ÂÂÂÂ(add_inferior_with_spaces): New.
> Â Â ÂÂÂÂ(add_inferior_command): Use the above.
> Â Â ÂÂÂÂ* inferior.h (delete_inferior_1, add_inferior_with_spaces):
> Â Â ÂÂÂÂDeclare.
> Â Â 
> Â Â ÂÂÂÂ* inflow.c (inflow_inferior_exit): Likewise.
> Â Â ÂÂÂÂ* jit.c (jit_inferior_exit_hook): Likewise.
> Â Â 
> Â Â ÂÂÂÂ* mi/mi-cmds.c (mi_cmds): Register add-inferior and
> Â Â ÂÂÂÂremove-inferior.
> Â Â ÂÂÂÂ* mi/mi-cmds.h (mi_cmd_add_inferior, mi_cmd_remove_inferior): New.
> Â Â ÂÂÂÂ* mi/mi-interp.c (mi_inferior_added, mi_inferior_removed): New.
> Â Â ÂÂÂÂ(report_initial_inferior): New.
> Â Â ÂÂÂÂ(mi_inferior_removed): Register the above. Make sure
> Â Â ÂÂÂÂinferior_added observer is called on the first inferior.
> Â Â ÂÂÂÂ(mi_new_thread, mi_thread_exit): Thread group is now identified by
> Â Â ÂÂÂÂinferior number, not pid.
> Â Â ÂÂÂÂ(mi_solib_loaded, mi_solib_unloaded): Report which inferiors are
> Â Â ÂÂÂÂaffected.
> Â Â ÂÂÂÂ* mi/mi-main.c (current_context): New.
> Â Â ÂÂÂÂ(proceed_thread_callback): Use typed closure.
> Â Â ÂÂÂÂProceed everything if pid is 0.
> Â Â ÂÂÂÂ(proceed_thread_callback_wrapper): New.
> Â Â ÂÂÂÂ(run_one_inferior): New.
> Â Â ÂÂÂÂ(mi_cmd_exec_continue, mi_cmd_exec_interrupt, mi_cmd_exec_run):
> Â Â ÂÂÂÂAdjust for multiexec behaviour.
> Â Â ÂÂÂÂ(mi_cmd_add_inferior, mi_cmd_remove_inferior): New.
> Â Â ÂÂÂÂ(mi_cmd_execute): Handle the 'thread-group' option here.
> Â Â ÂÂÂÂDo some extra checks.
> Â Â ÂÂÂÂ* mi-parse.c (mi_parse): Handle the --all and --thread-group
> Â Â ÂÂÂÂoptions.
> Â Â ÂÂÂÂ* mi-parse.h (struct mi_parse): New fields all and thread_group.
> 
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 0dc8474..0d8a471 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -10230,10 +10230,8 @@ add_catch_command (char *name, char *docstring,
> Â}
> Â
> Âstatic void
> -clear_syscall_counts (int pid)
> +clear_syscall_counts (struct inferior *inf)
> Â{
> - Âstruct inferior *inf = find_inferior_pid (pid);
> -
> Â Âinf->total_syscalls_count = 0;
> Â Âinf->any_syscall_count = 0;
> Â ÂVEC_free (int, inf->syscalls_counts);
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 02e2bbd..6da2d12 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -21528,6 +21528,11 @@ groups can be obtained using @samp{-list-thread-groups --available}.
> ÂIn general, the content of a thread group may be only retrieved only
> Âafter attaching to that thread group.
> Â
> +Thread groups are related to inferiors (@pxref{Inferiors and
> +Programs}). ÂEach inferior corresponds to a thread group of a special 
> +type @samp{process}, and some additional operations are permitted on
> +such thread groups.
> +
> Â@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> Â@node GDB/MI Command Syntax
> Â@section @sc{gdb/mi} Command Syntax
> @@ -21969,9 +21974,24 @@ several threads in the list. ÂThe @var{core} field reports the
> Âprocessor core on which the stop event has happened. ÂThis field may be absent
> Âif such information is not available.
> Â
> -@item =thread-group-created,id="@var{id}"
> +@item =thread-group-added,id="@var{id}"
> +@itemx =thread-group-removed,id="@var{id}"
> +A thread thread group was either added or removed. ÂThe @var{id} field
> +contains the @value{GDBN} identifier of the thread group. ÂWhen a thread
> +group is added, it generally might not be associated with a running
> +process. ÂWhen a thread group is removed, its id becomes invalid and
> +cannot be used in any way.
> +
> +@item =thread-group-started,id="@var{id}",pid="@var{pid}"
> +A thread group either because associated with a running program,
> +either because the program was started or it the thread group
> +was attached to a program. ÂThe @var{id} field contains the 
> +@value{GDBN} identifier of the thread group. ÂThe @var{pid} field
> +contains process identifier, specific to the operating system.
> +
> Â@itemx =thread-group-exited,id="@var{id}"
> -A thread thread group either was attached to, or has exited/detached
> +A thread thread group is no longer associated with a running program,
> +either because the program has exited, or because it was detached
> Âfrom. ÂThe @var{id} field contains the @value{GDBN} identifier of the
> Âthread group.
> Â
> @@ -22002,12 +22022,18 @@ opaque identifier of the library. ÂFor remote debugging case,
> Âlibrary file on the target, and on the host respectively. ÂFor native
> Âdebugging, both those fields have the same value. ÂThe
> Â@var{symbols-loaded} field reports if the debug symbols for this
> -library are loaded.
> +library are loaded. ÂThe @var{thread-group} field, if present,
> +contains the id of the thread group in which the library was loaded.
> +If the field is absent, it means the library was loaded in all present
> +thread groups.
> Â
> Â@item =library-unloaded,...
> ÂReports that a library was unloaded by the program. ÂThis notification
> Âhas 3 fields---@var{id}, @var{target-name} and @var{host-name} with
> -the same meaning as for the @code{=library-loaded} notification
> +the same meaning as for the @code{=library-loaded} notification. ÂThe 
> +@var{thread-group} field, if present, contains the id of the thread
> +group in which the library was loaded. ÂIf the field is absent,
> +it means the library was loaded in all present thread groups.
> Â
> Â@end table
> Â
> @@ -23106,7 +23132,7 @@ other cases.
> Â@subsubheading Synopsis
> Â
> Â@smallexample
> - -exec-continue [--all|--thread-group N]
> + -exec-continue [--all | --thread-group N]
> Â@end smallexample
> Â
> ÂResumes the execution of the inferior program until a breakpoint is
> @@ -23116,7 +23142,7 @@ depending on the value of the @samp{scheduler-locking} variable. ÂIn
> Ânon-stop mode (@pxref{Non-Stop Mode}), if the @samp{--all} is not
> Âspecified, only the thread specified with the @samp{--thread} option
> Â(or current thread, if no @samp{--thread} is provided) is resumed. ÂIf
> -@samp{--all} is specified, all threads will be resumed. ÂThe
> +@samp{--all} is specified, all threads (in all inferiours) will be resumed. ÂThe

s/inferiours/inferiors/   there are more instances of this.

> Â@samp{--all} option is ignored in all-stop mode. ÂIf the
> Â@samp{--thread-group} options is specified, then all threads in that
> Âthread group are resumed.
> @@ -23206,9 +23232,9 @@ asynchronous just like other execution commands. ÂThat is, first the
> Âreported after that using the @samp{*stopped} notification.
> Â
> ÂIn non-stop mode, only the context thread is interrupted by default.
> -All threads will be interrupted if the @samp{--all} option is
> -specified. ÂIf the @samp{--thread-group} option is specified, all
> -threads in that group will be interrupted.
> +All threads (in all inferiours) will be interrupted if the
> +@samp{--all} Âoption is specified. ÂIf the @samp{--thread-group}
> +option is Âspecified, all threads in that group will be interrupted.

             ^ looks like spurious space.

> Â
> Â@subsubheading @value{GDBN} Command
> Â
> @@ -23372,7 +23398,7 @@ fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
> Â@subsubheading Synopsis
> Â
> Â@smallexample
> - -exec-run
> + -exec-run [--all | --thread-group N ]
> Â@end smallexample
> Â
> ÂStarts execution of the inferior from the beginning. ÂThe inferior
> @@ -23380,6 +23406,11 @@ executes until either a breakpoint is encountered or the program
> Âexits. ÂIn the latter case the output will include an exit code, if
> Âthe program has exited exceptionally.
> Â
> +When no option is specified, the current inferiour is started. ÂIf the
> +@samp{--thread-group} option is specified, it should refer to a thread
> +group of type @samp{process}, and that thread group will be started.
> +If the @samp{--all} option is specified, then all inferiours will be started.
> +
> Â@subsubheading @value{GDBN} Command
> Â
> ÂThe corresponding @value{GDBN} command is @samp{run}.
> @@ -26437,7 +26468,8 @@ have the following fields:
> Â
> Â@table @code
> Â@item id
> -Identifier of the thread group. ÂThis field is always present.
> +Identifier of the thread group. ÂThis field is always present. ÂThe
> +identifier is an opaque string, and is not necessary an integer.
> Â
> Â@item type
> ÂThe type of the thread group. ÂAt present, only @samp{process} is a
> @@ -26445,7 +26477,7 @@ valid type.
> Â
> Â@item pid
> ÂThe target-specific process identifier. ÂThis field is only present
> -for thread groups of type @samp{process}.
> +for thread groups of type @samp{process} and only if the process exists.
> Â
> Â@item num_children
> ÂThe number of children this thread group has. ÂThis field may be
> @@ -26461,6 +26493,11 @@ This field is a list of integers, each identifying a core that one
> Âthread of the group is running on. ÂThis field may be absent if
> Âsuch information is not available.
> Â
> +@item executable
> +The name of the executable file that corresponds to this thread group.
> +The field is only present for thread groups of type @samp{process},
> +and only if there is corresponding executable file.
> +
> Â@end table
> Â
> Â@subheading Example
> @@ -26487,6 +26524,31 @@ such information is not available.
> Â Â Â Â Â Â Â Â Â Â Â Â Â@{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
> Â@end smallexample
> Â
> +
> +@subheading The @code{-add-inferior} Command
> +@findex -add-inferior
> +
> +@subheading Synopsis
> +
> +@smallexample
> +-add-inferior
> +@end smallexample
> +
> +Creates a new inferior (@pxref{Inferiors and Programs}). ÂThe created
> +inferior is not associated with any executable. ÂSuch associated may
> +be established with the @samp{-file-exec-and-symbols} command 
> +(@pxref{GDB/MI File Commands}). ÂThe command response has a single
> +field, @samp{thread-group}, whose value is the identifier of the
> +thread group corresponding to the new inferior.
> +
> +@subheading Example
> +
> +@smallexample
> +@value{GDBP}
> +-add-inferior
> +^done,thread-group="i3"
> +@end smallexample
> +
> Â@subheading The @code{-interpreter-exec} Command
> Â@findex -interpreter-exec
> Â
> diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
> index db3d114..fb0cc9d 100644
> --- a/gdb/doc/observer.texi
> +++ b/gdb/doc/observer.texi
> @@ -199,13 +199,23 @@ The thread's ptid has changed. ÂThe @var{old_ptid} parameter specifies
> Âthe old value, and @var{new_ptid} specifies the new value.
> Â@end deftypefun
> Â
> -@deftypefun void inferior_appeared (int @var{pid})
> -@value{GDBN} has attached to a new inferior identified by @var{pid}.
> +@deftypefun void inferior_added (struct inferior *@var{inf})
> +The inferior @var{inf} has been added to the list of inferiour. ÂAt
> +this point, it might not be associated with any process.
> Â@end deftypefun
> Â
> -@deftypefun void inferior_exit (int @var{pid})
> -Either @value{GDBN} detached from the inferior, or the inferior
> -exited. ÂThe argument @var{pid} identifies the inferior.
> +@deftypefun void inferior_appeared (struct inferior *@var{inf})
> +The inferior identified by @var{inf} has been attached to a process.
> +@end deftypefun
> +
> +@deftypefun void inferior_exit (struct inferior *@var{inf})
> +Either the inferior associated with @var{inf} has been detached from the
> +process, or the process has exited.
> +@end deftypefun
> +
> +@deftypefun void inferior_removed (struct inferior *@var{inf})
> +The inferior @var{inf} has been removed from the list of inferiors.
> +This method is called immediate before freeing @var{inf}.
> Â@end deftypefun
> Â
> Â@deftypefun void memory_changed (CORE_ADDR @var{addr}, int @var{len}, const bfd_byte *@var{data})
> @@ -213,8 +223,8 @@ Bytes from @var{data} to @var{data} + @var{len} have been written
> Âto the current inferior at @var{addr}.
> Â@end deftypefun
> Â
> - @deftypefun void test_notification (int @var{somearg})
> +@deftypefun void test_notification (int @var{somearg})
> ÂThis observer is used for internal testing. ÂDo not use. Â
> ÂSee testsuite/gdb.gdb/observer.exp.
> - @end deftypefun
> +@end deftypefun
> Â
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index d27a3e3..783b8fc 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -126,6 +126,8 @@ add_inferior_silent (int pid)
> Â
> Â Âinferior_alloc_data (inf);
> Â
> + Âobserver_notify_inferior_added (inf);
> +
> Â Âif (pid != 0)
> Â Â Âinferior_appeared (inf, pid);
> Â
> @@ -187,7 +189,7 @@ delete_threads_of_inferior (int pid)
> Â/* If SILENT then be quiet -- don't announce a inferior death, or the
> Â Â exit of its threads. Â*/
> Â
> -static void
> +void
> Âdelete_inferior_1 (struct inferior *todel, int silent)
> Â{
> Â Âstruct inferior *inf, *infprev;
> @@ -212,6 +214,8 @@ delete_inferior_1 (struct inferior *todel, int silent)
> Â Âelse
> Â Â Âinferior_list = inf->next;
> Â
> + Âobserver_notify_inferior_removed (inf);
> +
> Â Âfree_inferior (inf);
> Â}
> Â
> @@ -258,7 +262,7 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
> Â
> Â Â/* Notify the observers before removing the inferior from the list,
> Â Â Â so that the observers have a chance to look it up. Â*/
> - Âobserver_notify_inferior_exit (inf->pid);
> + Âobserver_notify_inferior_exit (inf);
> Â
> Â Âinf->pid = 0;
> Â Âif (inf->vfork_parent != NULL)
> @@ -308,7 +312,7 @@ inferior_appeared (struct inferior *inf, int pid)
> Â{
> Â Âinf->pid = pid;
> Â
> - Âobserver_notify_inferior_appeared (pid);
> + Âobserver_notify_inferior_appeared (inf);
> Â}
> Â
> Âvoid
> @@ -731,6 +735,24 @@ remove_inferior_command (char *args, int from_tty)
> Â Âdelete_inferior_1 (inf, 1);
> Â}
> Â
> +struct inferior *
> +add_inferior_with_spaces (void)
> +{
> + Âstruct address_space *aspace;
> + Âstruct program_space *pspace;
> + Âstruct inferior *inf;
> + Â
> + Â/* If all inferiors share an address space on this system, this
> + Â Â doesn't really return a new address space; otherwise, it
> + Â Â really does. Â*/
> + Âaspace = maybe_new_address_space ();
> + Âpspace = add_program_space (aspace);
> + Âinf = add_inferior (0);
> + Âinf->pspace = pspace;
> + Âinf->aspace = pspace->aspace;
> +
> + Âreturn inf;
> +}
> Â
> Â/* add-inferior [-copies N] [-exec FILENAME] Â*/
> Â
> @@ -775,18 +797,7 @@ add_inferior_command (char *args, int from_tty)
> Â
> Â Âfor (i = 0; i < copies; ++i)
> Â Â Â{
> - Â Â Âstruct address_space *aspace;
> - Â Â Âstruct program_space *pspace;
> - Â Â Âstruct inferior *inf;
> -
> - Â Â Â/* If all inferiors share an address space on this system, this
> -ÂÂÂÂÂÂÂ doesn't really return a new address space; otherwise, it
> -ÂÂÂÂÂÂÂ really does. Â*/
> - Â Â Âaspace = maybe_new_address_space ();
> - Â Â Âpspace = add_program_space (aspace);
> - Â Â Âinf = add_inferior (0);
> - Â Â Âinf->pspace = pspace;
> - Â Â Âinf->aspace = pspace->aspace;
> + Â Â Âstruct inferior *inf = add_inferior_with_spaces ();
> Â
> Â Â Â Âprintf_filtered (_("Added inferior %d\n"), inf->num);
> Â
> @@ -794,7 +805,7 @@ add_inferior_command (char *args, int from_tty)
> ÂÂÂÂÂÂÂÂ{
> ÂÂÂÂÂÂÂÂ Â/* Switch over temporarily, while reading executable and
> ÂÂÂÂÂÂÂÂ Â Â symbols.q Â*/
> -ÂÂÂÂÂÂÂ Âset_current_program_space (pspace);
> +ÂÂÂÂÂÂÂ Âset_current_program_space (inf->pspace);
> ÂÂÂÂÂÂÂÂ Âset_current_inferior (inf);
> ÂÂÂÂÂÂÂÂ Âswitch_to_thread (null_ptid);
> Â
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index 048fc11..cc5e571 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -520,6 +520,8 @@ extern struct inferior *add_inferior_silent (int pid);
> Â/* Delete an existing inferior list entry, due to inferior exit. Â*/
> Âextern void delete_inferior (int pid);
> Â
> +extern void delete_inferior_1 (struct inferior *todel, int silent);
> +
> Â/* Same as delete_inferior, but don't print new inferior notifications
> Â Â to the CLI. Â*/
> Âextern void delete_inferior_silent (int pid);
> @@ -606,4 +608,6 @@ extern void prune_inferiors (void);
> Â
> Âextern int number_of_inferiors (void);
> Â
> +extern struct inferior *add_inferior_with_spaces (void);
> +
> Â#endif /* !defined (INFERIOR_H) */
> diff --git a/gdb/inflow.c b/gdb/inflow.c
> index 599fc69..bb4ca18 100644
> --- a/gdb/inflow.c
> +++ b/gdb/inflow.c
> @@ -504,9 +504,8 @@ get_inflow_inferior_data (struct inferior *inf)
> Â Â list. Â*/
> Â
> Âstatic void
> -inflow_inferior_exit (int pid)
> +inflow_inferior_exit (struct inferior *inf)
> Â{
> - Âstruct inferior *inf = find_inferior_pid (pid);
> Â Âstruct terminal_info *info;
> Â
> Â Âinfo = inferior_data (inf, inflow_inferior_data);
> diff --git a/gdb/jit.c b/gdb/jit.c
> index 433746a..e17f0ab 100644
> --- a/gdb/jit.c
> +++ b/gdb/jit.c
> @@ -397,7 +397,7 @@ jit_inferior_created_observer (struct target_ops *objfile, int from_tty)
> Â Â for example when it crashes. Â*/
> Â
> Âstatic void
> -jit_inferior_exit_hook (int pid)
> +jit_inferior_exit_hook (struct inferior *inf)
> Â{
> Â Âstruct objfile *objf;
> Â Âstruct objfile *temp;
> diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
> index 729cc5f..9c4ba1f 100644
> --- a/gdb/mi/mi-cmds.c
> +++ b/gdb/mi/mi-cmds.c
> @@ -33,6 +33,7 @@ static void build_table (struct mi_cmd *commands);
> Â
> Âstruct mi_cmd mi_cmds[] =
> Â{
> + Â{ "add-inferior", { NULL, 0}, mi_cmd_add_inferior },

                               ^ EMISSINGSPACE

> Â Â{ "break-after", { "ignore", 1 }, NULL },
> Â Â{ "break-condition", { "cond", 1 }, NULL },
> Â Â{ "break-commands", { NULL, 0 }, mi_cmd_break_commands },
> @@ -84,6 +85,7 @@ struct mi_cmd mi_cmds[] =
> Â Â{ "list-features", { NULL, 0 }, mi_cmd_list_features},
> Â Â{ "list-target-features", { NULL, 0 }, mi_cmd_list_target_features},
> Â Â{ "list-thread-groups", { NULL, 0 }, mi_cmd_list_thread_groups }, Â
> + Â{ "remove-inferior", { NULL, 0 }, mi_cmd_remove_inferior },
> Â Â{ "stack-info-depth", { NULL, 0 }, mi_cmd_stack_info_depth},
> Â Â{ "stack-info-frame", { NULL, 0 }, mi_cmd_stack_info_frame},
> Â Â{ "stack-list-arguments", { NULL, 0 }, mi_cmd_stack_list_args},
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 7e1c819..d840104 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -36,6 +36,7 @@ extern const char mi_all_values[];
> Âtypedef void (mi_cmd_argv_ftype) (char *command, char **argv, int argc);
> Â
> Â/* Function implementing each command */
> +extern mi_cmd_argv_ftype mi_cmd_add_inferior;
> Âextern mi_cmd_argv_ftype mi_cmd_break_insert;
> Âextern mi_cmd_argv_ftype mi_cmd_break_commands;
> Âextern mi_cmd_argv_ftype mi_cmd_break_watch;
> @@ -72,6 +73,7 @@ extern mi_cmd_argv_ftype mi_cmd_interpreter_exec;
> Âextern mi_cmd_argv_ftype mi_cmd_list_features;
> Âextern mi_cmd_argv_ftype mi_cmd_list_target_features;
> Âextern mi_cmd_argv_ftype mi_cmd_list_thread_groups;
> +extern mi_cmd_argv_ftype mi_cmd_remove_inferior;
> Âextern mi_cmd_argv_ftype mi_cmd_stack_info_depth;
> Âextern mi_cmd_argv_ftype mi_cmd_stack_info_frame;
> Âextern mi_cmd_argv_ftype mi_cmd_stack_list_args;
> diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
> index 41388bb..04c4124 100644
> --- a/gdb/mi/mi-interp.c
> +++ b/gdb/mi/mi-interp.c
> @@ -56,13 +56,17 @@ static void mi_on_normal_stop (struct bpstats *bs, int print_frame);
> Â
> Âstatic void mi_new_thread (struct thread_info *t);
> Âstatic void mi_thread_exit (struct thread_info *t, int silent);
> -static void mi_inferior_appeared (int pid);
> -static void mi_inferior_exit (int pid);
> +static void mi_inferior_added (struct inferior *inf);
> +static void mi_inferior_appeared (struct inferior *inf);
> +static void mi_inferior_exit (struct inferior *inf);
> +static void mi_inferior_removed (struct inferior *inf);
> Âstatic void mi_on_resume (ptid_t ptid);
> Âstatic void mi_solib_loaded (struct so_list *solib);
> Âstatic void mi_solib_unloaded (struct so_list *solib);
> Âstatic void mi_about_to_proceed (void);
> Â
> +static int report_initial_inferior (struct inferior *inf, void *closure);
> +
> Âstatic void *
> Âmi_interpreter_init (int top_level)
> Â{
> @@ -86,13 +90,20 @@ mi_interpreter_init (int top_level)
> Â Â Â{
> Â Â Â Âobserver_attach_new_thread (mi_new_thread);
> Â Â Â Âobserver_attach_thread_exit (mi_thread_exit);
> + Â Â Âobserver_attach_inferior_added (mi_inferior_added);
> Â Â Â Âobserver_attach_inferior_appeared (mi_inferior_appeared);
> Â Â Â Âobserver_attach_inferior_exit (mi_inferior_exit);
> + Â Â Âobserver_attach_inferior_removed (mi_inferior_removed);
> Â Â Â Âobserver_attach_normal_stop (mi_on_normal_stop);
> Â Â Â Âobserver_attach_target_resumed (mi_on_resume);
> Â Â Â Âobserver_attach_solib_loaded (mi_solib_loaded);
> Â Â Â Âobserver_attach_solib_unloaded (mi_solib_unloaded);
> Â Â Â Âobserver_attach_about_to_proceed (mi_about_to_proceed);
> +
> + Â Â Â/* The initial inferior is created before this function is called, so we
> +ÂÂÂÂÂÂÂ need to report it explicitly. ÂUse iteration in case future version
> +ÂÂÂÂÂÂÂ of GDB creates more than one inferior up-front. Â*/
> + Â Â Âiterate_over_inferiors (report_initial_inferior, mi);
> Â Â Â}
> Â
> Â Âreturn mi;
> @@ -285,10 +296,13 @@ static void
> Âmi_new_thread (struct thread_info *t)
> Â{
> Â Âstruct mi_interp *mi = top_level_interpreter_data ();
> + Âstruct inferior *inf = find_inferior_pid (t->ptid.pid);

Use ptid_get_pid.

> +
> + Âgdb_assert (inf);
> Â
> Â Âfprintf_unfiltered (mi->event_channel, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-created,id=\"%d\",group-id=\"%d\"", 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Ât->num, t->ptid.pid);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-created,id=\"%d\",group-id=\"i%d\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Ât->num, inf->num);
> Â Âgdb_flush (mi->event_channel);
> Â}
> Â
> @@ -296,38 +310,64 @@ static void
> Âmi_thread_exit (struct thread_info *t, int silent)
> Â{
> Â Âstruct mi_interp *mi;
> + Âstruct inferior *inf;
> Â
> Â Âif (silent)
> Â Â Âreturn;
> Â
> + Âinf = find_inferior_pid (t->ptid.pid);

Ditto.

> +
> Â Âmi = top_level_interpreter_data ();
> Â Âtarget_terminal_ours ();
> Â Âfprintf_unfiltered (mi->event_channel, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-exited,id=\"%d\",group-id=\"%d\"", 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Ât->num,t->ptid.pid);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-exited,id=\"%d\",group-id=\"i%d\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Ât->num, inf->num);
> Â Âgdb_flush (mi->event_channel);
> Â}
> Â
> Âvoid
> -mi_inferior_appeared (int pid)
> +mi_inferior_added (struct inferior *inf)
> Â{
> Â Âstruct mi_interp *mi = top_level_interpreter_data ();
> Â Âtarget_terminal_ours ();
> - Âfprintf_unfiltered (mi->event_channel, "thread-group-created,id=\"%d\"",
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âpid);
> + Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-group-added,id=\"i%d\"",
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âinf->num);
> + Âgdb_flush (mi->event_channel);
> +}
> +
> +void
> +mi_inferior_appeared (struct inferior *inf)

Nit: could you make these explicitly "static", although there's
a declaration above that makes them static already?

> +{
> + Âstruct mi_interp *mi = top_level_interpreter_data ();
> + Âtarget_terminal_ours ();
> + Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-group-started,id=\"i%d\",pid=\"%d\"",
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âinf->num, inf->pid);
> Â Âgdb_flush (mi->event_channel);
> Â}
> Â
> Âstatic void
> -mi_inferior_exit (int pid)
> +mi_inferior_exit (struct inferior *inf)
> Â{
> Â Âstruct mi_interp *mi = top_level_interpreter_data ();
> Â Âtarget_terminal_ours ();
> - Âfprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"%d\"", 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âpid);
> + Âfprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"i%d\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âinf->num);
> Â Âgdb_flush (mi->event_channel); Â
> Â}
> Â
> +void
> +mi_inferior_removed (struct inferior *inf)
> +{
> + Âstruct mi_interp *mi = top_level_interpreter_data ();
> + Âtarget_terminal_ours ();
> + Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-group-removed,id=\"i%d\"",
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âinf->num);
> + Âgdb_flush (mi->event_channel);
> +}
> +
> Âstatic void
> Âmi_on_normal_stop (struct bpstats *bs, int print_frame)
> Â{
> @@ -489,10 +529,18 @@ mi_solib_loaded (struct so_list *solib)
> Â{
> Â Âstruct mi_interp *mi = top_level_interpreter_data ();
> Â Âtarget_terminal_ours ();
> - Âfprintf_unfiltered (mi->event_channel, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded=\"%d\"", 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âsolib->so_original_name, solib->so_original_name, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âsolib->so_name, solib->symbols_loaded);
> + Âif (gdbarch_has_global_solist (target_gdbarch))
> + Â Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded=\"%d\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_original_name, solib->so_original_name, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_name, solib->symbols_loaded);
> + Âelse
> + Â Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded=\"%d\",thread-group=\"i%d\"", 

In C, this:
 
 "foo"
 "bar"

is a single string "foobar".  So you could split these long lines like, e.g.:

                          "library-loaded,id=\"%s\",target-name=\"%s\","
                          "host-name=\"%s\",symbols-loaded=\"%d\","
                          "thread-group=\"i%d\"",  


> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_original_name, solib->so_original_name, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_name, solib->symbols_loaded,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcurrent_inferior ()->num);
> +
> Â Âgdb_flush (mi->event_channel);
> Â}
> Â
> @@ -501,13 +549,35 @@ mi_solib_unloaded (struct so_list *solib)
> Â{
> Â Âstruct mi_interp *mi = top_level_interpreter_data ();
> Â Âtarget_terminal_ours ();
> - Âfprintf_unfiltered (mi->event_channel, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"library-unloaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\"", 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âsolib->so_original_name, solib->so_original_name, 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âsolib->so_name);
> + Âif (gdbarch_has_global_solist (target_gdbarch))
> + Â Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"library-unloaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_original_name, solib->so_original_name, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_name);
> + Âelse
> + Â Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"library-unloaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",thread-group=\"i%d\"", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_original_name, solib->so_original_name, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂsolib->so_name, current_inferior ()->num);
> +
> Â Âgdb_flush (mi->event_channel);
> Â}
> Â
> +static int
> +report_initial_inferior (struct inferior *inf, void *closure)
> +{
> + Â/* This function is called from mi_intepreter_init, and since
> + Â Â mi_inferior_added assumes that inferior is fully initialized
> + Â Â and top_level_interpreter_data is set, we cannot call
> + Â Â it here. Â*/
> + Âstruct mi_interp *mi = closure;
> + Âtarget_terminal_ours ();
> + Âfprintf_unfiltered (mi->event_channel, 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â"thread-group-added,id=\"i%d\"",
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âinf->num);
> + Âgdb_flush (mi->event_channel);
> + Âreturn 0;
> +}
> Â
> Âextern initialize_file_ftype _initialize_mi_interp; /* -Wmissing-prototypes */
> Â
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index aa1ffaf..0fad5cf 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -78,6 +78,11 @@ static struct mi_timestamp *current_command_ts;
> Âstatic int do_timings = 0;
> Â
> Âchar *current_token;
> +/* Few commands would like to know if options like --thread-group
> + Â were explicitly specified. ÂThis variable keeps the current
> + Â parsed command including all option, and make it possible. Â*/
> +struct mi_parse *current_context;

This could be static?  A global named `current_context' (a very
generic name), is sort of asking for trouble if someone else
adds another `current_context' global somewhere else; the linker
may consider them the same variable, and it could go unnoticed.
Defensively, globals like these should be either
prefixed (e.g., mi_foo), or made static and exported through
a function.

> +
> Âint running_result_record_printed = 1;
> Â
> Â/* Flag indicating that the target has proceeded since the last
> @@ -177,54 +182,83 @@ mi_cmd_exec_jump (char *args, char **argv, int argc)
> Â Â/* FIXME: Should call a libgdb function, not a cli wrapper. Â*/
> Â Âreturn mi_execute_async_cli_command ("jump", argv, argc);
> Â}
> - 
> -static int
> -proceed_thread_callback (struct thread_info *thread, void *arg)
> -{
> - Âint pid = *(int *)arg;
> Â
> +
> +static void
> +proceed_thread_callback (struct thread_info *thread, int pid)

Pedantically, this one is no longer a callback.  You could rename
this one, and name the new function `proceed_thread_callback', instead
of `proceed_thread_callback_wrapper'.

> +{
> Â Âif (!is_stopped (thread->ptid))
> - Â Âreturn 0;
> + Â Âreturn;
> Â
> - Âif (PIDGET (thread->ptid) != pid)
> - Â Âreturn 0;
> + Âif (pid != 0 && PIDGET (thread->ptid) != pid)
> + Â Âreturn;
> Â
> Â Âswitch_to_thread (thread->ptid);
> Â Âclear_proceed_status ();
> Â Âproceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
> +}
> +
> +
> +static int
> +proceed_thread_callback_wrapper (struct thread_info *thread, void *arg)
> +{
> + Âint pid = *(int *)arg;
> + Âproceed_thread_callback (thread, pid);
> Â Âreturn 0;
> Â}
> Â
> Âvoid
> Âmi_cmd_exec_continue (char *command, char **argv, int argc)
> Â{
> - Âif (argc == 0)
> - Â Âcontinue_1 (0);
> - Âelse if (argc == 1 && strcmp (argv[0], "--all") == 0)
> - Â Âcontinue_1 (1);
> - Âelse if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
> + Âif (non_stop)
> Â Â Â{
> - Â Â Âstruct cleanup *old_chain;
> - Â Â Âint pid;
> - Â Â Âif (argv[1] == NULL || argv[1] == '\0')
> -ÂÂÂÂÂÂÂerror ("Thread group id not specified");
> - Â Â Âpid = atoi (argv[1]);
> - Â Â Âif (!in_inferior_list (pid))
> -ÂÂÂÂÂÂÂerror ("Invalid thread group id '%s'", argv[1]);
> + Â Â Â/* In non-stop mode, 'resume' always resumes a single thread. ÂTherefore,
> +ÂÂÂÂÂÂÂ to resume all threads of the current inferior, or all threads in all
> +ÂÂÂÂÂÂÂ inferiors, we need to iterate over threads. Â
> +ÂÂÂÂÂÂÂ 
> +ÂÂÂÂÂÂÂ See comment on infcmd.c:proceed_thread_callback for rationale. Â*/
> + Â Â Âif (current_context->all || current_context->thread_group != -1)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âint pid = 0;
> +ÂÂÂÂÂÂÂ Âstruct cleanup *back_to = make_cleanup_restore_current_thread ();
> Â
> - Â Â Âold_chain = make_cleanup_restore_current_thread ();
> - Â Â Âiterate_over_threads (proceed_thread_callback, &pid);
> - Â Â Âdo_cleanups (old_chain); Â Â Â Â Â Â
> +ÂÂÂÂÂÂÂ Âif (!current_context->all)
> +ÂÂÂÂÂÂÂ Â Â{
> +ÂÂÂÂÂÂÂ Â Â Âstruct inferior *inf = find_inferior_id (current_context->thread_group);
> +ÂÂÂÂÂÂÂ Â Â Âpid = inf->pid;
> +ÂÂÂÂÂÂÂ Â Â}
> +ÂÂÂÂÂÂÂ Âiterate_over_threads (proceed_thread_callback_wrapper, &pid);
> +ÂÂÂÂÂÂÂ Âdo_cleanups (back_to);
> +ÂÂÂÂÂÂÂ}
> + Â Â Âelse
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âcontinue_1 (0);
> +ÂÂÂÂÂÂÂ}
> Â Â Â}
> Â Âelse
> - Â Âerror ("Usage: -exec-continue [--all|--thread-group id]");
> + Â Â{
> + Â Â Âstruct cleanup *back_to = make_cleanup_restore_integer (&sched_multi);
> + Â Â Âif (current_context->all)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âsched_multi = 1;
> +ÂÂÂÂÂÂÂ Âcontinue_1 (0);ÂÂÂÂÂÂÂ
> +ÂÂÂÂÂÂÂ}
> + Â Â Âelse 
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Â/* In all-stop mode, -exec-continue traditionally resumed either
> +ÂÂÂÂÂÂÂ Â Â all threads, or one thread, depending on the 'scheduler-locking'
> +ÂÂÂÂÂÂÂ Â Â variable. ÂLet's continue to do the same. Â*/
> +ÂÂÂÂÂÂÂ Âcontinue_1 (1);
> +ÂÂÂÂÂÂÂ}
> + Â Â Âdo_cleanups (back_to);
> + Â Â}
> Â}
> Â
> Âstatic int
> Âinterrupt_thread_callback (struct thread_info *thread, void *arg)
> Â{
> Â Âint pid = *(int *)arg;
> -
> + Â
> Â Âif (!is_running (thread->ptid))
> Â Â Âreturn 0;
> Â
> @@ -243,36 +277,31 @@ interrupt_thread_callback (struct thread_info *thread, void *arg)
> Âvoid
> Âmi_cmd_exec_interrupt (char *command, char **argv, int argc)
> Â{
> - Âif (argc == 0)
> + Â/* In all-stop mode, everything stops, so we don't need to try
> + Â Â anything specific. Â*/
> + Âif (!non_stop)
> Â Â Â{
> - Â Â Âif (!is_running (inferior_ptid))
> -ÂÂÂÂÂÂÂerror ("Current thread is not running.");
> -
> Â Â Â Âinterrupt_target_1 (0);
> + Â Â Âreturn;
> Â Â Â}
> - Âelse if (argc == 1 && strcmp (argv[0], "--all") == 0)
> +
> + Âif (current_context->all)
> Â Â Â{
> - Â Â Âif (!any_running ())
> -ÂÂÂÂÂÂÂerror ("Inferior not running.");
> - Â Â Â
> + Â Â Â/* This will interrupt all threads in all inferiors. Â*/
> Â Â Â Âinterrupt_target_1 (1);
> Â Â Â}
> - Âelse if (argc == 2 && strcmp (argv[0], "--thread-group") == 0)
> + Âelse if (current_context->thread_group != -1)
> Â Â Â{
> - Â Â Âstruct cleanup *old_chain;
> - Â Â Âint pid;
> - Â Â Âif (argv[1] == NULL || argv[1] == '\0')
> -ÂÂÂÂÂÂÂerror ("Thread group id not specified");
> - Â Â Âpid = atoi (argv[1]);
> - Â Â Âif (!in_inferior_list (pid))
> -ÂÂÂÂÂÂÂerror ("Invalid thread group id '%s'", argv[1]);
> -
> - Â Â Âold_chain = make_cleanup_restore_current_thread ();
> - Â Â Âiterate_over_threads (interrupt_thread_callback, &pid);
> - Â Â Âdo_cleanups (old_chain);
> + Â Â Âstruct inferior *inf = find_inferior_id (current_context->thread_group);
> + Â Â Âiterate_over_threads (interrupt_thread_callback, &(inf->pid));

Redundant ()'s.

> Â Â Â}
> Â Âelse
> - Â Âerror ("Usage: -exec-interrupt [--all|--thread-group id]");
> + Â Â{
> + Â Â Â/* Interrupt just the current thread -- either explicitly
> +ÂÂÂÂÂÂÂ specified via --thread or whatever was current before
> +ÂÂÂÂÂÂÂ MI command was sent. Â*/
> + Â Â Âinterrupt_target_1 (0);
> + Â Â}
> Â}
> Â
> Â/* Given MI command arguments, recompose then back into a single string
> @@ -349,6 +378,34 @@ mi_cmd_exec_until (char *command, char **argv, int argc)
> Â Âdo_cleanups (back_to);
> Â}
> Â
> +static int run_one_inferior (struct inferior *inf, void *arg)

Function name on column 1, please.

> +{
> + Âstruct thread_info *tp = 0;
> +
> + Âif (inf->pid != 0)
> + Â Â{
> + Â Â Âif (inf->pid != ptid_get_pid (inferior_ptid))
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âstruct thread_info *tp;
> +ÂÂÂÂÂÂÂ Â
> +ÂÂÂÂÂÂÂ Âtp = any_thread_of_process (inf->pid);
> +ÂÂÂÂÂÂÂ Âif (!tp)
> +ÂÂÂÂÂÂÂ Â Âerror (_("Inferior has no threads."));
> +
> +ÂÂÂÂÂÂÂ Âswitch_to_thread (tp->ptid);
> +ÂÂÂÂÂÂÂ}
> + Â Â}
> + Âelse
> + Â Â{
> + Â Â Âset_current_inferior (inf);
> + Â Â Âswitch_to_thread (null_ptid);
> + Â Â Âset_current_program_space (inf->pspace);
> + Â Â}
> + Âmi_execute_cli_command ("run", target_can_async_p (), 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Âtarget_can_async_p () ? "&" : NULL);
> + Âreturn 0;
> +}
> +
> Âvoid
> Âmi_cmd_exec_run (char *command, char **argv, int argc)
> Â{
> @@ -371,14 +428,26 @@ mi_cmd_exec_run (char *command, char **argv, int argc)
> Â
> Â Âif (argc == 0)
> Â Â Â{
> - Â Â Âmi_execute_cli_command ("run", target_can_async_p (), 
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Âtarget_can_async_p () ? "&" : NULL);
> + Â Â Âif (current_context->all)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âstruct cleanup *back_to = save_current_space_and_thread ();
> +ÂÂÂÂÂÂÂ Âiterate_over_inferiors (run_one_inferior, NULL);
> +ÂÂÂÂÂÂÂ Âdo_cleanups (back_to);
> +ÂÂÂÂÂÂÂ}
> + Â Â Âelse
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âmi_execute_cli_command ("run", target_can_async_p (), 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Âtarget_can_async_p () ? "&" : NULL);
> +ÂÂÂÂÂÂÂ}
> Â Â Â}
> Â Âelse
> Â Â Â{
> Â Â Â Âstruct cleanup *back_to;
> Â Â Â Âchar *r = recompose_args (argv, argc, target_can_async_p ());
> Â Â Â Âback_to = make_cleanup (xfree, r);
> +
> + Â Â Âif (current_context->all)
> +ÂÂÂÂÂÂÂerror (_("Could not use --all with explicit arguments"));

"Could not", or "Can not" ?

> Â Â Â Â
> Â Â Â Âmi_execute_cli_command ("run", 1, r);
> Â
> @@ -524,13 +593,23 @@ print_one_inferior (struct inferior *inferior, void *xdata)
> Â Â Â Âstruct cleanup *back_to
> ÂÂÂÂÂÂÂÂ= make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
> Â
> - Â Â Âui_out_field_fmt (uiout, "id", "%d", inferior->pid);
> + Â Â Âui_out_field_fmt (uiout, "id", "i%d", inferior->num);
> Â Â Â Âui_out_field_string (uiout, "type", "process");
> - Â Â Âui_out_field_int (uiout, "pid", inferior->pid);
> + Â Â Âif (inferior->pid != 0)
> +ÂÂÂÂÂÂÂui_out_field_int (uiout, "pid", inferior->pid);
> +
> + Â Â Âif (inferior->pspace->ebfd)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âui_out_field_string (uiout, "executable", 
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Â Â Â bfd_get_filename (inferior->pspace->ebfd));
> +ÂÂÂÂÂÂÂ}
> Â
> - Â Â Âdata.pid = inferior->pid;
> Â Â Â Âdata.cores = 0;
> - Â Â Âiterate_over_threads (collect_cores, &data);
> + Â Â Âif (inferior->pid != 0)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âdata.pid = inferior->pid;
> +ÂÂÂÂÂÂÂ Âiterate_over_threads (collect_cores, &data);
> +ÂÂÂÂÂÂÂ}
> Â
> Â Â Â Âif (!VEC_empty (int, data.cores))
> ÂÂÂÂÂÂÂÂ{
> @@ -1541,6 +1620,40 @@ mi_cmd_list_target_features (char *command, char **argv, int argc)
> Â Âerror ("-list-target-features should be passed no arguments");
> Â}
> Â
> +void 
> +mi_cmd_add_inferior (char *command, char **argv, int argc)
> +{
> + Âstruct inferior *inf;
> +
> + Âif (argc != 0)
> + Â Âerror ("-add-inferior shuld be passed not arguments");

Something's wrong with this sentence.  Also, most MI errors
you've added have the string wrapped in _() for i18n, while these
do not.

> + Â Â
> + Âinf = add_inferior_with_spaces ();
> +
> + Âui_out_field_fmt (uiout, "inferior", "i%d", inf->num); Â
> +}
> +
> +void
> +mi_cmd_remove_inferior (char *command, char **argv, int argc)
> +{
> + Âint id;
> + Âstruct inferior *inf;
> +
> + Âif (argc != 1)
> + Â Âerror ("-remove-iferior should be passed a single argument");

Typo: "inferior"

> +
> + Âif (sscanf (argv[1], "i%d", &id) != 1)
> + Â Âerror ("the thread group id is syntactically invalid");
> +
> + Âinf = find_inferior_id (id);
> + Âif (!inf)
> + Â Âerror ("the specified thread group does not exist");
> +
> + Âdelete_inferior_1 (inf, 1 /* silent */); Â Â
> +}
> +
> +
> +
> Â/* Execute a command within a safe environment.
> Â Â Return <0 for error; >=0 for ok.
> Â
> @@ -1740,9 +1853,37 @@ mi_cmd_execute (struct mi_parse *parse)
> Â
> Â Âcleanup = make_cleanup (null_cleanup, NULL);
> Â
> + Âif (parse->all && parse->thread_group != -1)
> + Â Âerror (_("Cannot specify --thread-group together with --all"));
> +
> + Âif (parse->all && parse->thread != -1)
> + Â Âerror (_("Cannot specify --thread together with --all"));
> +
> + Âif (parse->thread_group != -1 && parse->thread != -1)
> + Â Âerror (_("Cannot specify --thread together with --thread-group"));
> +
> Â Âif (parse->frame != -1 && parse->thread == -1)
> Â Â Âerror (_("Cannot specify --frame without --thread"));
> Â
> + Âif (parse->thread_group != -1)
> + Â Â{
> + Â Â Âstruct inferior *inf = find_inferior_id (parse->thread_group);
> + Â Â Âstruct thread_info *tp = 0;
> +
> + Â Â Âif (!inf)
> +ÂÂÂÂÂÂÂerror (_("Invalid thread group for the --tread-group option"));
> +
> + Â Â Âset_current_inferior (inf);
> + Â Â Â/* This behaviour means that if --thread-group option identifies
> +ÂÂÂÂÂÂÂ an inferior with multiple threads, then a random one will be picked.
> +ÂÂÂÂÂÂÂ This is not a problem -- frontend should always provide --thread if
> +ÂÂÂÂÂÂÂ it wishes to operate on a specific thread. Â*/
> + Â Â Âif (inf->pid != 0)
> +ÂÂÂÂÂÂÂtp = any_thread_of_process (inf->pid);
> + Â Â Âswitch_to_thread (tp ? tp->ptid : null_ptid);
> + Â Â Âset_current_program_space (inf->pspace);
> + Â Â}
> +
> Â Âif (parse->thread != -1)
> Â Â Â{
> Â Â Â Âstruct thread_info *tp = find_thread_id (parse->thread);
> @@ -1767,6 +1908,8 @@ mi_cmd_execute (struct mi_parse *parse)
> ÂÂÂÂÂÂÂÂerror (_("Invalid frame id: %d"), frame);
> Â Â Â}
> Â
> + Âcurrent_context = parse;
> +

Hmm, aren't the `struct mi_parse' objects leaking
for every MI command?  I can't see where they're released in
mi_execute_command ?


> Â Âif (parse->cmd->argv_func != NULL)
> Â Â Âparse->cmd->argv_func (parse->command, parse->argv, parse->argc);
> Â Âelse if (parse->cmd->cli.cmd != 0)
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index 4ff70ef..ec955aa 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -151,6 +151,8 @@ mi_parse (char *cmd)
> Â Âchar *chp;
> Â Âstruct mi_parse *parse = XMALLOC (struct mi_parse);
> Â Âmemset (parse, 0, sizeof (*parse));
> + Âparse->all = 0;
> + Âparse->thread_group = -1;
> Â Âparse->thread = -1;
> Â Âparse->frame = -1;
> Â
> @@ -210,8 +212,31 @@ mi_parse (char *cmd)
> Â Âfor (;;)
> Â Â Â{
> Â Â Â Âchar *start = chp;
> + Â Â Âsize_t as = sizeof ("--all ") - 1;
> + Â Â Âsize_t tgs = sizeof ("--thread-group ") - 1;
> Â Â Â Âsize_t ts = sizeof ("--thread ") - 1;
> Â Â Â Âsize_t fs = sizeof ("--frame ") - 1;
> + Â Â Âif (strncmp (chp, "--all ", as) == 0)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âparse->all = 1;
> +ÂÂÂÂÂÂÂ Âchp += as;
> +ÂÂÂÂÂÂÂ}
> + Â Â Â/* See if this --all as the last token in the input. Â*/
> + Â Â Âif (strncmp (chp, "--all", as) == 0)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âparse->all = 1;
> +ÂÂÂÂÂÂÂ Âchp += (as - 1);
> +ÂÂÂÂÂÂÂ}

In the latter strncmp above:

+ if (strncmp (chp, "--all", as) == 0)

AS is always larger than strlen("--all"), so the
strncmp's check on AS is useless and confusing here.
I think you wanted:

      if (strcmp (chp, "--all") == 0)
       {
         parse->all = 1;
         chp += strlen (chp);
       }


> + Â Â Âif (strncmp (chp, "--thread-group ", tgs) == 0)
> +ÂÂÂÂÂÂÂ{
> +ÂÂÂÂÂÂÂ Âif (parse->thread_group != -1)
> +ÂÂÂÂÂÂÂ Â Âerror ("Duplicate '--thread-group' option");
> +ÂÂÂÂÂÂÂ Âchp += tgs;
> +ÂÂÂÂÂÂÂ Âif (*chp != 'i')
> +ÂÂÂÂÂÂÂ Â Âerror ("Invalid thread group id");
> +ÂÂÂÂÂÂÂ Âchp += 1;
> +ÂÂÂÂÂÂÂ Âparse->thread_group = strtol (chp, &chp, 10);
> +ÂÂÂÂÂÂÂ}

More of the `to i18n or not to i18n' issue.

> Â Â Â Âif (strncmp (chp, "--thread ", ts) == 0)
> ÂÂÂÂÂÂÂÂ{
> ÂÂÂÂÂÂÂÂ Âif (parse->thread != -1)
> diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
> index a63ee8e..3c6cd9a 100644
> --- a/gdb/mi/mi-parse.h
> +++ b/gdb/mi/mi-parse.h
> @@ -46,6 +46,8 @@ struct mi_parse
> Â Â Âchar *args;
> Â Â Âchar **argv;
> Â Â Âint argc;
> + Â Âint all;
> + Â Âint thread_group; /* At present, the same as inferior number. Â*/
> Â Â Âint thread;
> Â Â Âint frame;
> Â Â};
> diff --git a/gdb/testsuite/gdb.mi/mi-nonstop.exp b/gdb/testsuite/gdb.mi/mi-nonstop.exp
> index 605f48b..397dec5 100644
> --- a/gdb/testsuite/gdb.mi/mi-nonstop.exp
> +++ b/gdb/testsuite/gdb.mi/mi-nonstop.exp
> @@ -151,7 +151,7 @@ if { [is_remote target] } {
> Â Â Âunsupported $test
> Â} else {
> Â Â Âgdb_expect {
> -ÂÂÂÂÂÂÂ-re ".*=thread-exited,id=\"2\",group-id=\"\[0-9\]+\"\r\n$" {
> +ÂÂÂÂÂÂÂ-re ".*=thread-exited,id=\"2\",group-id=\"i\[0-9\]+\"\r\n$" {
> ÂÂÂÂÂÂÂÂ Â Âpass $test
> ÂÂÂÂÂÂÂÂ}
> ÂÂÂÂÂÂÂÂtimeout {

Otherwise, looks good to me.

Do you know if current frontends had bad assumptions, and will
behave or misbehave with this change?  E.g., CDI, DSF-GDB, kdevelop?

-- 
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]