* c-lang.c (c_printstr): Compute real length of NUL terminated
string at first.
+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.
{
volatile struct gdb_exception except;
struct cleanup *old_chain;
+ const struct language_defn *lang = NULL;
int subexp;
lexptr = *stringptr;
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)
{
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);
+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.
--- /dev/null
+# 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 .*"
+
+
--- /dev/null
+-- 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;
--- /dev/null
+/* 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 ();
+}
+
--- /dev/null
+-- 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;
--- /dev/null
+-- 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;
--- /dev/null
+-- 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;
--- /dev/null
+-- 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;