Use breakpoint location to parse condition over current language.
authorJoel Brobecker <brobecker@gnat.com>
Mon, 17 May 2010 17:23:33 +0000 (17:23 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Mon, 17 May 2010 17:23:33 +0000 (17:23 +0000)
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
gdb/parse.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/cond_lang.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/a.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/foo.c [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/mixed.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/mixed.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/cond_lang/pck.ads [new file with mode: 0644]

index f30de16..de8f3bd 100644 (file)
@@ -6,6 +6,12 @@
 
 2010-05-17  Joel Brobecker  <brobecker@adacore.com>
 
+       * 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  <brobecker@adacore.com>
+
        * jv-lang.c (java_lookup_class): Remove commented out code.
        (type_from_class): Likewise.
        (java_op_print_tab): Remove commented-out elements.
index 1f2f6a7..cf5189a 100644 (file)
@@ -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);
index e3905ba..bc55d70 100644 (file)
@@ -1,5 +1,9 @@
 2010-05-17  Joel Brobecker  <brobecker@adacore.com>
 
+       * gdb.ada/cond_lang: New testcase.
+
+2010-05-17  Joel Brobecker  <brobecker@adacore.com>
+
        * lib/gdb.exp (banned_variables): New variable/constant.
        (gdb_init): Add write trace on variables listed in banned_variables.
        (gdb_finish): Remove write traces on variables listed in
diff --git a/gdb/testsuite/gdb.ada/cond_lang.exp b/gdb/testsuite/gdb.ada/cond_lang.exp
new file mode 100644 (file)
index 0000000..dcd46da
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..e1cda16
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..fe27fc9
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+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 (file)
index 0000000..1d5fd31
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..b3a712a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..d412fec
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..4fbc2a2
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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;