public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak'
@ 2018-11-17 12:04 Philippe Waroquiers
  2018-11-17 12:04 ` [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto Philippe Waroquiers
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:04 UTC (permalink / raw)
  To: gdb-patches

The commands 'info [functions|variables|types]|rbreak' work
on the global program, not only in the current frame.
So in in mixed languages program, these commands examine and print
entities defined in different languages.

Now, GDB uses the current language to print all the results of
these commands, which is somewhat surprising.

For example, when the current frame is in Ada,
info function gethostbyname gives:
  File ../nss/getXXbyYY.c:
  87:	function gethostbyname (a1: access char) return access hostent;

This patch series ensures that these commands respect the 'set language auto'
setup, to print the results in the language used to define the printed
entities.

This is the second version of the patch series, which handles all the
comments of Eli and Pedro.

For the documentation, the changes are
  * gdb.texinfo: Added references to 'set language'.
  * NEWS: Better sentence, as suggested by Eli.

For the code and test, all suggestions of Pedro were done,
a.o. change the class name to scoped_switch_to_sym_language_if_auto
which is more clear, change the test to have a better gdb.sum.

Thanks for the review, ok to push ?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto.
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
@ 2018-11-17 12:04 ` Philippe Waroquiers
  2018-11-17 12:05 ` [RFAv2 4/5] Document language choice in 'info [functions|variables|types]|rbreak' commands Philippe Waroquiers
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

The class scoped_switch_to_sym_language_if_auto allows to switch in a scope
the current language to the language of a symbol when language mode is
set to auto.

2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* language.h (scoped_switch_to_sym_language_if_auto): New class.
---
 gdb/language.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/gdb/language.h b/gdb/language.h
index 02a84ff9a2..9577065669 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -707,4 +707,39 @@ private:
   enum language m_lang;
 };
 
+/* If language_mode is language_mode_auto,
+   then switch current language to the language of SYM
+   and restore current language upon destruction.
+
+   Else do nothing.  */
+
+class scoped_switch_to_sym_language_if_auto
+{
+public:
+
+  explicit scoped_switch_to_sym_language_if_auto (const struct symbol *sym)
+  {
+    if (language_mode == language_mode_auto)
+      {
+	m_lang = current_language->la_language;
+	m_switched = true;
+	set_language (SYMBOL_LANGUAGE (sym));
+      }
+    else
+      m_switched = false;
+  }
+
+  ~scoped_switch_to_sym_language_if_auto ()
+  {
+    if (m_switched)
+      set_language (m_lang);
+  }
+
+  DISABLE_COPY_AND_ASSIGN (scoped_switch_to_sym_language_if_auto);
+
+private:
+  bool m_switched;
+  enum language m_lang;
+};
+
 #endif /* defined (LANGUAGE_H) */
-- 
2.19.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFAv2 4/5] Document language choice in 'info [functions|variables|types]|rbreak' commands
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
  2018-11-17 12:04 ` [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto Philippe Waroquiers
@ 2018-11-17 12:05 ` Philippe Waroquiers
  2018-11-17 12:05 ` [RFAv2 5/5] NEWS: Document the language choice by 'info [types|functions|variables]|rbreak' Philippe Waroquiers
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

doc/ChangeLog
2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Examining the Symbol Table): Document language choice
	for 'info types|functions|variables' commands.
	(Setting Breakpoints): Document language choice to print
	the functions in which a breakpoint is set.
---
 gdb/doc/gdb.texinfo | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 944a2c4383..3c3915b332 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -3873,6 +3873,13 @@ breakpoints are set, they are treated just like the breakpoints set with
 the @code{break} command.  You can delete them, disable them, or make
 them conditional the same way as any other breakpoint.
 
+In programs using different languages, @value{GDBN} chooses the syntax
+to print the list of all breakpoints it sets according to the
+@samp{set language} value: using @samp{set language auto}
+(see @ref{Automatically, ,Set Language Automatically}) means to use the
+language of the breakpoint's function, other values mean to use
+the manually specified language (see @ref{Manually, ,Set Language Manually}).
+
 The syntax of the regular expression is the standard one used with tools
 like @file{grep}.  Note that this is different from the syntax used by
 shells, so for instance @code{foo*} matches all functions that include
@@ -17903,6 +17910,13 @@ types in your program whose names include the string @code{value}, but
 @samp{i type ^value$} gives information only on types whose complete
 name is @code{value}.
 
