+ if (arg_str != NULL && arg_str[0] != '\0')
+ taskno_arg = value_as_long (parse_and_eval (arg_str));
+
+ if (uiout->is_mi_like_p ())
+ /* In GDB/MI mode, we want to provide the thread ID corresponding
+ to each task. This allows clients to quickly find the thread
+ associated to any task, which is helpful for commands that
+ take a --thread argument. However, in order to be able to
+ provide that thread ID, the thread list must be up to date
+ first. */
+ target_update_thread_list ();
+
+ data = get_ada_tasks_inferior_data (inf);
+
+ /* Compute the number of tasks that are going to be displayed
+ in the output. If an argument was given, there will be
+ at most 1 entry. Otherwise, there will be as many entries
+ as we have tasks. */
+ if (taskno_arg)
+ {
+ if (taskno_arg > 0 && taskno_arg <= data->task_list.size ())
+ nb_tasks = 1;
+ else
+ nb_tasks = 0;
+ }
+ else
+ nb_tasks = data->task_list.size ();
+
+ nb_columns = uiout->is_mi_like_p () ? 8 : 7;
+ ui_out_emit_table table_emitter (uiout, nb_columns, nb_tasks, "tasks");
+ uiout->table_header (1, ui_left, "current", "");
+ uiout->table_header (3, ui_right, "id", "ID");
+ {
+ size_t tid_width = 9;
+ /* Grown below in case the largest entry is bigger. */
+
+ if (!uiout->is_mi_like_p ())
+ {
+ for (taskno = 1; taskno <= data->task_list.size (); taskno++)
+ {
+ const struct ada_task_info *const task_info
+ = &data->task_list[taskno - 1];
+
+ gdb_assert (task_info != NULL);
+
+ tid_width = std::max (tid_width,
+ 1 + strlen (phex_nz (task_info->task_id,
+ sizeof (CORE_ADDR))));
+ }
+ }
+ uiout->table_header (tid_width, ui_right, "task-id", "TID");
+ }
+ /* The following column is provided in GDB/MI mode only because
+ it is only really useful in that mode, and also because it
+ allows us to keep the CLI output shorter and more compact. */
+ if (uiout->is_mi_like_p ())
+ uiout->table_header (4, ui_right, "thread-id", "");
+ uiout->table_header (4, ui_right, "parent-id", "P-ID");
+ uiout->table_header (3, ui_right, "priority", "Pri");
+ uiout->table_header (22, ui_left, "state", "State");
+ /* Use ui_noalign for the last column, to prevent the CLI uiout
+ from printing an extra space at the end of each row. This
+ is a bit of a hack, but does get the job done. */
+ uiout->table_header (1, ui_noalign, "name", "Name");
+ uiout->table_body ();
+
+ for (taskno = 1; taskno <= data->task_list.size (); taskno++)
+ {
+ const struct ada_task_info *const task_info =
+ &data->task_list[taskno - 1];
+ int parent_id;
+
+ gdb_assert (task_info != NULL);
+
+ /* If the user asked for the output to be restricted
+ to one task only, and this is not the task, skip
+ to the next one. */
+ if (taskno_arg && taskno != taskno_arg)
+ continue;
+
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
+
+ /* Print a star if this task is the current task (or the task
+ currently selected). */
+ if (task_info->ptid == inferior_ptid)
+ uiout->field_string ("current", "*");
+ else
+ uiout->field_skip ("current");
+
+ /* Print the task number. */
+ uiout->field_signed ("id", taskno);
+
+ /* Print the Task ID. */
+ uiout->field_string ("task-id", phex_nz (task_info->task_id,
+ sizeof (CORE_ADDR)));
+
+ /* Print the associated Thread ID. */
+ if (uiout->is_mi_like_p ())
+ {
+ thread_info *thread = (ada_task_is_alive (task_info)
+ ? find_thread_ptid (inf, task_info->ptid)
+ : nullptr);
+
+ if (thread != NULL)
+ uiout->field_signed ("thread-id", thread->global_num);
+ else
+ {
+ /* This can happen if the thread is no longer alive. */
+ uiout->field_skip ("thread-id");
+ }
+ }
+
+ /* Print the ID of the parent task. */
+ parent_id = get_task_number_from_id (task_info->parent, inf);
+ if (parent_id)
+ uiout->field_signed ("parent-id", parent_id);
+ else
+ uiout->field_skip ("parent-id");
+
+ /* Print the base priority of the task. */
+ uiout->field_signed ("priority", task_info->priority);
+
+ /* Print the task current state. */
+ if (task_info->caller_task)
+ uiout->field_fmt ("state",
+ _("Accepting RV with %-4d"),
+ get_task_number_from_id (task_info->caller_task,
+ inf));
+ else if (task_info->called_task)
+ uiout->field_fmt ("state",
+ _("Waiting on RV with %-3d"),
+ get_task_number_from_id (task_info->called_task,
+ inf));
+ else
+ uiout->field_string ("state", task_states[task_info->state]);
+
+ /* Finally, print the task name, without quotes around it, as mi like
+ is not expecting quotes, and in non mi-like no need for quotes
+ as there is a specific column for the name. */
+ uiout->field_fmt ("name",
+ (task_info->name[0] != '\0'
+ ? ui_file_style ()
+ : metadata_style.style ()),
+ "%s",
+ (task_info->name[0] != '\0'
+ ? task_info->name
+ : _("<no name>")));
+
+ uiout->text ("\n");
+ }