From 0cce5bd9dd8b740485b4ce847a0bd09a23097076 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Mon, 17 May 2010 17:23:33 +0000 Subject: [PATCH] Use breakpoint location to parse condition over current language. gdb/ChangeLog: * parse.c (parse_exp_in_context): When block is not NULL, use its associated language to parse the expression instead of the current_language. gdb/testsuite/ChangeLog: * gdb.ada/cond_lang: New testcase. --- gdb/ChangeLog | 6 +++ gdb/parse.c | 35 ++++++++++++-- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.ada/cond_lang.exp | 58 +++++++++++++++++++++++ gdb/testsuite/gdb.ada/cond_lang/a.adb | 21 ++++++++ gdb/testsuite/gdb.ada/cond_lang/foo.c | 25 ++++++++++ gdb/testsuite/gdb.ada/cond_lang/mixed.adb | 49 +++++++++++++++++++ gdb/testsuite/gdb.ada/cond_lang/mixed.ads | 20 ++++++++ gdb/testsuite/gdb.ada/cond_lang/pck.adb | 21 ++++++++ gdb/testsuite/gdb.ada/cond_lang/pck.ads | 20 ++++++++ 10 files changed, 255 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/cond_lang.exp create mode 100644 gdb/testsuite/gdb.ada/cond_lang/a.adb create mode 100644 gdb/testsuite/gdb.ada/cond_lang/foo.c create mode 100644 gdb/testsuite/gdb.ada/cond_lang/mixed.adb create mode 100644 gdb/testsuite/gdb.ada/cond_lang/mixed.ads create mode 100644 gdb/testsuite/gdb.ada/cond_lang/pck.adb create mode 100644 gdb/testsuite/gdb.ada/cond_lang/pck.ads diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f30de168598..de8f3bdf988 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -4,6 +4,12 @@ * c-lang.c (c_printstr): Compute real length of NUL terminated string at first. +2010-05-17 Joel Brobecker + + * parse.c (parse_exp_in_context): When block is not NULL, use + its associated language to parse the expression instead of + the current_language. + 2010-05-17 Joel Brobecker * jv-lang.c (java_lookup_class): Remove commented out code. diff --git a/gdb/parse.c b/gdb/parse.c index 1f2f6a7a912..cf5189ab4d2 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -1068,6 +1068,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma, { volatile struct gdb_exception except; struct cleanup *old_chain; + const struct language_defn *lang = NULL; int subexp; lexptr = *stringptr; @@ -1105,17 +1106,43 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma, expression_context_pc = BLOCK_START (expression_context_block); } + if (language_mode == language_mode_auto && block != NULL) + { + /* Find the language associated to the given context block. + Default to the current language if it can not be determined. + + Note that using the language corresponding to the current frame + can sometimes give unexpected results. For instance, this + routine is often called several times during the inferior + startup phase to re-parse breakpoint expressions after + a new shared library has been loaded. The language associated + to the current frame at this moment is not relevant for + the breakpoint. Using it would therefore be silly, so it seems + better to rely on the current language rather than relying on + the current frame language to parse the expression. That's why + we do the following language detection only if the context block + has been specifically provided. */ + struct symbol *func = block_linkage_function (block); + + if (func != NULL) + lang = language_def (SYMBOL_LANGUAGE (func)); + if (lang == NULL || lang->la_language == language_unknown) + lang = current_language; + } + else + lang = current_language; + expout_size = 10; expout_ptr = 0; expout = (struct expression *) xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size)); - expout->language_defn = current_language; + expout->language_defn = lang; expout->gdbarch = get_current_arch (); TRY_CATCH (except, RETURN_MASK_ALL) { - if (current_language->la_parser ()) - current_language->la_error (NULL); + if (lang->la_parser ()) + lang->la_error (NULL); } if (except.reason < 0) { @@ -1148,7 +1175,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma, if (out_subexp) *out_subexp = subexp; - current_language->la_post_parser (&expout, void_context_p); + lang->la_post_parser (&expout, void_context_p); if (expressiondebug) dump_prefix_expression (expout, gdb_stdlog); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e3905bada09..bc55d701dbf 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-05-17 Joel Brobecker + + * gdb.ada/cond_lang: New testcase. + 2010-05-17 Joel Brobecker * lib/gdb.exp (banned_variables): New variable/constant. diff --git a/gdb/testsuite/gdb.ada/cond_lang.exp b/gdb/testsuite/gdb.ada/cond_lang.exp new file mode 100644 index 00000000000..dcd46da270c --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang.exp @@ -0,0 +1,58 @@ +# Copyright 2010 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 "cond_lang" +set testfile "${testdir}/a" +set cfile "${testdir}/foo" +set adasrcfile ${srcdir}/${subdir}/${testfile}.adb +set csrcfile ${srcdir}/${subdir}/${cfile}.c +set cobject ${objdir}/${subdir}/${cfile}.o +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +gdb_compile "${csrcfile}" "${cobject}" object [list debug] +if {[gdb_compile_ada "${adasrcfile}" "${binfile}" executable [list debug]] != "" } { + return -1 +} + +clean_restart ${testfile} + +# Run to c_function an verify that the language automatically gets set to C. +runto c_function +gdb_test "show lang" \ + "The current source language is \"auto; currently c\"\\." + +# Now, insert a breakpoint inside an Ada unit, using a condition written +# in Ada. Even though the current language is "auto; currently c", we +# expect the debugger to parse the expression using Ada, because the +# current language mode is auto, and the breakpoint is inside Ada code. +set bp_location [gdb_get_line_number "STOP" ${testdir}/mixed.adb] +gdb_test "break mixed.adb:${bp_location} if light = green" \ + "Breakpoint \[0-9\]* at .*: file .*/mixed.adb, line \[0-9\]*\\." + +# Now, continue until we hit the breakpoint. If the condition is +# evaluated correctly, the first hit will be ignored, and the debugger +# will stop at the second hit only, when the "light" argument is equal +# to green. +gdb_test "continue" \ + "Breakpoint \[0-9\]*, mixed\\.break_me \\(light=green\\) at .*" + + diff --git a/gdb/testsuite/gdb.ada/cond_lang/a.adb b/gdb/testsuite/gdb.ada/cond_lang/a.adb new file mode 100644 index 00000000000..e1cda169951 --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/a.adb @@ -0,0 +1,21 @@ +-- Copyright 2010 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 . + +with Mixed; + +procedure A is +begin + Mixed.Start_Test; +end A; diff --git a/gdb/testsuite/gdb.ada/cond_lang/foo.c b/gdb/testsuite/gdb.ada/cond_lang/foo.c new file mode 100644 index 00000000000..fe27fc91c26 --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/foo.c @@ -0,0 +1,25 @@ +/* Copyright 2010 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +extern callme (void); + +void +c_function (void) +{ + callme (); +} + diff --git a/gdb/testsuite/gdb.ada/cond_lang/mixed.adb b/gdb/testsuite/gdb.ada/cond_lang/mixed.adb new file mode 100644 index 00000000000..1d5fd31ce6f --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/mixed.adb @@ -0,0 +1,49 @@ +-- Copyright 2010 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 . + +with Pck; use Pck; + +package body Mixed is + -- We are importing symbols from foo.o, so make sure this object file + -- gets linked in. + Pragma Linker_Options ("foo.o"); + + type Color is (Red, Green, Blue); + + procedure C_Function; + pragma Import (C, C_Function, "c_function"); + + procedure Callme; + pragma Export (C, Callme, "callme"); + + procedure Break_Me (Light : Color) is + begin + Put_Line ("Light: " & Color'Image (Light)); -- STOP + end Break_Me; + + procedure Callme is + begin + Break_Me (Red); + Break_Me (Green); + Break_Me (Blue); + end Callme; + + procedure Start_Test is + begin + -- Call C_Function, which will call Callme. + C_Function; + end Start_Test; + +end Mixed; diff --git a/gdb/testsuite/gdb.ada/cond_lang/mixed.ads b/gdb/testsuite/gdb.ada/cond_lang/mixed.ads new file mode 100644 index 00000000000..b3a712a4a2e --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/mixed.ads @@ -0,0 +1,20 @@ +-- Copyright 2010 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 . + +package Mixed is + + procedure Start_Test; + +end Mixed; diff --git a/gdb/testsuite/gdb.ada/cond_lang/pck.adb b/gdb/testsuite/gdb.ada/cond_lang/pck.adb new file mode 100644 index 00000000000..d412feca553 --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/pck.adb @@ -0,0 +1,21 @@ +-- Copyright 2010 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 . + +package body Pck is + procedure Put_Line (S : String) is + begin + null; + end Put_Line; +end Pck; diff --git a/gdb/testsuite/gdb.ada/cond_lang/pck.ads b/gdb/testsuite/gdb.ada/cond_lang/pck.ads new file mode 100644 index 00000000000..4fbc2a25715 --- /dev/null +++ b/gdb/testsuite/gdb.ada/cond_lang/pck.ads @@ -0,0 +1,20 @@ +-- Copyright 2010 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 . + +package Pck is + procedure Put_Line (S : String); + -- Stub implementation of Put_Line to avoid a dependency on Text_IO. + -- Does actually nothing. +end Pck; -- 2.30.2