+In programs using different languages, @value{GDBN} chooses the syntax
+to print the type description according to the
+@samp{set language} value: using @samp{set language auto}
+(see @ref{Automatically, ,Set Language Automatically}) means to use the
+language of the type, other values mean to use
+the manually specified language (see @ref{Manually, ,Set Language Manually}).
+
 This command differs from @code{ptype} in two ways: first, like
 @code{whatis}, it does not print a detailed description; second, it
 lists all source files and line numbers where a type is defined.
@@ -17987,6 +18001,13 @@ Similarly to @samp{info types}, this command groups its output by source
 files and annotates each function definition with its source line
 number.
 
+In programs using different languages, @value{GDBN} chooses the syntax
+to print the function name and type according to the
+@samp{set language} value: using @samp{set language auto}
+(see @ref{Automatically, ,Set Language Automatically}) means to use the
+language of the function, other values mean to use
+the manually specified language (see @ref{Manually, ,Set Language Manually}).
+
 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
 printing header information and messages explaining why no functions
 have been printed.
@@ -18027,6 +18048,13 @@ outside of functions (i.e.@: excluding local variables).
 The printed variables are grouped by source files and annotated with
 their respective source line numbers.
 
+In programs using different languages, @value{GDBN} chooses the syntax
+to print the variable name and type according to the
+@samp{set language} value: using @samp{set language auto}
+(see @ref{Automatically, ,Set Language Automatically}) means to use the
+language of the variable, other values mean to use
+the manually specified language (see @ref{Manually, ,Set Language Manually}).
+
 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
 printing header information and messages explaining why no variables
 have been printed.
-- 
2.19.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
                   ` (3 preceding siblings ...)
  2018-11-17 12:05 ` [RFAv2 2/5] Use scoped_switch_to_sym_language_if_auto in symtab.c to switch language Philippe Waroquiers
