- nb_tasks = VEC_length (ada_task_info_s, data->task_list);
-
- old_chain = make_cleanup_ui_out_table_begin_end (uiout, 7, nb_tasks,
- "tasks");
- ui_out_table_header (uiout, 1, ui_left, "current", "");
- ui_out_table_header (uiout, 3, ui_right, "id", "ID");
- ui_out_table_header (uiout, 9, ui_right, "task-id", "TID");
- ui_out_table_header (uiout, 4, ui_right, "parent-id", "P-ID");
- ui_out_table_header (uiout, 3, ui_right, "priority", "Pri");
- ui_out_table_header (uiout, 22, ui_left, "state", "State");
+
+ /* 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");