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]

[PATCH] In MI mode -var-create --language not working.


Trying to use --language to create a variable showed that --language was
not always working.  In some cases GDB understands that the language is automatic
and cannot parse the language set while executing the command.
In order to fix this just before executing the command language mode
should be set to manual.  In this way GDB can parse the expression using
the language given in the command.
To do so mode has temporarily to be changed to manual expressing that any
evaluation done using the language parameter has priority over the automatic
one.
Tests are also included doing evaluations when the default language is c/c++
and when default language is Fortran.

2014-07-25  Walfred Tedeschi  <walfred.tedeschi@intel.com>

	* utils.c (saved_language_and_mode): new struct to accommodate
	the language mode and the current language for cleanup.
	(do_restore_current_language): Add the language and mode
	to be restored.  (make_cleanup_restore_current_language):
	pass the mode and language to the do_restore_current_language.

gdb/mi
	* mi-main.c (mi_cmd_execute): Set to manual the language mode
	to execute an mi command when --language is present.

gdb/testsuite:

	* gdb.mi/mi-language1.cc: New file.
	* gdb.mi/mi-language2.cc: New file.
	* gdb.mi/mi-language1.exp: New file.
	* gdb.mi/mi-language2.exp: New file.

---
 gdb/mi/mi-main.c                      |  1 +
 gdb/testsuite/gdb.mi/mi-language1.cc  | 36 +++++++++++++++++++++
 gdb/testsuite/gdb.mi/mi-language1.exp | 60 +++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.mi/mi-language2.exp | 54 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.mi/mi-language2.f90 | 40 +++++++++++++++++++++++
 gdb/utils.c                           | 24 +++++++++++---
 6 files changed, 210 insertions(+), 5 deletions(-)
 create mode 100644 gdb/testsuite/gdb.mi/mi-language1.cc
 create mode 100644 gdb/testsuite/gdb.mi/mi-language1.exp
 create mode 100644 gdb/testsuite/gdb.mi/mi-language2.exp
 create mode 100644 gdb/testsuite/gdb.mi/mi-language2.f90

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 59717ca..0198981 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2236,6 +2236,7 @@ mi_cmd_execute (struct mi_parse *parse)
   if (parse->language != language_unknown)
     {
       make_cleanup_restore_current_language ();
+      language_mode = language_mode_manual;
       set_language (parse->language);
     }
 