@ 2018-11-17 12:05 ` Philippe Waroquiers
  2018-11-30 20:46   ` New FAILs added by gdb.ada/info_auto_lang.exp (was: Re: [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.) Sergio Durigan Junior
  2018-11-17 19:19 ` [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Pedro Alves
  5 siblings, 1 reply; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.ada/info_auto_lang.exp: New testcase.
	* gdb.ada/info_auto_lang/global_pack.ads: New file.
	* gdb.ada/info_auto_lang/proc_in_ada.adb: New file.
	* gdb.ada/info_auto_lang/some_c.c: New file.
---
 gdb/testsuite/gdb.ada/info_auto_lang.exp      | 154 ++++++++++++++++++
 .../gdb.ada/info_auto_lang/global_pack.ads    |  25 +++
 .../gdb.ada/info_auto_lang/proc_in_ada.adb    |  24 +++
 gdb/testsuite/gdb.ada/info_auto_lang/some_c.c |  28 ++++
 4 files changed, 231 insertions(+)
 create mode 100644 gdb/testsuite/gdb.ada/info_auto_lang.exp
 create mode 100644 gdb/testsuite/gdb.ada/info_auto_lang/global_pack.ads
 create mode 100644 gdb/testsuite/gdb.ada/info_auto_lang/proc_in_ada.adb
 create mode 100644 gdb/testsuite/gdb.ada/info_auto_lang/some_c.c

diff --git a/gdb/testsuite/gdb.ada/info_auto_lang.exp b/gdb/testsuite/gdb.ada/info_auto_lang.exp
new file mode 100644
index 0000000000..4ba79fff42
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/info_auto_lang.exp
@@ -0,0 +1,154 @@
+# Copyright 2018 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 "ada.exp"
+
+# This test verifies that the commands
+#   info [functions|variables|types]
+# respect the 'set language auto|ada|c' setting, whatever the language
+# of the current frame.
+# Similarly, checks that rbreak reports its results respecting
+# the language mode.
+
+standard_ada_testfile proc_in_ada
+set cfile "some_c"
+set csrcfile ${srcdir}/${subdir}/${testdir}/${cfile}.c
+set cobject [standard_output_file ${cfile}.o]
+
+if { [gdb_compile "${csrcfile}" "${cobject}" object [list debug]] != "" } {
+    untested "failed to compile"
+    return -1
+}
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
+    untested "failed to compile"
+    return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/some_c.c]
+if ![runto "some_c.c:$bp_location"] then {
+    fail "can't run to some_c.c STOP location"
+    return
+}
+
+set func_in_c(c_syntax)      "${decimal}:	void proc_in_c\\\(void\\\);"
+set func_in_c(ada_syntax)    "${decimal}:	procedure proc_in_c;"
+set func_in_ada(c_syntax)    "${decimal}:	void proc_in_ada\\\(void\\\);"
+set func_in_ada(ada_syntax)  "${decimal}:	procedure proc_in_ada;"
+
+set type_in_c(c_syntax) [multi_line \
+			    "${decimal}:	typedef struct {" \
+			    "    int some_component_in_c;" \
+			    "} some_type_in_c;" ]
+set type_in_c(ada_syntax) [multi_line \
+			      "${decimal}:	record" \
+			      "    some_component_in_c: int;" \
+			      "end record" ]
+set type_in_ada(c_syntax) "${decimal}:	struct global_pack__some_type_in_ada;"
+set type_in_ada(ada_syntax)  "${decimal}:	global_pack.some_type_in_ada;"
+
+set var_in_c(c_syntax)     "${decimal}:	some_type_in_c some_struct_in_c;"
+set var_in_c(ada_syntax)   "${decimal}:	some_struct_in_c: some_type_in_c;"
+set var_in_ada(c_syntax)   "${decimal}:	struct global_pack__some_type_in_ada global_pack.some_struct_in_ada;"
+set var_in_ada(ada_syntax) "${decimal}:	global_pack.some_struct_in_ada: global_pack.some_type_in_ada;"
+
+set rbreak_func_in_c(c_syntax)      "void proc_in_c\\\(void\\\);"
+set rbreak_func_in_c(ada_syntax)    "procedure proc_in_c;"
+set rbreak_func_in_ada(c_syntax)    "void proc_in_ada\\\(void\\\);"
+set rbreak_func_in_ada(ada_syntax)  "procedure proc_in_ada;"
+
+
+foreach_with_prefix language_choice { "auto" "ada" "c" } {
+
+    # Check that switching to the desired language_choice when the selected
+    # frame has the same language (or the desired language is auto) gives no
+    # warning.  Also set the expected matches for the various commands
+    # tested afterwards.
+    if {$language_choice == "auto"} {
+	gdb_test "frame 0" "#0 .*" "select frame with lang c"
+	set c_match c_syntax
+	set ada_match ada_syntax
+    } elseif {$language_choice == "ada"} {
+	gdb_test "frame 1" "#1 .*" "select frame with lang ada"
+	set c_match ada_syntax
+	set ada_match ada_syntax
+    } elseif {$language_choice == "c"} {
+	gdb_test "frame 0" "#0 .*" "select frame with lang c"
+	set c_match c_syntax
+	set ada_match c_syntax
+    } else {
+	error "unexpected language choice"
+    }
+    gdb_test_no_output "set language $language_choice" "set language language_choice"
+
+    foreach frame {
+	"0"
+	"1" } {
+	if { $frame == 0 } {
+	    set frame_lang "c"
+	} else {
+	    set frame_lang "ada"
+	}
+
+	with_test_prefix "frame=$frame, frame_lang=$frame_lang" {
+
+	    gdb_test "frame $frame" "#$frame .*" "select frame"
+
+	    gdb_test "info functions proc_in_" \
+		[multi_line \
+		     "All functions matching regular expression \"proc_in_\":" \
+		     "" \
+		     "File .*some_c.c:" \
+		     $func_in_c($c_match) \
+		     "" \
+		     "File .*proc_in_ada.adb:" \
+		     $func_in_ada($ada_match)
+		]
+
+	    gdb_test "info types some_type" \
+		[multi_line \
+		     "All types matching regular expression \"some_type\":" \
+		     "" \
+		     "File .*some_c.c:" \
+		     $type_in_c($c_match) \
+		     "" \
+		     "File .*global_pack.ads:" \
+		     $type_in_ada($ada_match)
+		]
+
+	    gdb_test "info variables some_struct" \
+		[multi_line \
+		     "All variables matching regular expression \"some_struct\":" \
+		     "" \
+		     "File .*some_c.c:" \
+		     $var_in_c($c_match) \
+		     "" \
+		     "File .*global_pack.ads:" \
+		     $var_in_ada($ada_match)
+		]
+
+	    gdb_test "rbreak proc_in_" \
+		[multi_line \
+		     "Breakpoint.*file .*some_c.c,.*" \
+		     $rbreak_func_in_c($c_match) \
+		     "Breakpoint.*file .*proc_in_ada.adb,.*" \
+		     $rbreak_func_in_ada($ada_match)
+		]
+	    delete_breakpoints
+	}
+    }
+}
+
diff --git a/gdb/testsuite/gdb.ada/info_auto_lang/global_pack.ads b/gdb/testsuite/gdb.ada/info_auto_lang/global_pack.ads
new file mode 100644
index 0000000000..31e7c3cf91
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/info_auto_lang/global_pack.ads
@@ -0,0 +1,25 @@
+--  Copyright 2018 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 Global_Pack is
+  Some_Number_In_Ada : Integer := 0;
+
+  type Some_Type_In_Ada is
+    record
+      Some_Component_In_Ada : Integer;
+    end record;
+
+  Some_Struct_In_Ada : Some_Type_In_Ada;
+end Global_Pack;
diff --git a/gdb/testsuite/gdb.ada/info_auto_lang/proc_in_ada.adb b/gdb/testsuite/gdb.ada/info_auto_lang/proc_in_ada.adb
new file mode 100644
index 0000000000..a82f4a05cd
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/info_auto_lang/proc_in_ada.adb
@@ -0,0 +1,24 @@
+--  Copyright 2018 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 Global_Pack; use Global_Pack;
+procedure Proc_In_Ada is
+  procedure Something_In_C
+    with Import, Convention => C, External_Name => "proc_in_c";
+   pragma Linker_Options ("some_c.o");
+begin
+  Something_In_C;
+  Some_Number_In_Ada := Some_Number_In_Ada + 1;
+end Proc_In_Ada;
diff --git a/gdb/testsuite/gdb.ada/info_auto_lang/some_c.c b/gdb/testsuite/gdb.ada/info_auto_lang/some_c.c
new file mode 100644
index 0000000000..bda00cbf34
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/info_auto_lang/some_c.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2018 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/>.  */
+
+int some_number_in_c;
+typedef struct {
+   int some_component_in_c;
+} some_type_in_c;
+
+some_type_in_c some_struct_in_c;
+void proc_in_c (void)
+{
+   some_number_in_c++;
+   some_struct_in_c.some_component_in_c++; /* STOP */
+}
-- 
2.19.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFAv2 5/5] NEWS: Document the language choice by 'info [types|functions|variables]|rbreak'.
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
  2018-11-17 12:04 ` [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto Philippe Waroquiers
  2018-11-17 12:05 ` [RFAv2 4/5] Document language choice in 'info [functions|variables|types]|rbreak' commands Philippe Waroquiers
@ 2018-11-17 12:05 ` Philippe Waroquiers
  2018-11-17 12:05 ` [RFAv2 2/5] Use scoped_switch_to_sym_language_if_auto in symtab.c to switch language Philippe Waroquiers
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

gdb/ChangeLog
2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Document the language choice done by
	'info [types|functions|variables]|rbreak'.
---
 gdb/NEWS | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index ff9b192a38..ef037dee4a 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -96,6 +96,15 @@ info variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]
   on the entity names or entity types.  The flag -q disables
   printing headers or informations messages.
 
+info functions
+info types
+info variables
+rbreak
+  These commands now determine the syntax for the shown entities
+  according to the language chosen by `set language'.  In particular,
+  `set language auto' means to automatically choose the language of
+  the shown entities.
+
 thread apply [all | COUNT | -COUNT] [FLAG]... COMMAND
   The 'thread apply' command accepts new FLAG arguments.
   FLAG arguments allow to control what output to produce and how to handle
-- 
2.19.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [RFAv2 2/5] Use scoped_switch_to_sym_language_if_auto in symtab.c to switch language.
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
                   ` (2 preceding siblings ...)
  2018-11-17 12:05 ` [RFAv2 5/5] NEWS: Document the language choice by 'info [types|functions|variables]|rbreak' Philippe Waroquiers
@ 2018-11-17 12:05 ` Philippe Waroquiers
  2018-11-17 12:05 ` [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode Philippe Waroquiers
  2018-11-17 19:19 ` [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Pedro Alves
  5 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-17 12:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

Use scoped_switch_to_sym_language_if_auto in treg_matches_sym_type_name to
replace the local logic that was doing the same as the new class
scoped_switch_to_sym_language_if_auto.

Use scoped_switch_to_sym_language_if_auto inside print_symbol_info, so
that symbol information is printed in the symbol language when
language mode is auto.
This modifies the behaviour of the test dw2-case-insensitive.exp,
as the function FUNC_lang is now printed with the Fortran syntax
(as declared in the .S file).

gdb/ChangeLog
2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* symtab.c (treg_matches_sym_type_name): Use
	scoped_switch_to_sym_language_if_auto instead of local logic.
	(print_symbol_info): Use scoped_switch_to_sym_language_if_auto
	to switch to SYM language when language mode is auto.

gdb/testsuite/ChangeLog
2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.dwarf2/dw2-case-insensitive.exp: Update due to auto switch to
	FUNC_lang language syntax.
---
 gdb/symtab.c                                      | 12 +++++-------
 gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp |  4 +++-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2e9e6325ad..9fbf54a78f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4288,15 +4288,12 @@ treg_matches_sym_type_name (const compiled_regex &treg,
   if (sym_type == NULL)
     return false;
 
-  if (language_mode == language_mode_auto)
-    {
-      scoped_restore_current_language l;
+  {
+    scoped_switch_to_sym_language_if_auto l (sym);
 
-      set_language (SYMBOL_LANGUAGE (sym));
-      printed_sym_type_name = type_to_string (sym_type);
-    }
-  else
     printed_sym_type_name = type_to_string (sym_type);
+  }
+
 
   if (symbol_lookup_debug > 1)
     {
@@ -4601,6 +4598,7 @@ print_symbol_info (enum search_domain kind,
 		   struct symbol *sym,
 		   int block, const char *last)
 {
+  scoped_switch_to_sym_language_if_auto l (sym);
   struct symtab *s = symbol_symtab (sym);
 
   if (last != NULL)
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp b/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
index b15dcafa00..328facd64e 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
@@ -42,8 +42,10 @@ gdb_test "info functions fUnC_lang" \
 gdb_test "set case-sensitive off" {warning: the current case sensitivity setting does not match the language\.}
 
 # The dot-leading symbol is for ppc64 function descriptors.
+# Note that info functions gives the FUNC_lang result using the fortran syntax
+# as specified in dw-case-insensitive-debug.S DW_AT_language.
 gdb_test "info functions fUnC_lang" \
-	 "All functions matching regular expression \"fUnC_lang\":\[\r\n\]+File file1.txt:\r\n\tfoo FUNC_lang\\(void\\);(\r\n\r\nNon-debugging symbols:\r\n0x\[0-9a-f\]+ +\\.FUNC_lang)?" \
+	 "All functions matching regular expression \"fUnC_lang\":\[\r\n\]+File file1.txt:\r\n\tfoo FUNC_lang\\(\\);(\r\n\r\nNon-debugging symbols:\r\n0x\[0-9a-f\]+ +\\.FUNC_lang)?" \
 	 "regexp case-sensitive off"
 
 gdb_test "p fuNC_lang" { = {foo \(void\)} 0x[0-9a-f]+ <FUNC_lang>}
-- 
2.19.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak'
  2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
                   ` (4 preceding siblings ...)
  2018-11-17 12:05 ` [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode Philippe Waroquiers
@ 2018-11-17 19:19 ` Pedro Alves
  2018-11-20 21:59   ` Philippe Waroquiers
  5 siblings, 1 reply; 10+ messages in thread
From: Pedro Alves @ 2018-11-17 19:19 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches

On 11/17/2018 12:04 PM, Philippe Waroquiers wrote:
> The commands 'info [functions|variables|types]|rbreak' work
> on the global program, not only in the current frame.
> So in in mixed languages program, these commands examine and print
> entities defined in different languages.
> 
> Now, GDB uses the current language to print all the results of
> these commands, which is somewhat surprising.
> 
> For example, when the current frame is in Ada,
> info function gethostbyname gives:
>   File ../nss/getXXbyYY.c:
>   87:	function gethostbyname (a1: access char) return access hostent;
> 
> This patch series ensures that these commands respect the 'set language auto'
> setup, to print the results in the language used to define the printed
> entities.
> 
> This is the second version of the patch series, which handles all the
> comments of Eli and Pedro.
> 
> For the documentation, the changes are
>   * gdb.texinfo: Added references to 'set language'.
>   * NEWS: Better sentence, as suggested by Eli.
> 
> For the code and test, all suggestions of Pedro were done,
> a.o. change the class name to scoped_switch_to_sym_language_if_auto
> which is more clear, change the test to have a better gdb.sum.
> 
> Thanks for the review, ok to push ?

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak'
  2018-11-17 19:19 ` [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Pedro Alves
@ 2018-11-20 21:59   ` Philippe Waroquiers
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-20 21:59 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On Sat, 2018-11-17 at 19:19 +0000, Pedro Alves wrote:
> > For the code and test, all suggestions of Pedro were done,
> > a.o. change the class name to scoped_switch_to_sym_language_if_auto
> > which is more clear, change the test to have a better gdb.sum.
> > 
> > Thanks for the review, ok to push ?
> 
> OK.
> 
> Thanks,
> Pedro Alves
Pushed now ...
Philippe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* New FAILs added by gdb.ada/info_auto_lang.exp (was: Re: [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.)
  2018-11-17 12:05 ` [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode Philippe Waroquiers
@ 2018-11-30 20:46   ` Sergio Durigan Junior
  2018-11-30 23:26     ` Philippe Waroquiers
  0 siblings, 1 reply; 10+ messages in thread
From: Sergio Durigan Junior @ 2018-11-30 20:46 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: gdb-patches

On Saturday, November 17 2018, Philippe Waroquiers wrote:

> 2018-11-17  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
>
> 	* gdb.ada/info_auto_lang.exp: New testcase.
> 	* gdb.ada/info_auto_lang/global_pack.ads: New file.
> 	* gdb.ada/info_auto_lang/proc_in_ada.adb: New file.
> 	* gdb.ada/info_auto_lang/some_c.c: New file.

Hey Philippe,

I've just noticed that this commit introduced a bunch of new FAILs in
our testsuite.  This is what I'm seeing here:

  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=0, frame_lang=c: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=0, frame_lang=c: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=0, frame_lang=c: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=0, frame_lang=c: rbreak proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=1, frame_lang=ada: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=1, frame_lang=ada: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=1, frame_lang=ada: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=auto: frame=1, frame_lang=ada: rbreak proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=0, frame_lang=c: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=0, frame_lang=c: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=0, frame_lang=c: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=0, frame_lang=c: rbreak proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=1, frame_lang=ada: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=1, frame_lang=ada: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=1, frame_lang=ada: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=ada: frame=1, frame_lang=ada: rbreak proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=0, frame_lang=c: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=0, frame_lang=c: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=0, frame_lang=c: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=0, frame_lang=c: rbreak proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=1, frame_lang=ada: info functions proc_in_
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=1, frame_lang=ada: info types some_type
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=1, frame_lang=ada: info variables some_struct
  FAIL: gdb.ada/info_auto_lang.exp: language_choice=c: frame=1, frame_lang=ada: rbreak proc_in_

If you're interested, you can also check the results generated by our
BuildBot here:

  https://sourceware.org/ml/gdb-testers/2018-q4/msg03864.html

I haven't investigated further to see where/what the error is.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: New FAILs added by gdb.ada/info_auto_lang.exp (was: Re: [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.)
  2018-11-30 20:46   ` New FAILs added by gdb.ada/info_auto_lang.exp (was: Re: [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.) Sergio Durigan Junior
@ 2018-11-30 23:26     ` Philippe Waroquiers
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Waroquiers @ 2018-11-30 23:26 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

On Fri, 2018-11-30 at 15:46 -0500, Sergio Durigan Junior wrote:
> If you're interested, you can also check the results generated by our
> BuildBot here:
> 
>   https://sourceware.org/ml/gdb-testers/2018-q4/msg03864.html
> 
> I haven't investigated further to see where/what the error is.
I will investigate this week-end, thanks for the pointer.

Philippe

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-11-30 23:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-17 12:04 [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Philippe Waroquiers
2018-11-17 12:04 ` [RFAv2 1/5] Add class scoped_switch_to_sym_language_if_auto Philippe Waroquiers
2018-11-17 12:05 ` [RFAv2 4/5] Document language choice in 'info [functions|variables|types]|rbreak' commands Philippe Waroquiers
2018-11-17 12:05 ` [RFAv2 5/5] NEWS: Document the language choice by 'info [types|functions|variables]|rbreak' Philippe Waroquiers
2018-11-17 12:05 ` [RFAv2 2/5] Use scoped_switch_to_sym_language_if_auto in symtab.c to switch language Philippe Waroquiers
2018-11-17 12:05 ` [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode Philippe Waroquiers
2018-11-30 20:46   ` New FAILs added by gdb.ada/info_auto_lang.exp (was: Re: [RFAv2 3/5] Add a test to verify info [functions|variables|types]|rbreak respect language_mode.) Sergio Durigan Junior
2018-11-30 23:26     ` Philippe Waroquiers
2018-11-17 19:19 ` [RFAv2 0/5] Use language mode in 'info [functions|variables|types]|rbreak' Pedro Alves
2018-11-20 21:59   ` Philippe Waroquiers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).