From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7346 invoked by alias); 25 Mar 2009 19:56:53 -0000 Received: (qmail 7336 invoked by uid 22791); 25 Mar 2009 19:56:51 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_44,J_CHICKENPOX_45 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Mar 2009 19:56:42 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 663122BAC17; Wed, 25 Mar 2009 15:56:40 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id CdD8g+OLzfvV; Wed, 25 Mar 2009 15:56:40 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id EA6A82BAC14; Wed, 25 Mar 2009 15:56:39 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 705145BD21; Wed, 25 Mar 2009 12:56:33 -0700 (PDT) Date: Wed, 25 Mar 2009 19:58:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFC] Add task-specific breakpoint capability... Message-ID: <20090325195633.GC9472@adacore.com> References: <20090324203319.GB24100@adacore.com> <20090325162141.GW9472@adacore.com> <20090325162711.GX9472@adacore.com> <20090325165433.GZ9472@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ExXT7PjY8AI4Hyfa" Content-Disposition: inline In-Reply-To: <20090325165433.GZ9472@adacore.com> User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-03/txt/msg00560.txt.bz2 --ExXT7PjY8AI4Hyfa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1163 OK, here is a new version of the patch. Hopefully, everything that we discussed earlier should be incorporated, and I also tried to fix a few tab/spaces issues (my favorite :). I'm also adding a testcase. gdb/: 2009-03-25 Joel Brobecker Provide support for (Ada) task-specific breakpoints. * ada-lang.h (ada_get_task_number): Add declaration. (breakpoint_ada_task_match): Delete declaration. * ada-tasks.c (ada_get_task_number): Make non-static. * breakpoint.h (struct breakpoint): Add field "task". * breakpoint.c (print_one_breakpoint_location): Add handling of task-specific breakpoints. (create_breakpoint, create_breakpoints, find_condition_and_thread): New parameter "task". (break_command_really): Update calls to find_condition_and_thread and create_breakpoints. (breakpoint_re_set_one): Update call to find_condition_and_thread. Set b->task. gdb/testsuite/: 2009-03-25 Joel Brobecker * gdb.ada/tasks: New testcase. All tested on x86_64-linux. Will commit in a day or two... -- Joel --ExXT7PjY8AI4Hyfa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="task.diff" Content-length: 7153 diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index 88b6c16..c9554a4 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -461,14 +461,14 @@ extern char *ada_main_name (void); extern int valid_task_id (int); +extern int ada_get_task_number (ptid_t); + extern void ada_adjust_exception_stop (bpstat bs); extern void ada_print_exception_stop (bpstat bs); extern int ada_get_current_task (ptid_t); -extern int breakpoint_ada_task_match (CORE_ADDR, ptid_t); - extern int ada_print_exception_breakpoint_nontask (struct breakpoint *); extern void ada_print_exception_breakpoint_task (struct breakpoint *); diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index d0ce5ab..4f0aaf5 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -160,7 +160,7 @@ static int stale_task_list_p = 1; /* Return the task number of the task whose ptid is PTID, or zero if the task could not be found. */ -static int +int ada_get_task_number (ptid_t ptid) { int i; diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 7ffdf77..c742c7b 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1893,8 +1893,9 @@ int breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) { const struct bp_location *bpt; - /* The thread ID associated to PTID, computed lazily. */ + /* The thread and task IDs associated to PTID, computed lazily. */ int thread = -1; + int task = 0; ALL_BP_LOCATIONS (bpt) { @@ -1920,6 +1921,17 @@ breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) continue; } + if (bpt->owner->task != 0) + { + /* This is a task-specific breakpoint. Check that ptid + matches that task. If task hasn't been computed yet, + it is now time to do so. */ + if (task == 0) + task = ada_get_task_number (ptid); + if (bpt->owner->task != task) + continue; + } + if (overlay_debugging && section_is_overlay (bpt->section) && !section_is_mapped (bpt->section)) @@ -3567,12 +3579,20 @@ print_one_breakpoint_location (struct breakpoint *b, break; } - if (!part_of_multiple && b->thread != -1) + if (!part_of_multiple) { - /* FIXME: This seems to be redundant and lost here; see the - "stop only in" line a little further down. */ - ui_out_text (uiout, " thread "); - ui_out_field_int (uiout, "thread", b->thread); + if (b->thread != -1) + { + /* FIXME: This seems to be redundant and lost here; see the + "stop only in" line a little further down. */ + ui_out_text (uiout, " thread "); + ui_out_field_int (uiout, "thread", b->thread); + } + else if (b->task != 0) + { + ui_out_text (uiout, " task "); + ui_out_field_int (uiout, "task", b->task); + } } ui_out_text (uiout, "\n"); @@ -5124,7 +5144,7 @@ static void create_breakpoint (struct symtabs_and_lines sals, char *addr_string, char *cond_string, enum bptype type, enum bpdisp disposition, - int thread, int ignore_count, + int thread, int task, int ignore_count, struct breakpoint_ops *ops, int from_tty, int enabled) { struct breakpoint *b = NULL; @@ -5156,6 +5176,7 @@ create_breakpoint (struct symtabs_and_lines sals, char *addr_string, set_breakpoint_count (breakpoint_count + 1); b->number = breakpoint_count; b->thread = thread; + b->task = task; b->cond_string = cond_string; b->ignore_count = ignore_count; @@ -5334,7 +5355,7 @@ static void create_breakpoints (struct symtabs_and_lines sals, char **addr_string, char *cond_string, enum bptype type, enum bpdisp disposition, - int thread, int ignore_count, + int thread, int task, int ignore_count, struct breakpoint_ops *ops, int from_tty, int enabled) { @@ -5346,7 +5367,7 @@ create_breakpoints (struct symtabs_and_lines sals, char **addr_string, create_breakpoint (expanded, addr_string[i], cond_string, type, disposition, - thread, ignore_count, ops, from_tty, enabled); + thread, task, ignore_count, ops, from_tty, enabled); } update_global_location_list (1); @@ -5453,7 +5474,7 @@ do_captured_parse_breakpoint (struct ui_out *ui, void *data) If no thread is found, *THREAD is set to -1. */ static void find_condition_and_thread (char *tok, CORE_ADDR pc, - char **cond_string, int *thread) + char **cond_string, int *thread, int *task) { *cond_string = NULL; *thread = -1; @@ -5496,6 +5517,18 @@ find_condition_and_thread (char *tok, CORE_ADDR pc, if (!valid_thread_id (*thread)) error (_("Unknown thread %d."), *thread); } + else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) + { + char *tmptok; + + tok = end_tok + 1; + tmptok = tok; + *task = strtol (tok, &tok, 0); + if (tok == tmptok) + error (_("Junk after task keyword.")); + if (!valid_task_id (*task)) + error (_("Unknown task %d\n"), *task); + } else error (_("Junk at end of arguments.")); } @@ -5534,6 +5567,7 @@ break_command_really (char *arg, char *cond_string, int thread, int i; int pending = 0; int not_found = 0; + int task = 0; sals.sals = NULL; sals.nelts = 0; @@ -5635,7 +5669,8 @@ break_command_really (char *arg, char *cond_string, int thread, re-parse it in context of each sal. */ cond_string = NULL; thread = -1; - find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, &thread); + find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, + &thread, &task); if (cond_string) make_cleanup (xfree, cond_string); } @@ -5652,7 +5687,7 @@ break_command_really (char *arg, char *cond_string, int thread, hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, tempflag ? disp_del : disp_donttouch, - thread, ignore_count, ops, from_tty, enabled); + thread, task, ignore_count, ops, from_tty, enabled); } else { @@ -7491,11 +7526,14 @@ breakpoint_re_set_one (void *bint) { char *cond_string = 0; int thread = -1; + int task = 0; + find_condition_and_thread (s, sals.sals[0].pc, - &cond_string, &thread); + &cond_string, &thread, &task); if (cond_string) b->cond_string = cond_string; b->thread = thread; + b->task = task; b->condition_not_parsed = 0; } expanded = expand_line_sal_maybe (sals.sals[0]); diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 94287de..e18717d 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -423,9 +423,12 @@ struct breakpoint hardware. */ enum watchpoint_triggered watchpoint_triggered; - /* Thread number for thread-specific breakpoint, or -1 if don't care */ + /* Thread number for thread-specific breakpoint, or -1 if don't care. */ int thread; + /* Ada task number for task-specific breakpoint, or 0 if don't care. */ + int task; + /* Count of the number of times this breakpoint was taken, dumped with the info, but not used for anything else. Useful for seeing how many times you hit a break prior to the program --ExXT7PjY8AI4Hyfa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="task-tc.diff" Content-length: 5480 diff --git a/gdb/testsuite/gdb.ada/tasks.exp b/gdb/testsuite/gdb.ada/tasks.exp new file mode 100644 index 0000000..e5d9f92 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tasks.exp @@ -0,0 +1,79 @@ +# Copyright 2009 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if $tracelevel then { + strace $tracelevel +} + +load_lib "ada.exp" + +set testdir "tasks" +set testfile "${testdir}/foo" +set srcfile ${srcdir}/${subdir}/${testfile}.adb +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +set bp_location [gdb_get_line_number "STOP_HERE" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +# Make sure that all tasks appear in the "info tasks" listing, and +# that the active task is the environment task. +gdb_test "info tasks" \ + [join {" ID TID P-ID Pri State Name" \ + "\\* 1 .* main_task" \ + " 2 .* task_list\\(1\\)" \ + " 3 .* task_list\\(2\\)" \ + " 4 .* task_list\\(3\\)"} \ + "\r\n"] \ + "info tasks before inserting breakpoint" + +# Now, insert a breakpoint that should stop only if task 3 stops. +gdb_test "break break_me task 3" "Breakpoint .* at .*" + +# Continue to that breakpoint. Task 2 should hit it first, and GDB +# is expected to ignore that hit and resume the execution. Only then +# task 3 will hit our breakpoint, and GDB is expected to stop at that +# point. +gdb_test "continue" \ + ".*Breakpoint.*, foo.break_me \\(\\).*" \ + "continue to breakpoint" + +# Check that it is indeed task 3 that hit the breakpoint by checking +# which is the active task. +gdb_test "info tasks" \ + [join {" ID TID P-ID Pri State Name" \ + " 1 .* main_task" \ + " 2 .* task_list\\(1\\)" \ + "\\* 3 .* task_list\\(2\\)" \ + " 4 .* task_list\\(3\\)"} \ + "\r\n"] \ + "info tasks after hitting breakpoint" + +# Now, resume the execution and make sure that GDB does not stop when +# task 4 hits the breakpoint. Continuing thus results in our program +# running to completion. +gdb_test "continue" \ + ".*Program exited normally\..*" \ + "continue until end of program" + diff --git a/gdb/testsuite/gdb.ada/tasks/foo.adb b/gdb/testsuite/gdb.ada/tasks/foo.adb new file mode 100644 index 0000000..edf66be --- /dev/null +++ b/gdb/testsuite/gdb.ada/tasks/foo.adb @@ -0,0 +1,68 @@ +-- Copyright 2009 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +procedure Foo is + + task type Caller is + entry Initialize; + entry Call_Break_Me; + entry Finalize; + end Caller; + type Caller_Ptr is access Caller; + + procedure Break_Me is + begin + null; + end Break_Me; + + task body Caller is + begin + accept Initialize do + null; + end Initialize; + accept Call_Break_Me do + Break_Me; + end Call_Break_Me; + accept Finalize do + null; + end Finalize; + end Caller; + + Task_List : array (1 .. 3) of Caller_Ptr; + +begin + + -- Start all our tasks, and call the "Initialize" entry to make + -- sure all of them have now been started. We call that entry + -- immediately after having created the task in order to make sure + -- that we wait for that task to be created before we try to create + -- another one. That way, we know that the order in our Task_List + -- corresponds to the order in the GNAT runtime. + for J in Task_List'Range loop + Task_List (J) := new Caller; + Task_List (J).Initialize; + end loop; + + -- Next, call their Call_Break_Me entry of each task, using the same + -- order as the order used to create them. + for J in Task_List'Range loop -- STOP_HERE + Task_List (J).Call_Break_Me; + end loop; + + -- And finally, let all the tasks die... + for J in Task_List'Range loop + Task_List (J).Finalize; + end loop; +end Foo; --ExXT7PjY8AI4Hyfa--