gdb/ada-tasks.c - gdb
Global variables defined
Data types defined
Functions defined
Macros defined
Source code
- #include "defs.h"
- #include "observer.h"
- #include "gdbcmd.h"
- #include "target.h"
- #include "ada-lang.h"
- #include "gdbcore.h"
- #include "inferior.h"
- #include "gdbthread.h"
- #include "progspace.h"
- #include "objfiles.h"
- #define KNOWN_TASKS_NAME "system__tasking__debug__known_tasks"
- static const int MAX_NUMBER_OF_KNOWN_TASKS = 1000;
- #define KNOWN_TASKS_LIST "system__tasking__debug__first_task"
- enum task_states
- {
- Unactivated,
- Runnable,
- Terminated,
- Activator_Sleep,
- Acceptor_Sleep,
- Entry_Caller_Sleep,
- Async_Select_Sleep,
- Delay_Sleep,
- Master_Completion_Sleep,
- Master_Phase_2_Sleep,
- Interrupt_Server_Idle_Sleep,
- Interrupt_Server_Blocked_Interrupt_Sleep,
- Timer_Server_Sleep,
- AST_Server_Sleep,
- Asynchronous_Hold,
- Interrupt_Server_Blocked_On_Event_Flag,
- Activating,
- Acceptor_Delay_Sleep
- };
- static const char *task_states[] = {
- N_("Unactivated"),
- N_("Runnable"),
- N_("Terminated"),
- N_("Child Activation Wait"),
- N_("Accept or Select Term"),
- N_("Waiting on entry call"),
- N_("Async Select Wait"),
- N_("Delay Sleep"),
- N_("Child Termination Wait"),
- N_("Wait Child in Term Alt"),
- "",
- "",
- "",
- "",
- N_("Asynchronous Hold"),
- "",
- N_("Activating"),
- N_("Selective Wait")
- };
- static const char *long_task_states[] = {
- N_("Unactivated"),
- N_("Runnable"),
- N_("Terminated"),
- N_("Waiting for child activation"),
- N_("Blocked in accept or select with terminate"),
- N_("Waiting on entry call"),
- N_("Asynchronous Selective Wait"),
- N_("Delay Sleep"),
- N_("Waiting for children termination"),
- N_("Waiting for children in terminate alternative"),
- "",
- "",
- "",
- "",
- N_("Asynchronous Hold"),
- "",
- N_("Activating"),
- N_("Blocked in selective wait statement")
- };
- struct atcb_fieldnos
- {
-
- int common;
- int entry_calls;
- int atc_nesting_level;
-
- int state;
- int parent;
- int priority;
- int image;
- int image_len;
- int activation_link;
- int call;
- int ll;
-
- int ll_thread;
- int ll_lwp;
-
- int call_self;
- };
- struct ada_tasks_pspace_data
- {
-
- int initialized_p;
-
- struct type *atcb_type;
-
- struct type *atcb_common_type;
-
- struct type *atcb_ll_type;
-
- struct type *atcb_call_type;
-
- struct atcb_fieldnos atcb_fieldno;
- };
- static const struct program_space_data *ada_tasks_pspace_data_handle;
- typedef struct ada_task_info ada_task_info_s;
- DEF_VEC_O(ada_task_info_s);
- enum ada_known_tasks_kind
- {
-
- ADA_TASKS_UNKNOWN = 0,
-
- ADA_TASKS_NOT_FOUND,
-
- ADA_TASKS_ARRAY,
-
- ADA_TASKS_LIST,
- };
- struct ada_tasks_inferior_data
- {
-
- enum ada_known_tasks_kind known_tasks_kind;
-
- CORE_ADDR known_tasks_addr;
-
- struct type *known_tasks_element;
-
- unsigned int known_tasks_length;
-
- int task_list_valid_p;
-
- VEC(ada_task_info_s) *task_list;
- };
- static const struct inferior_data *ada_tasks_inferior_data_handle;
- static struct ada_tasks_pspace_data *
- get_ada_tasks_pspace_data (struct program_space *pspace)
- {
- struct ada_tasks_pspace_data *data;
- data = program_space_data (pspace, ada_tasks_pspace_data_handle);
- if (data == NULL)
- {
- data = XCNEW (struct ada_tasks_pspace_data);
- set_program_space_data (pspace, ada_tasks_pspace_data_handle, data);
- }
- return data;
- }
- static struct ada_tasks_inferior_data *
- get_ada_tasks_inferior_data (struct inferior *inf)
- {
- struct ada_tasks_inferior_data *data;
- data = inferior_data (inf, ada_tasks_inferior_data_handle);
- if (data == NULL)
- {
- data = XCNEW (struct ada_tasks_inferior_data);
- set_inferior_data (inf, ada_tasks_inferior_data_handle, data);
- }
- return data;
- }
- int
- ada_get_task_number (ptid_t ptid)
- {
- int i;
- struct inferior *inf = find_inferior_ptid (ptid);
- struct ada_tasks_inferior_data *data;
- gdb_assert (inf != NULL);
- data = get_ada_tasks_inferior_data (inf);
- for (i = 0; i < VEC_length (ada_task_info_s, data->task_list); i++)
- if (ptid_equal (VEC_index (ada_task_info_s, data->task_list, i)->ptid,
- ptid))
- return i + 1;
- return 0;
- }
- static int
- get_task_number_from_id (CORE_ADDR task_id, struct inferior *inf)
- {
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- int i;
- for (i = 0; i < VEC_length (ada_task_info_s, data->task_list); i++)
- {
- struct ada_task_info *task_info =
- VEC_index (ada_task_info_s, data->task_list, i);
- if (task_info->task_id == task_id)
- return i + 1;
- }
-
- return 0;
- }
- int
- valid_task_id (int task_num)
- {
- struct ada_tasks_inferior_data *data;
- ada_build_task_list ();
- data = get_ada_tasks_inferior_data (current_inferior ());
- return (task_num > 0
- && task_num <= VEC_length (ada_task_info_s, data->task_list));
- }
- static int
- ada_task_is_alive (struct ada_task_info *task_info)
- {
- return (task_info->state != Terminated);
- }
- void
- iterate_over_live_ada_tasks (ada_task_list_iterator_ftype *iterator)
- {
- int i, nb_tasks;
- struct ada_task_info *task;
- struct ada_tasks_inferior_data *data;
- ada_build_task_list ();
- data = get_ada_tasks_inferior_data (current_inferior ());
- nb_tasks = VEC_length (ada_task_info_s, data->task_list);
- for (i = 0; i < nb_tasks; i++)
- {
- task = VEC_index (ada_task_info_s, data->task_list, i);
- if (!ada_task_is_alive (task))
- continue;
- iterator (task);
- }
- }
- static void
- value_as_string (char *dest, struct value *val, int length)
- {
- memcpy (dest, value_contents (val), length);
- dest[length] = '\0';
- }
- static void
- read_fat_string_value (char *dest, struct value *val, int max_len)
- {
- struct value *array_val;
- struct value *bounds_val;
- int len;
-
- static int initialize_fieldnos = 1;
- static int array_fieldno;
- static int bounds_fieldno;
- static int upper_bound_fieldno;
-
- if (initialize_fieldnos)
- {
- struct type *type = value_type (val);
- struct type *bounds_type;
- array_fieldno = ada_get_field_index (type, "P_ARRAY", 0);
- bounds_fieldno = ada_get_field_index (type, "P_BOUNDS", 0);
- bounds_type = TYPE_FIELD_TYPE (type, bounds_fieldno);
- if (TYPE_CODE (bounds_type) == TYPE_CODE_PTR)
- bounds_type = TYPE_TARGET_TYPE (bounds_type);
- if (TYPE_CODE (bounds_type) != TYPE_CODE_STRUCT)
- error (_("Unknown task name format. Aborting"));
- upper_bound_fieldno = ada_get_field_index (bounds_type, "UB0", 0);
- initialize_fieldnos = 0;
- }
-
- bounds_val = value_ind (value_field (val, bounds_fieldno));
- len = value_as_long (value_field (bounds_val, upper_bound_fieldno));
-
- if (len > max_len)
- len = max_len;
-
- array_val = value_ind (value_field (val, array_fieldno));
- read_memory (value_address (array_val), (gdb_byte *) dest, len);
-
- dest[len] = '\0';
- }
- static void
- get_tcb_types_info (void)
- {
- struct type *type;
- struct type *common_type;
- struct type *ll_type;
- struct type *call_type;
- struct atcb_fieldnos fieldnos;
- struct ada_tasks_pspace_data *pspace_data;
- const char *atcb_name = "system__tasking__ada_task_control_block___XVE";
- const char *atcb_name_fixed = "system__tasking__ada_task_control_block";
- const char *common_atcb_name = "system__tasking__common_atcb";
- const char *private_data_name = "system__task_primitives__private_data";
- const char *entry_call_record_name = "system__tasking__entry_call_record";
-
- struct symbol *atcb_sym =
- lookup_symbol_in_language (atcb_name, NULL, STRUCT_DOMAIN,
- language_c, NULL);
- const struct symbol *common_atcb_sym =
- lookup_symbol_in_language (common_atcb_name, NULL, STRUCT_DOMAIN,
- language_c, NULL);
- const struct symbol *private_data_sym =
- lookup_symbol_in_language (private_data_name, NULL, STRUCT_DOMAIN,
- language_c, NULL);
- const struct symbol *entry_call_record_sym =
- lookup_symbol_in_language (entry_call_record_name, NULL, STRUCT_DOMAIN,
- language_c, NULL);
- if (atcb_sym == NULL || atcb_sym->type == NULL)
- {
-
- atcb_sym = lookup_symbol_in_language (atcb_name_fixed, NULL,
- STRUCT_DOMAIN, language_c, NULL);
- if (atcb_sym == NULL || atcb_sym->type == NULL)
- error (_("Cannot find Ada_Task_Control_Block type. Aborting"));
- type = atcb_sym->type;
- }
- else
- {
-
- type = atcb_sym->type;
- type = ada_template_to_fixed_record_type_1 (type, NULL, 0, NULL, 0);
- }
- if (common_atcb_sym == NULL || common_atcb_sym->type == NULL)
- error (_("Cannot find Common_ATCB type. Aborting"));
- if (private_data_sym == NULL || private_data_sym->type == NULL)
- error (_("Cannot find Private_Data type. Aborting"));
- if (entry_call_record_sym == NULL || entry_call_record_sym->type == NULL)
- error (_("Cannot find Entry_Call_Record type. Aborting"));
-
- common_type = common_atcb_sym->type;
-
- ll_type = private_data_sym->type;
-
- call_type = entry_call_record_sym->type;
-
- fieldnos.common = ada_get_field_index (type, "common", 0);
- fieldnos.entry_calls = ada_get_field_index (type, "entry_calls", 1);
- fieldnos.atc_nesting_level =
- ada_get_field_index (type, "atc_nesting_level", 1);
- fieldnos.state = ada_get_field_index (common_type, "state", 0);
- fieldnos.parent = ada_get_field_index (common_type, "parent", 1);
- fieldnos.priority = ada_get_field_index (common_type, "base_priority", 0);
- fieldnos.image = ada_get_field_index (common_type, "task_image", 1);
- fieldnos.image_len = ada_get_field_index (common_type, "task_image_len", 1);
- fieldnos.activation_link = ada_get_field_index (common_type,
- "activation_link", 1);
- fieldnos.call = ada_get_field_index (common_type, "call", 1);
- fieldnos.ll = ada_get_field_index (common_type, "ll", 0);
- fieldnos.ll_thread = ada_get_field_index (ll_type, "thread", 0);
- fieldnos.ll_lwp = ada_get_field_index (ll_type, "lwp", 1);
- fieldnos.call_self = ada_get_field_index (call_type, "self", 0);
-
- if (fieldnos.ll_lwp < 0)
- fieldnos.ll_lwp = ada_get_field_index (ll_type, "thread_id", 1);
-
- pspace_data = get_ada_tasks_pspace_data (current_program_space);
- pspace_data->initialized_p = 1;
- pspace_data->atcb_type = type;
- pspace_data->atcb_common_type = common_type;
- pspace_data->atcb_ll_type = ll_type;
- pspace_data->atcb_call_type = call_type;
- pspace_data->atcb_fieldno = fieldnos;
- }
- static ptid_t
- ptid_from_atcb_common (struct value *common_value)
- {
- long thread = 0;
- CORE_ADDR lwp = 0;
- struct value *ll_value;
- ptid_t ptid;
- const struct ada_tasks_pspace_data *pspace_data
- = get_ada_tasks_pspace_data (current_program_space);
- ll_value = value_field (common_value, pspace_data->atcb_fieldno.ll);
- if (pspace_data->atcb_fieldno.ll_lwp >= 0)
- lwp = value_as_address (value_field (ll_value,
- pspace_data->atcb_fieldno.ll_lwp));
- thread = value_as_long (value_field (ll_value,
- pspace_data->atcb_fieldno.ll_thread));
- ptid = target_get_ada_task_ptid (lwp, thread);
- return ptid;
- }
- static void
- read_atcb (CORE_ADDR task_id, struct ada_task_info *task_info)
- {
- struct value *tcb_value;
- struct value *common_value;
- struct value *atc_nesting_level_value;
- struct value *entry_calls_value;
- struct value *entry_calls_value_element;
- int called_task_fieldno = -1;
- static const char ravenscar_task_name[] = "Ravenscar task";
- const struct ada_tasks_pspace_data *pspace_data
- = get_ada_tasks_pspace_data (current_program_space);
- if (!pspace_data->initialized_p)
- get_tcb_types_info ();
- tcb_value = value_from_contents_and_address (pspace_data->atcb_type,
- NULL, task_id);
- common_value = value_field (tcb_value, pspace_data->atcb_fieldno.common);
-
- task_info->task_id = task_id;
-
- if (pspace_data->atcb_fieldno.image_len == -1)
- {
- if (pspace_data->atcb_fieldno.image >= 0)
- read_fat_string_value (task_info->name,
- value_field (common_value,
- pspace_data->atcb_fieldno.image),
- sizeof (task_info->name) - 1);
- else
- {
- struct bound_minimal_symbol msym;
- msym = lookup_minimal_symbol_by_pc (task_id);
- if (msym.minsym)
- {
- const char *full_name = MSYMBOL_LINKAGE_NAME (msym.minsym);
- const char *task_name = full_name;
- const char *p;
-
- for (p = full_name; *p; p++)
- if (p[0] == '_' && p[1] == '_')
- task_name = p + 2;
-
- strncpy (task_info->name, task_name, sizeof (task_info->name));
- task_info->name[sizeof (task_info->name) - 1] = 0;
- }
- else
- {
-
- strcpy (task_info->name, ravenscar_task_name);
- }
- }
- }
- else
- {
- int len = value_as_long
- (value_field (common_value,
- pspace_data->atcb_fieldno.image_len));
- value_as_string (task_info->name,
- value_field (common_value,
- pspace_data->atcb_fieldno.image),
- len);
- }
-
- task_info->state =
- value_as_long (value_field (common_value,
- pspace_data->atcb_fieldno.state));
- task_info->priority =
- value_as_long (value_field (common_value,
- pspace_data->atcb_fieldno.priority));
-
- if (pspace_data->atcb_fieldno.parent >= 0)
- task_info->parent =
- value_as_address (value_field (common_value,
- pspace_data->atcb_fieldno.parent));
- else
- task_info->parent = 0;
-
- if (pspace_data->atcb_fieldno.atc_nesting_level > 0
- && pspace_data->atcb_fieldno.entry_calls > 0)
- {
-
- atc_nesting_level_value =
- value_field (tcb_value, pspace_data->atcb_fieldno.atc_nesting_level);
- entry_calls_value =
- ada_coerce_to_simple_array_ptr
- (value_field (tcb_value, pspace_data->atcb_fieldno.entry_calls));
- entry_calls_value_element =
- value_subscript (entry_calls_value,
- value_as_long (atc_nesting_level_value));
- called_task_fieldno =
- ada_get_field_index (value_type (entry_calls_value_element),
- "called_task", 0);
- task_info->called_task =
- value_as_address (value_field (entry_calls_value_element,
- called_task_fieldno));
- }
- else
- {
- task_info->called_task = 0;
- }
-
- task_info->caller_task = 0;
- if (pspace_data->atcb_fieldno.call >= 0)
- {
-
- const CORE_ADDR call =
- value_as_address (value_field (common_value,
- pspace_data->atcb_fieldno.call));
- struct value *call_val;
- if (call != 0)
- {
- call_val =
- value_from_contents_and_address (pspace_data->atcb_call_type,
- NULL, call);
- task_info->caller_task =
- value_as_address
- (value_field (call_val, pspace_data->atcb_fieldno.call_self));
- }
- }
-
- if (target_has_execution && ada_task_is_alive (task_info))
- task_info->ptid = ptid_from_atcb_common (common_value);
- else
- task_info->ptid = null_ptid;
- }
- static void
- add_ada_task (CORE_ADDR task_id, struct inferior *inf)
- {
- struct ada_task_info task_info;
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- read_atcb (task_id, &task_info);
- VEC_safe_push (ada_task_info_s, data->task_list, &task_info);
- }
- static int
- read_known_tasks_array (struct ada_tasks_inferior_data *data)
- {
- const int target_ptr_byte = TYPE_LENGTH (data->known_tasks_element);
- const int known_tasks_size = target_ptr_byte * data->known_tasks_length;
- gdb_byte *known_tasks = alloca (known_tasks_size);
- int i;
-
- read_memory (data->known_tasks_addr, known_tasks, known_tasks_size);
- for (i = 0; i < data->known_tasks_length; i++)
- {
- CORE_ADDR task_id =
- extract_typed_address (known_tasks + i * target_ptr_byte,
- data->known_tasks_element);
- if (task_id != 0)
- add_ada_task (task_id, current_inferior ());
- }
- return 1;
- }
- static int
- read_known_tasks_list (struct ada_tasks_inferior_data *data)
- {
- const int target_ptr_byte = TYPE_LENGTH (data->known_tasks_element);
- gdb_byte *known_tasks = alloca (target_ptr_byte);
- CORE_ADDR task_id;
- const struct ada_tasks_pspace_data *pspace_data
- = get_ada_tasks_pspace_data (current_program_space);
-
- if (pspace_data->atcb_fieldno.activation_link < 0)
- return 0;
-
- read_memory (data->known_tasks_addr, known_tasks, target_ptr_byte);
- task_id = extract_typed_address (known_tasks, data->known_tasks_element);
- while (task_id != 0)
- {
- struct value *tcb_value;
- struct value *common_value;
- add_ada_task (task_id, current_inferior ());
-
- tcb_value = value_from_contents_and_address (pspace_data->atcb_type,
- NULL, task_id);
- common_value = value_field (tcb_value, pspace_data->atcb_fieldno.common);
- task_id = value_as_address
- (value_field (common_value,
- pspace_data->atcb_fieldno.activation_link));
- }
- return 1;
- }
- static void
- ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
- {
- struct bound_minimal_symbol msym;
- struct symbol *sym;
-
- if (data->known_tasks_kind != ADA_TASKS_UNKNOWN)
- return;
-
- msym = lookup_minimal_symbol (KNOWN_TASKS_NAME, NULL, NULL);
- if (msym.minsym != NULL)
- {
- data->known_tasks_kind = ADA_TASKS_ARRAY;
- data->known_tasks_addr = BMSYMBOL_VALUE_ADDRESS (msym);
-
- sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL, VAR_DOMAIN,
- language_c, NULL);
- if (sym != NULL)
- {
-
- struct type *type = check_typedef (SYMBOL_TYPE (sym));
- struct type *eltype = NULL;
- struct type *idxtype = NULL;
- if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
- eltype = check_typedef (TYPE_TARGET_TYPE (type));
- if (eltype != NULL
- && TYPE_CODE (eltype) == TYPE_CODE_PTR)
- idxtype = check_typedef (TYPE_INDEX_TYPE (type));
- if (idxtype != NULL
- && !TYPE_LOW_BOUND_UNDEFINED (idxtype)
- && !TYPE_HIGH_BOUND_UNDEFINED (idxtype))
- {
- data->known_tasks_element = eltype;
- data->known_tasks_length =
- TYPE_HIGH_BOUND (idxtype) - TYPE_LOW_BOUND (idxtype) + 1;
- return;
- }
- }
-
- data->known_tasks_element =
- builtin_type (target_gdbarch ())->builtin_data_ptr;
- data->known_tasks_length = MAX_NUMBER_OF_KNOWN_TASKS;
- return;
- }
-
- msym = lookup_minimal_symbol (KNOWN_TASKS_LIST, NULL, NULL);
- if (msym.minsym != NULL)
- {
- data->known_tasks_kind = ADA_TASKS_LIST;
- data->known_tasks_addr = BMSYMBOL_VALUE_ADDRESS (msym);
- data->known_tasks_length = 1;
- sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL, VAR_DOMAIN,
- language_c, NULL);
- if (sym != NULL && SYMBOL_VALUE_ADDRESS (sym) != 0)
- {
-
- struct type *type = check_typedef (SYMBOL_TYPE (sym));
- if (TYPE_CODE (type) == TYPE_CODE_PTR)
- {
- data->known_tasks_element = type;
- return;
- }
- }
-
- data->known_tasks_element =
- builtin_type (target_gdbarch ())->builtin_data_ptr;
- data->known_tasks_length = 1;
- return;
- }
-
- data->known_tasks_kind = ADA_TASKS_NOT_FOUND;
- data->known_tasks_addr = 0;
- }
- static int
- read_known_tasks (void)
- {
- struct ada_tasks_inferior_data *data =
- get_ada_tasks_inferior_data (current_inferior ());
-
- VEC_truncate (ada_task_info_s, data->task_list, 0);
-
- ada_tasks_inferior_data_sniffer (data);
- gdb_assert (data->known_tasks_kind != ADA_TASKS_UNKNOWN);
- switch (data->known_tasks_kind)
- {
- case ADA_TASKS_NOT_FOUND:
- return 0;
- case ADA_TASKS_ARRAY:
- return read_known_tasks_array (data);
- case ADA_TASKS_LIST:
- return read_known_tasks_list (data);
- }
-
- data->task_list_valid_p = 1;
- return 1;
- }
- int
- ada_build_task_list (void)
- {
- struct ada_tasks_inferior_data *data;
- if (!target_has_stack)
- error (_("Cannot inspect Ada tasks when program is not running"));
- data = get_ada_tasks_inferior_data (current_inferior ());
- if (!data->task_list_valid_p)
- read_known_tasks ();
- return VEC_length (ada_task_info_s, data->task_list);
- }
- void
- print_ada_task_info (struct ui_out *uiout,
- char *arg_str,
- struct inferior *inf)
- {
- struct ada_tasks_inferior_data *data;
- int taskno, nb_tasks;
- int taskno_arg = 0;
- struct cleanup *old_chain;
- int nb_columns;
- if (ada_build_task_list () == 0)
- {
- ui_out_message (uiout, 0,
- _("Your application does not use any Ada tasks.\n"));
- return;
- }
- if (arg_str != NULL && arg_str[0] != '\0')
- taskno_arg = value_as_long (parse_and_eval (arg_str));
- if (ui_out_is_mi_like_p (uiout))
-
- target_update_thread_list ();
- data = get_ada_tasks_inferior_data (inf);
-
- 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,
- 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");
-
- if (ui_out_is_mi_like_p (uiout))
- ui_out_table_header (uiout, 4, ui_right, "thread-id", "");
- 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");
-
- ui_out_table_header (uiout, 1, ui_noalign, "name", "Name");
- ui_out_table_body (uiout);
- 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);
- int parent_id;
- struct cleanup *chain2;
- gdb_assert (task_info != NULL);
-
- if (taskno_arg && taskno != taskno_arg)
- continue;
- chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-
- if (ptid_equal (task_info->ptid, inferior_ptid))
- ui_out_field_string (uiout, "current", "*");
- else
- ui_out_field_skip (uiout, "current");
-
- ui_out_field_int (uiout, "id", taskno);
-
- ui_out_field_fmt (uiout, "task-id", "%9lx", (long) task_info->task_id);
-
- if (ui_out_is_mi_like_p (uiout))
- {
- const int thread_id = pid_to_thread_id (task_info->ptid);
- if (thread_id != 0)
- ui_out_field_int (uiout, "thread-id", thread_id);
- else
-
- ui_out_field_skip (uiout, "thread-id");
- }
-
- parent_id = get_task_number_from_id (task_info->parent, inf);
- if (parent_id)
- ui_out_field_int (uiout, "parent-id", parent_id);
- else
- ui_out_field_skip (uiout, "parent-id");
-
- ui_out_field_int (uiout, "priority", task_info->priority);
-
- if (task_info->caller_task)
- ui_out_field_fmt (uiout, "state",
- _("Accepting RV with %-4d"),
- get_task_number_from_id (task_info->caller_task,
- inf));
- else if (task_info->state == Entry_Caller_Sleep
- && task_info->called_task)
- ui_out_field_fmt (uiout, "state",
- _("Waiting on RV with %-3d"),
- get_task_number_from_id (task_info->called_task,
- inf));
- else
- ui_out_field_string (uiout, "state", task_states[task_info->state]);
-
- ui_out_field_fmt (uiout, "name",
- "%s",
- task_info->name[0] != '\0' ? task_info->name
- : _("<no name>"));
- ui_out_text (uiout, "\n");
- do_cleanups (chain2);
- }
- do_cleanups (old_chain);
- }
- static void
- info_task (struct ui_out *uiout, char *taskno_str, struct inferior *inf)
- {
- const int taskno = value_as_long (parse_and_eval (taskno_str));
- struct ada_task_info *task_info;
- int parent_taskno = 0;
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- if (ada_build_task_list () == 0)
- {
- ui_out_message (uiout, 0,
- _("Your application does not use any Ada tasks.\n"));
- return;
- }
- if (taskno <= 0 || taskno > VEC_length (ada_task_info_s, data->task_list))
- error (_("Task ID %d not known. Use the \"info tasks\" command to\n"
- "see the IDs of currently known tasks"), taskno);
- task_info = VEC_index (ada_task_info_s, data->task_list, taskno - 1);
-
- printf_filtered (_("Ada Task: %s\n"),
- paddress (target_gdbarch (), task_info->task_id));
-
- if (task_info->name[0] != '\0')
- printf_filtered (_("Name: %s\n"), task_info->name);
- else
- printf_filtered (_("<no name>\n"));
-
- printf_filtered (_("Thread: %#lx\n"), ptid_get_tid (task_info->ptid));
- printf_filtered (_("LWP: %#lx\n"), ptid_get_lwp (task_info->ptid));
-
- if (task_info->parent != 0)
- parent_taskno = get_task_number_from_id (task_info->parent, inf);
- if (parent_taskno)
- {
- struct ada_task_info *parent =
- VEC_index (ada_task_info_s, data->task_list, parent_taskno - 1);
- printf_filtered (_("Parent: %d"), parent_taskno);
- if (parent->name[0] != '\0')
- printf_filtered (" (%s)", parent->name);
- printf_filtered ("\n");
- }
- else
- printf_filtered (_("No parent\n"));
-
- printf_filtered (_("Base Priority: %d\n"), task_info->priority);
-
- {
- int target_taskno = 0;
- if (task_info->caller_task)
- {
- target_taskno = get_task_number_from_id (task_info->caller_task, inf);
- printf_filtered (_("State: Accepting rendezvous with %d"),
- target_taskno);
- }
- else if (task_info->state == Entry_Caller_Sleep && task_info->called_task)
- {
- target_taskno = get_task_number_from_id (task_info->called_task, inf);
- printf_filtered (_("State: Waiting on task %d's entry"),
- target_taskno);
- }
- else
- printf_filtered (_("State: %s"), _(long_task_states[task_info->state]));
- if (target_taskno)
- {
- struct ada_task_info *target_task_info =
- VEC_index (ada_task_info_s, data->task_list, target_taskno - 1);
- if (target_task_info->name[0] != '\0')
- printf_filtered (" (%s)", target_task_info->name);
- }
- printf_filtered ("\n");
- }
- }
- static void
- info_tasks_command (char *arg, int from_tty)
- {
- struct ui_out *uiout = current_uiout;
- if (arg == NULL || *arg == '\0')
- print_ada_task_info (uiout, NULL, current_inferior ());
- else
- info_task (uiout, arg, current_inferior ());
- }
- static void
- display_current_task_id (void)
- {
- const int current_task = ada_get_task_number (inferior_ptid);
- if (current_task == 0)
- printf_filtered (_("[Current task is unknown]\n"));
- else
- printf_filtered (_("[Current task is %d]\n"), current_task);
- }
- static void
- task_command_1 (char *taskno_str, int from_tty, struct inferior *inf)
- {
- const int taskno = value_as_long (parse_and_eval (taskno_str));
- struct ada_task_info *task_info;
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- if (taskno <= 0 || taskno > VEC_length (ada_task_info_s, data->task_list))
- error (_("Task ID %d not known. Use the \"info tasks\" command to\n"
- "see the IDs of currently known tasks"), taskno);
- task_info = VEC_index (ada_task_info_s, data->task_list, taskno - 1);
- if (!ada_task_is_alive (task_info))
- error (_("Cannot switch to task %d: Task is no longer running"), taskno);
-
- target_update_thread_list ();
-
- if (!find_thread_ptid (task_info->ptid))
- error (_("Unable to compute thread ID for task %d.\n"
- "Cannot switch to this task."),
- taskno);
- switch_to_thread (task_info->ptid);
- ada_find_printable_frame (get_selected_frame (NULL));
- printf_filtered (_("[Switching to task %d]\n"), taskno);
- print_stack_frame (get_selected_frame (NULL),
- frame_relative_level (get_selected_frame (NULL)),
- SRC_AND_LOC, 1);
- }
- static void
- task_command (char *taskno_str, int from_tty)
- {
- struct ui_out *uiout = current_uiout;
- if (ada_build_task_list () == 0)
- {
- ui_out_message (uiout, 0,
- _("Your application does not use any Ada tasks.\n"));
- return;
- }
- if (taskno_str == NULL || taskno_str[0] == '\0')
- display_current_task_id ();
- else
- {
-
- if (!target_has_execution)
- error (_("\
- Task switching not supported when debugging from core files\n\
- (use thread support instead)"));
- task_command_1 (taskno_str, from_tty, current_inferior ());
- }
- }
- static void
- ada_task_list_changed (struct inferior *inf)
- {
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- data->task_list_valid_p = 0;
- }
- static void
- ada_tasks_invalidate_pspace_data (struct program_space *pspace)
- {
- get_ada_tasks_pspace_data (pspace)->initialized_p = 0;
- }
- static void
- ada_tasks_invalidate_inferior_data (struct inferior *inf)
- {
- struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
- data->known_tasks_kind = ADA_TASKS_UNKNOWN;
- data->task_list_valid_p = 0;
- }
- static void
- ada_tasks_normal_stop_observer (struct bpstats *unused_args, int unused_args2)
- {
-
- ada_task_list_changed (current_inferior ());
- }
- static void
- ada_tasks_new_objfile_observer (struct objfile *objfile)
- {
- struct inferior *inf;
-
- if (objfile == NULL)
- {
-
- struct program_space *pspace;
- for (pspace = program_spaces; pspace != NULL; pspace = pspace->next)
- ada_tasks_invalidate_pspace_data (pspace);
- }
- else
- {
-
- ada_tasks_invalidate_pspace_data (objfile->pspace);
- }
-
- for (inf = inferior_list; inf != NULL; inf = inf->next)
- if (objfile == NULL || inf->pspace == objfile->pspace)
- ada_tasks_invalidate_inferior_data (inf);
- }
- extern initialize_file_ftype _initialize_tasks;
- void
- _initialize_tasks (void)
- {
- ada_tasks_pspace_data_handle = register_program_space_data ();
- ada_tasks_inferior_data_handle = register_inferior_data ();
-
- observer_attach_normal_stop (ada_tasks_normal_stop_observer);
- observer_attach_new_objfile (ada_tasks_new_objfile_observer);
-
- add_info ("tasks", info_tasks_command,
- _("Provide information about all known Ada tasks"));
- add_cmd ("task", class_run, task_command,
- _("Use this command to switch between Ada tasks.\n\
- Without argument, this command simply prints the current task ID"),
- &cmdlist);
- }