This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/Ada] Implement Ada tasking support


Hello,

Following our re-design of the ada-tasks module a while back to be
submittable, I think it is now time to contribute this code.

Ada is one of these languages that includes tasking constructions
built in to the language. While in C we use a thread library,
in Ada, we use what is called "tasks". What this new module provides
is support for examining these tasks:

  1. Getting the list of tasks and their current state
  2. Switching from task to task

(1) is achieved by poking into an array in the GNAT Tasking runtime
    named System.Tasking.Debug.Known_Tasks. We rely on the debugging
    information to find how the Ada Task Control Block structure is
    laid out, and get the pieces of info that we are looking at.
    This part requires a little bit of code, particularly since
    we try to accomodate maybe older versions of the GNAT runtime too.
    But the code itself isn't very complicated. Just walking through
    the type structures, and storing the information in a list of our
    own.

(2) is a little more tricky - basically, what we need to do is relate
    the information in each Ada Task Control Block (ATCB) back to
    the associated thread. In practice, there are two fields, the
    "thread" field, and the "LWP" field that we can use, whose content,
    meaning and even availability depends on the target, and transform
    that into the ptid of the corresponding thread. The good news is
    that we know fairly well, for each target, what to use and how,
    in order to get that ptid. So this strongly suggested a target
    method.

Pretty much all of the code is contained in one file: ada-tasks.c.
The rest is pretty much adding the new target method and providing
an implementation.

If there is a piece on which I'd like some feedback on, it's part (2).
I am including an implementation for Linux targets. It's one of the
less simple ones, just to show you what it would look like. Other
target will be a simple assembly of the information provided.  Once
the principle is confirmed and this patch goes in, I can submit support
for the others.

I will also attach a patch for the documentation. But here is a summary
of the commands that are being added:

  * info tasks: Prints the list of Ada tasks, and a short description
    of each one of them. For instance:

        (gdb) info tasks
          ID       TID P-ID Pri State                  Name
           1   8089008    0  48 Child Termination Wait main_task
           2   8089858    1  48 Accept Statement       my_callee
        *  3   808c9a8    1  48 Running                my_caller

  * info task TASKNO: Prints a more verbose description of a task:

        (gdb) info tasks 3
        Ada Task: 808c9a8
        Name: my_caller
        Thread: 0
        LWP: 0x2bd0
        Parent: 1 (main_task)
        Base Priority: 48
        State: Runnable


  * task [TASKNO]: Switch to the given task (by switching to the
    associated thread). If TASKNO is omitted, then print the task
    number of the current task. For instance:

        (gdb) task
        [Current task is 3]
        (gdb) task 1
        [Switching to task 1]
        #3  0x0804a21a in task_switch () at task_switch.adb:55
        55      end Task_Switch;

I should also say that this patch introduces a couple of uses
of current_gdbarch. Both of them are in the same function, so I should
probably make it into one instance. Will do before committing.
However, the real issue is how to get the right gdbarch in this case.
Ulrich?

I have omitted the part that allows you to restrict a breakpoint to
a given task ("break LINESPEC task TASKNO") for now, but will soon
start discussing this if this goes in.

Apart from that, I think that's it for the introduction to this patch.
I hope we can make it part of GDB soon.

gdb/:
2008-09-22  Joel Brobecker  <brobecker@adacore.com>

        * target.h (struct target_ops): Add new field to_get_ada_task_ptid.
        (target_get_ada_task_ptid): New macro.
        * target.c (default_get_ada_task_ptid): New function.
        (update_current_target): Inherit field default_get_ada_task_ptid.
        (update_current_target): Make default_get_ada_task_ptid the default
        value for field to_get_ada_task_ptid.
        * ada-lang.h (struct task_control_block): Delete. Never used.
        (struct task_ptid, task_ptid_t, struct task_entry, task_list):
        Likewise.
        (struct ada_task_info): New.
        (ada_task_is_alive, ada_find_printable_frame)
        (ada_task_list_iterator_ftype, iterate_over_live_ada_tasks): Add
        declarations.
        (ada_build_task_list): Update prototype.
        (init_task_list, ada_is_exception_breakpoint): Remove prototypes.
        * ada-lang.c (ada_find_printable_frame): Make non-static.
        * ada-tasks.c: New file.
        * Makefile.in (SFILES): Add ada-tasks.c.
        (COMMON_OBS): Add ada-tasks.o.
        * linux-thread-db.c (thread_db_find_thread_from_tid)
        (thread_db_get_ada_task_ptid): New functions.
        (init_thread_db_ops): Set thread_db_ops.to_get_ada_task_ptid.

This change affects the completion testcase a little bit in an expected
way. Adjusted thusly:

gdb/testsuite:
2008-09-22  Joel Brobecker  <brobecker@adacore.com>

        * gdb.base/completion.exp: Update expected output following
        the addition of the "info tasks" command.

Tested on x86-linux. No regression. I will also provide a simple
testcase that have been very useful to me in the past few years.
For when the patch goes in.

Finally, the documentation:
gdb/doc:

2008-09-22  Joel Brobecker  <brobecker@adacore.com>

        * gdb.texinfo (Ada Tasks, Ada Tasks and Core Files): New nodes.

OK to commit?

Thanks,
-- 
Joel

Attachment: ada-tasks.diff
Description: Text document

Attachment: doc-ada-tasks.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]