From 6cda5a20820e95cf01d510f2478cd4b992cf416b Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Fri, 21 Oct 2011 18:46:06 +0000 Subject: [Ada] Fix number of lines in -ada-task-info output When using the new -ada-task-info command with an argument, the output would say that there are N entries in the returned table, (where N is the total number of tasks present in the inferior). But, in fact, the table would only contain at most 1 entry. This patch fixes this by properly computing the number of tasks being displayed before giving it to the uiout. gdb/ChangeLog: * ada-tasks.c (print_ada_task_info): Fix computation of number of tasks displayed in command output. gdb/testsuite/ChangeLog: * gdb.ada/mi_task_info/task_switch.adb: New file. * gdb.ada/mi_task_info.exp: New file. --- gdb/ada-tasks.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'gdb/ada-tasks.c') diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index 8ab5ad5..5b82561 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -984,7 +984,21 @@ print_ada_task_info (struct ui_out *uiout, target_find_new_threads (); data = get_ada_tasks_inferior_data (inf); - nb_tasks = VEC_length (ada_task_info_s, data->task_list); + + /* 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 <= VEC_length (ada_task_info_s, data->task_list)) + nb_tasks = 1; + else + nb_tasks = 0; + } + else + nb_tasks = VEC_length (ada_task_info_s, data->task_list); nb_columns = ui_out_is_mi_like_p (uiout) ? 8 : 7; old_chain = make_cleanup_ui_out_table_begin_end (uiout, nb_columns, @@ -1006,7 +1020,9 @@ print_ada_task_info (struct ui_out *uiout, ui_out_table_header (uiout, 1, ui_noalign, "name", "Name"); ui_out_table_body (uiout); - for (taskno = 1; taskno <= nb_tasks; taskno++) + for (taskno = 1; + taskno <= VEC_length (ada_task_info_s, data->task_list); + taskno++) { const struct ada_task_info *const task_info = VEC_index (ada_task_info_s, data->task_list, taskno - 1); -- cgit v1.1