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.
This patch enhances the -ada-task-info command, adding a new
field called "thread-id" in the command output. This field
provides the ID of the task's corresponding thread (if that
information could not be determined, the field is omitted).
This field is useful in the context of GDB/MI users, because
it allows a quick translation from Ada task to thread, and
thus easy use of all the commands that take a --thread argument.
gdb/ChangeLog:
* ada-tasks.c (print_ada_task_info): Add "thread-id" field
in output of -ada-task-info GDB/MI command.
This patch introduces a new GDB/MI command: -ada-tasks-info,
which is meant to be the MI equivalent of the CLI `info tasks'
command.
This new command returns an array, with each row corresponding
to one task. For now, the columns of the array corresponds to
the columns displayed in the CLI output.
gdb/ChangeLog:
* ada-lang.h (struct inferior): Declare.
(print_ada_task_info): Add declaration.
* ada-tasks.c (print_ada_task_info): Make non-static.
* mi/mi-cmds.c (mi_cmds): Add "ada-task-info".
* mi/mi-cmds.h (mi_cmd_ada_task_info): Add declaration.
* mi/mi-main.c: #include "ada-lang.h".
(mi_cmd_list_features): Add "ada-task-info" to the list
of supported features.
(mi_cmd_ada_task_info): New function.
This is in preparation for providing a GDB/MI equivalent of
the `info tasks' command. The previous implementation was using
various printf commands to generate the command output, which
does not work at all if we want to use that same code to generate
the result for that new GDB/MI command.
This patch thus re-implements the `info tasks' command (with no
arguments) in a way that makes it GDB/MI friendly.
There is an additional hicup, which is the fact that the `info tasks'
command displays a completely different type of output when a task
ID is given. For instance:
(gdb) info task 2
Ada Task: 0x644d20
Name: my_callee
Thread: 0
LWP: 0x5809
Parent: 1 (main_task)
Base Priority: 48
State: Blocked in accept or select with terminate
The above output is better when in CLI mode, but really not
what we want when in GDB/MI mode. In GDB/MI mode, we want to
follow what the `-thread-info' command does when a task-id
is given as an argument, which is to produce the same table,
but with only one element/task in it.
For compatibility as well as practical reasons, we do not want
to change the output of the `info task TASKNO' command when in
CLI mode. But it's easy to preserve this behavior while providing
the desirable output when in GDB/MI mode. For this, the function
used to generated the `info tasks' output has been enhanced to take
an argument interpreted as a string. The CLI command knows to never
provide that argument, while the GDB/MI command will pass one if
provided by the user.
gdb/ChangeLog:
* ada-tasks.c (print_ada_task_info): New function, merging
short_task_info and info_tasks together. Reimplement using
ui-out instead of printing to stdout directly. Move the code
building and checking the task list here, instead of leaving it
in info_tasks_command.
(info_task): Move the code building and checking the task
list here, instead of leaving it in info_tasks_command.
(info_tasks_command): Delete code building and checking
the task list - moved elsewhere. Update calls to info_tasks
and info_task.
One of the minor changes the switch caused is the introduction
of a space between the "current" column, and the task "ID"
column, which wasn't there before. This matches what we do
in the "info threads" command, so I kept that change. This
required an adjustment in the testsuite, however...
gdb/testsuite/ChangeLog:
* gdb.ada/tasks.exp: Make the expected output for
the `info tasks' tests more resilient to spacing
changes.
Originally, this function had a parameter called `warn_if_null'
which would trigger a message to be printed on stdout if the
program was found to not use Ada tasking. It used one of the printf_
functions for that, which is wrong when considering the context of
GDB/MI interpreters.
So, this patch changes this function to stop printing the message,
and leaves that part to the callers instead. It also changes the
semantics slightly to return the number of tasks found, rather than
a yes/no answer. Not strictly needed, but simple enough to do, and
potentially useful later.
gdb/ChangeLog:
* ada-lang.h (ada_build_task_list): Remove parameter
`warn_if_null'.
* ada-tasks.c (ada_build_task_list): Remove parameter
`warn_if_null'. Adjust implementation and documentation.
(valid_task_id, ada_get_environment_task)
iterate_over_live_ada_tasks): Adjust call to ada_build_task_list.
(info_tasks_command): Adjust implementation.
(task_command): Likewise.
* ravenscar-thread.c (ravenscar_find_new_threads): Fix call
to ada_build_task_list.
Instead of storing "the" Ada task list using a static global
in ada-tasks, this patch stores that information inside
per-inferior data.
We also add in the per-inferior data the location and type of
data used in the runtime to store that task list. Previously,
this information was saved as a static variable in one of the
functions, but this approach has the major flaw that it does
not handle multi-inferior debugging.
gdb/ChangeLog:
* ada-tasks.c (ada_tasks_check_symbol_table, task_list): Delete.
(enum ada_known_tasks_kind, struct ada_tasks_inferior_data): New.
(ada_tasks_inferior_data_handle): New static global.
(get_ada_tasks_inferior_data): New function.
(ada_get_task_number, get_task_number_from_id, valid_task_id)
(ada_get_environment_task, iterate_over_live_ada_tasks)
(add_ada_task, read_known_tasks_array, read_known_tasks_list):
Adjust.
(ada_set_current_inferior_known_tasks_addr): New function.
(read_known_tasks, ada_build_task_list, short_task_info)
(info_tasks, info_task, info_tasks_command, task_command_1)
(task_command, ada_task_list_changed): Adjust.
(ada_tasks_invalidate_inferior_data): New function.
(ada_normal_stop_observer, ada_new_objfile_observer): Adjust.
(_initialize_tasks): Set ada_tasks_inferior_data_handle.
* ada-lang.h (struct inferior): Add declaration.
(ada_task_list_changed): Update profile.
* remote-wtx-pd.c: #include "inferior.h".
(switch_to_pd_internal): Update call to ada_task_list_changed.
This module caches the type description of various elements of
the Ada Task Control Block (ATCB). This cache was implemented
as static globals, which is wrong in the case where we have
multiple inferiors. This change cleans things up a bit by moving
some of these static globals to a per-program-space area.
gdb/ChangeLog:
* ada-tasks.c: #include "progspace.h" and "objfiles.h".
(atcb_type, atcb_common_type, atcb_ll_type, atcb_call_type)
(atcb_fieldno): Delete these static globals.
(struct ada_tasks_pspace_data): New struct.
(ada_tasks_pspace_data_handle): New static global.
(get_ada_tasks_pspace_data): New function.
(ada_tasks_invalidate_pspace_data): New function.
(get_tcb_types_info, ptid_from_atcb_common, read_atcb)
(read_known_tasks_list, ada_new_objfile_observer): Adjust.
(_initialize_tasks): Create this module's per-progspace
data handle.
`atcb' is clearer than `tcb', as it stands for Ada Task Control
Block. This is also consistent with the rest of the code, which
uses atcb...
gdb/ChangeLog:
* ada-tasks.c (struct atcb_fieldnos): Renames struct tcb_fieldnos.
The mapping between Ada tasks, and the underlying threads is
normally maintained by the GNAT runtime under the known_tasks
array. For performance reasons, this array is just a static
array with 10_000 entries in it. However, this is not very
practical in certain environments where memory is limited.
For those environments, the runtime has been enhanced to use
an alternate scheme with a linked list.
This change enhances the Ada tasking support to recognize this
situation and use the correct way of reading the tasks info
based on the the situation.
gdb/ChangeLog (Tristan Gingold)
* ada-tasks.c (KNOWN_TASKS_LIST): New macro.
(tcb_fieldno): Add activation_link field.
(get_known_tasks_addr): Moved and rewritten.
(get_tcb_types_info): Set activation_link field.
(read_known_tasks_array): Add parameter. Rewritten.
(read_known_tasks_list): New function.
(read_known_tasks): New function.
(ada_build_task_list): Call read_known_tasks instead of
read_known_tasks_array.
* ravenscar-thread.c: Add first_task_name constant.
(has_ravenscar_runtime): Check for task list too.
Just some minor cleanup changes in preparation for an upcoming
change...
gdb/ChangeLog (Tristan Gingold)
* ada-tasks.c: Renames fieldno to actb_fieldno.
(ada_get_task_number): Indentation.
(get_tcb_types_info): Remove all parameters. Write directly
the globals.
(ptid_from_atcb_common): Adjust.
(read_atcb): Adjust.
Type symbols that are used to decode the Ada task control block may be
duplicated in any unit that uses a tasking feature; an Ada lookup of
these symbols would collect all the duplicated instances and could
provoke the load of a huge amount of debug symbols in the process.
However, when decoding the task information, we are only interested in
one instance; and we have the full name of the symbol anyway. So use
a C lookup instead of an Ada lookup.
2010-11-05 Jerome Guitton <guitton@adacore.com>
* ada-tasks.c (get_tcb_types_info): Use C lookups to get
ATCB symbols.
This new function is needed by the ravenscar-thread layer.
gdb/ChangeLog:
* ada-tasks.c (iterate_over_live_ada_tasks): New function.
* ada-lang.h (iterate_over_live_ada_tasks): Declare.
After thread support over core files was added for GNU/Linux was added,
we started noticing the following type of crash when trying to perform
task switches (this is a bit accademic, since task switching is not
supported when debugging core files - this is what our testcase was
verifying).
(please check out the comment inside ada-tasks.c:task_command for
more details on this topic)
The reason for the crash comes from the fact that the GNU/Linux thread
layer now gets pushed on the target stack, causing the associated
to_get_ada_task_ptid target method to be activated. This routine
makes the assumption that, for all threads, the private area is not
NULL. This is incorrect in the case of core files, as the core layer
creates some threads with no private data.
But, taking a step back, we don't need to try to compute the task ptid,
as we'll never be using it anyways (we only use it for task switching).
So the fix is to avoid the ptid computation altogether when debugging
a core file.
gdb/ChangeLog:
* ada-tasks.c (read_atcb): Do not compute the task ptid when
debugging a core file.
This is to prevent an internal error during an Ada task switch. A task
switch is simply a thread switch under the hood. What we do is collect
the info from the Ada Task Control Block, deduce the associated thread
ptid, and then switch to that thread. If the thread ptid computation
routine has not been implemented for the target, of if there is a bug,
then we end up computing a bogus ptid which GDB does not know about,
which eventually leads to an assertion failure:
(gdb) task 1
[New Thread 5715]
/[...]/gdb/thread.c:595: internal-error: is_thread_state:
Assertion `tp' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
When this happens, it's just nicer for the user to print an error
message, and cancel the task switch. After this patch is applied,
this is what we get:
(gdb) task 1
[New Thread 10250]
Unable to compute thread ID for task 1.
Cannot switch to this task.
gdb/ChangeLog:
* ada-tasks.c (task_command_1): Check that the task ptid is valid
before doing the associated thread switch.
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* valarith.c (value_subscript, value_subscripted_rvalue,
value_bitstring_subscript, value_ptradd): Use LONGEST instead
of value as type of the index argument.
(value_ptrsub): Remove.
* wrapper.h (gdb_value_subscript): Use LONGEST instead of
value as type of the index argument.
* wrapper.c (gdb_value_subscript): Likewise.
Update calls to gdb_value_subscript, value_subscript,
value_subscripted_rvalue, value_bitstring_subscript and
value_ptradd to use LONGEST instead of value as index
argument type. Use value_ptradd instead of value_ptrsub.
* ada-lang.c (ada_value_subscript, ada_value_ptr_subscript,
ada_tag_name_2): Update.
* ada-tasks.c (read_atcb): Update.
* eval.c (evaluate_subexp_standard): Update.
* valarith.c (value_subscript): Update.
* gnu-v2-abi.c (gnuv2_virtual_fn_field): Update.
* gnu-v3-abi.c (gnuv3_get_virtual_fn, gnuv3_baseclass_offset,
gnuv3_method_ptr_to_value): Update.
* jv-lang.c (evaluate_subexp_java): Update.
* m2-lang.c (evaluate_subexp_modula2): Update.
* python/python-value.c (valpy_getitem, valpy_binop): Update.
* wrapper.c (gdb_value_subscript): Update.
* varobj.c (c_describe_child): Update.
Silence a few -Wmissing-prototypes warnings.
PR build/9877:
* amd64-nat.c: Include "amd64-nat.h".
* fork-child.c (_initialize_fork_child): Ditto.
* gcore.c (_initialize_gcore): Ditto.
* inf-ptrace.c: Include "inf-ptrace.h".
(inf_ptrace_store_registers): Make it static.
* linux-nat.c (linux_nat_terminal_ours): Make it static.
(_initialize_linux_nat): Declare before definition.
* linux-tdep.c: Include "linux-tdep.h".
* linux-thread-db.c (_initialize_thread_db): Declare before
definition.
* proc-service.c (_initialize_proc_service): Ditto.
* remote.c (remote_send_printf): Make it static.
* solib.c: Include "solib.h".
* symfile-mem.c (_initialize_symfile_mem): Declare before
definition.
* ada-lang.c (ada_la_decode, ada_match_name)
(ada_suppress_symbol_printing, ada_is_array_type)
(ada_value_ptr_subscript, ada_array_length)
(ada_to_static_fixed_value): Make them static.
(_initialize_ada_language): Declare before definition.
* ada-tasks.c (ada_get_task_number, ada_get_environment_task)
(ada_task_list_changed, ada_new_objfile_observer): Make them
static.
(_initialize_tasks): Declare before definition.
* addrmap.c (_initialize_addrmap): Declare before definition.
* auxv.c (default_auxv_parse): Make it static.
* bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make
them static.
* breakpoint.c (remove_sal): Add line break.
(expand_line_sal_maybe): Make it static.
* cp-name-parser.y: Include "cp-support.h".
* cp-valprint.c (cp_find_class_member): Make it static.
* eval.c (value_f90_subarray): Ditto.
* exceptions.c (print_any_exception): Ditto.
* findcmd.c (_initialize_mem_search): Declare before definition.
* frame.c (frame_observer_target_changed): Make it static.
* gnu-v3-abi.c (gnuv3_find_method_in): Make it static.
* inf-child.c: Include "inf-child.h".
* inferior.h (valid_inferior_id): Rename to ...
(valid_gdb_inferior_id): ... this.
* infrun.c (infrun_thread_stop_requested, siginfo_make_value):
Make them static.
* jv-lang.c (java_language_arch_info): Make it static.
* m2-typeprint.c (m2_get_discrete_bounds): Ditto.
* osdata.c (info_osdata_command): Make it static.
* regcache.c (regcache_observer_target_changed): Make it static.
* reverse.c (_initialize_reverse): Declare before definition.
* stabsread.c (cleanup_undefined_types_noname)
(cleanup_undefined_types_1): Make them static.
* symfile.c (place_section): Make it static.
* symtab.c (find_pc_sect_psymtab_closer): Make it static.
* target-descriptions.c (_initialize_target_descriptions): Declare
before definition.
* target.c (default_get_ada_task_ptid, find_default_can_async_p)
(find_default_is_async_p, find_default_supports_non_stop): Make
them static.
(target_supports_non_stop): Add prototype.
(dummy_pid_to_str): Make it static.
* utils.c (_initialize_utils): Declare before definition.
* ada-exp.y (_initialize_ada_exp): Declare before definition.
* solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype.
* target.h (struct target_ops): Add a prototype to the
to_can_execute_reverse callback.
* macroscope.c (_initialize_macroscope): Declare before definition.
* cp-namespace.c (_initialize_cp_namespace): Declare before definition.
* python/python.c (_initialize_python): Declare before definition.
* tui/tui-command.c: Include "tui/tui-command.h".
* tui/tui-data.c (init_content_element, init_win_info): Make them
static.
* tui/tui-disasm.c: Include "tui/tui-disasm.h".
* tui/tui-interp.c (_initialize_tui_interp): Declare before
definition.
* tui/tui-layout.c: Include "tui/tui-layout.h".
(_initialize_tui_layout): Declare before definition.
* tui/tui-regs.c: Include "tui/tui-regs.h".
(tui_display_reg_element_at_line): Make it static.
(_initialize_tui_regs): Declare before definition.
* tui/tui-stack.c (_initialize_tui_stack): Declare before
definition.
* tui/tui-win.c: Include "tui/tui-win.h".
(_initialize_tui_win): Declare before definition.
(tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH.
* tui/tui-win.h (tui_sigwinch_handler): Delete declaration.
(tui_get_cmd_list): Add a prototype.
* tui/tui-windata.c: Include tui-windata.h.
* tui/tui-wingeneral.c (box_win): Make it static.
* cli/cli-logging.c (show_logging_command): Make it static.
(_initialize_cli_logging): Declare before definition.
* mi/mi-common.c (_initialize_gdb_mi_common): Declare before
definition.
* ada-tasks.c (ada_normal_stop_observer): Adjust prototype.
* infcmd.c (finish_command_continuation): Pass '1' for
'print_frame' parameter to the observer.
* infrun.c (normal_stop): Don't print mi-specific information
here. Pass 'stop_print_frame' to the 'print_frame' parameter
of the observer.
* mi/mi-interp.c (mi_on_normal_stop): Adjust prototype.
If we need to print frame, and current uiout is not the MI one,
print frame again.
make it non-static.
* ada-lang.h (task_control_block): declaration moved from ada-task.c
to ada-lang.h; this is needed to be able to implement the kill command
in multi-task mode.
(task_ptid): Ditto.
(task_entry): Ditto.
(task_list): Ditto.
(ada_build_task_list): Ditto.
* ada-lang.c: Conditionalize routines and data structures related
to breakpoints, exceptions, completion, and symbol caching on
GNAT_GDB, since these are not yet used in the submitted public sources.
(ada_main_name): Editorial: Move definition out of exception-related
code.
* ada-lang.h: run through gdb_indent.sh
* ada-tasks.c: run through gdb_indent.sh
* ada-typeprint.c: run through gdb_indent.sh
* ada-valprint.c: run through gdb_indent.sh
malloc() with xmalloc
* ada-tasks.c (init_task_list): replace calls to free with xfree()
* ada-lang.c (replace_operator_with_call, fill_in_ada_prototype,
ada_finish_decode_line_1, all_sals_for_line
ada_breakpoint_rewrite): replace calls to free() with xfree()