diff --git a/gdb/testsuite/gdb.mi/mi-language1.cc b/gdb/testsuite/gdb.mi/mi-language1.cc
new file mode 100644
index 0000000..0c8bd42
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-language1.cc
@@ -0,0 +1,36 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 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/>.  */
+
+struct A
+{
+  virtual ~A ();
+  int a1;
+};
+
+A::~A ()
+{
+  a1 = 800;
+}
+
+int
+main (void)
+{
+  A alpha;
+  alpha.a1 = 100;
+
+  return alpha.a1; /* only bp.  */
+}
diff --git a/gdb/testsuite/gdb.mi/mi-language1.exp b/gdb/testsuite/gdb.mi/mi-language1.exp
new file mode 100644
index 0000000..a8df370
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-language1.exp
@@ -0,0 +1,60 @@
+# Copyright 2014 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 { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+standard_testfile .cc
+
+if [get_compiler_info "c++"] {
+    return -1
+}
+
+if {[gdb_compile $srcdir/$subdir/$srcfile $binfile executable {debug c++}] != ""} {
+  untested $testfile.exp
+  return -1
+}
+
+mi_gdb_load ${binfile}
+
+if ![mi_run_to_main] {
+    untested "could not run to main"
+    return -1
+}
+
+set lineno [gdb_get_line_number "only bp."]
+
+mi_create_breakpoint "$srcfile:$lineno" "add mi-language1 bp" keep {main\(\)} \
+                     ".*mi-language1.cc" $lineno $hex "break in main"
+
+mi_execute_to "exec-continue" "breakpoint-hit" \
+              "main" "" ".*" ".*" {"" "disp=\"keep\""} \
+              "continue to mi-language1 bp"
+
+mi_gdb_test "-var-create --language fortran alpha_1 * (alpha%a1)" \
+            "\\^done,name=\"alpha_1\",numchild=\"0\",value=\"100\",type=\"int\",thread-id=\"\[0-9\]+\",has_more=\"0\"" \
+            "-var-create from c using fortran language"
+
+mi_gdb_test "-var-create alpha_2 * (alpha.a1)" \
+            "\\^done,name=\"alpha_2\",numchild=\"0\",value=\"100\",type=\"int\",thread-id=\"\[0-9\]+\",has_more=\"0\"" \
+            "-var-create from c using default language"
+gdb_exit
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.mi/mi-language2.exp b/gdb/testsuite/gdb.mi/mi-language2.exp
new file mode 100644
index 0000000..76474e6
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-language2.exp
@@ -0,0 +1,54 @@
+# Copyright 2014 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/>.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+standard_testfile mi-language2.f90
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+     {debug f90}] != "" } {
+     untested mi-language2.exp
+     return -1
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+set bp_lineno [gdb_get_line_number "only bp"]
+
+mi_create_breakpoint "-t mi-language2.f90:$bp_lineno" "add mi-language2 bp"\
+  "del" "struct_test" ".*mi-language2.f90" $bp_lineno $hex \
+  "MI-language2 insert breakpoint at line $bp_lineno (only bp)"
+
+mi_run_cmd
+
+mi_expect_stop "breakpoint-hit" "struct_test" "" ".*mi-language2.f90" \
+               "$bp_lineno" { "" "disp=\"del\"" } "mi-language2 run to breakpoint at line $bp_lineno"
+
+mi_gdb_test "-var-create --language c alpha_1 * (p.c)" \
+            "\\^done,name=\"alpha_1\",numchild=\"0\",value=\"1\",type=\"integer\\(kind=4\\)\",thread-id=\"\[0-9\]+\",has_more=\"0\"" \
+            "-var-create from fortran using fortran language"
+
+mi_gdb_test "-var-create alpha_2 * (p%c)" \
+            "\\^done,name=\"alpha_2\",numchild=\"0\",value=\"1\",type=\"integer\\(kind=4\\)\",thread-id=\"\[0-9\]+\",has_more=\"0\"" \
+            "-var-create from fortran using default language"
+gdb_exit
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.mi/mi-language2.f90 b/gdb/testsuite/gdb.mi/mi-language2.f90
new file mode 100644
index 0000000..ec49f2b
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-language2.f90
@@ -0,0 +1,40 @@
+! Copyright 2014 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/>.
+!
+! Ihis file is the Fortran source file for derived-type.exp.  It was written
+! by Wu Zhou. (woodzltc@cn.ibm.com)
+
+program struct_test
+
+  type bar
+    integer :: c
+    real :: d
+  end type
+  type foo
+    real :: a
+    type(bar) :: x
+    character*7 :: b
+  end type foo
+  type(foo) :: q
+  type(bar) :: p
+
+  p = bar(1, 2.375)
+  q%a = 3.125
+  q%b = "abcdefg"
+  q%x%c = 1
+  q%x%d = 2.375
+  print *,p,q                     ! only bp
+
+end program struct_test
diff --git a/gdb/utils.c b/gdb/utils.c
index 4da9501..96a87ca 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -444,24 +444,38 @@ make_cleanup_free_so (struct so_list *so)
 
 /* Helper for make_cleanup_restore_current_language.  */
 
+struct saved_language_and_mode
+{
+  enum language lang;
+  enum language_mode mode;
+};
+
 static void
 do_restore_current_language (void *p)
 {
-  enum language saved_lang = (uintptr_t) p;
+  struct saved_language_and_mode *lang_and_mode =
+      (struct saved_language_and_mode*) p;
+  enum language saved_lang = lang_and_mode->lang;
+  language_mode = lang_and_mode->mode;
 
+  xfree (p);
   set_language (saved_lang);
 }
 
-/* Remember the current value of CURRENT_LANGUAGE and make it restored when
-   the cleanup is run.  */
+/* Remember the current value of CURRENT_LANGUAGE and
+   LANGUAGE_MODE restoring them when the cleanup is run.  */
 
 struct cleanup *
 make_cleanup_restore_current_language (void)
 {
-  enum language saved_lang = current_language->la_language;
+  struct saved_language_and_mode *lang_and_mode
+		= XNEW (struct saved_language_and_mode);
+
+  lang_and_mode->lang = current_language->la_language;
+  lang_and_mode->mode = language_mode;
 
   return make_cleanup (do_restore_current_language,
-		       (void *) (uintptr_t) saved_lang);
+		       (void *) lang_and_mode);
 }
 
 /* Helper function for make_cleanup_clear_parser_state.  */
-- 
1.9.1


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