From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18553 invoked by alias); 2 Jan 2008 13:38:43 -0000 Received: (qmail 18489 invoked by uid 22791); 2 Jan 2008 13:38:40 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 02 Jan 2008 13:31:48 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7356B2A966B for ; Wed, 2 Jan 2008 08:31:41 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ZIanxQXD1VAd for ; Wed, 2 Jan 2008 08:31:41 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 877EE2A9669 for ; Wed, 2 Jan 2008 08:31:39 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id A79CBE7ACB; Wed, 2 Jan 2008 05:31:32 -0800 (PST) Date: Wed, 02 Jan 2008 13:38:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA] Fix "set lang auto" oddity when inferior not started yet Message-ID: <20080102133132.GD15903@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="O3RTKUHj+75w1tg5" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00019.txt.bz2 --O3RTKUHj+75w1tg5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1145 Consider the following scenario: (gdb) file my_c_program (gdb) show lang The current source language is "auto; currently c". (gdb) set lang ada Now, try to set the language_mode back to "auto", and see what the language is: (gdb) set lang auto (gdb) show lang The current source language is "auto". We forgot to set the language! This was reported to us a while ago by the GPS team (GPS is an IDE that contains a frontend to GDB), because they rely in some occasions on GDB to tell them what the language is. The attached patch fixes the problem. 2008-01-02 Joel Brobecker * symfile.c (set_initial_language): Make non-static. * symfile.h (set_initial_language): Add declaration. * language.c: #include "symfile.h". (set_language): Call set_initial_language if the frame language could not be determined. I also wrote a tiny testcase: 2008-01-02 Joel Brobecker * gdb.base/set_lang_auto.exp: New testcase. All tested on x86-linux, no regression. OK to commit? Thanks, -- Joel --O3RTKUHj+75w1tg5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="set_lang_auto.diff" Content-length: 2753 Index: symfile.c =================================================================== --- symfile.c (revision 45) +++ symfile.c (revision 46) @@ -87,8 +87,6 @@ static int simple_read_overlay_region_ta static void simple_free_overlay_region_table (void); #endif -static void set_initial_language (void); - static void load_command (char *, int); static void symbol_file_add_main_1 (char *args, int from_tty, int flags); @@ -1576,7 +1574,7 @@ symbol_file_command (char *args, int fro stabs we find, but we can't do that until later when we read in full symbols. */ -static void +void set_initial_language (void) { struct partial_symtab *pst; Index: symfile.h =================================================================== --- symfile.h (revision 45) +++ symfile.h (revision 46) @@ -292,6 +292,8 @@ extern int auto_solib_limit; /* From symfile.c */ +extern void set_initial_language (void); + extern struct partial_symtab *allocate_psymtab (char *, struct objfile *); extern void discard_psymtab (struct partial_symtab *); Index: language.c =================================================================== --- language.c (revision 45) +++ language.c (revision 46) @@ -43,6 +43,7 @@ #include "parser-defs.h" #include "jv-lang.h" #include "demangle.h" +#include "symfile.h" extern void _initialize_language (void); @@ -185,11 +186,14 @@ local or auto Automatic setting based /* Found it! Go into manual mode, and use this language. */ if (languages[i]->la_language == language_auto) { - /* Enter auto mode. Set to the current frame's language, if known. */ + /* Enter auto mode. Set to the current frame's language, if + known, or fallback to the initial language. */ language_mode = language_mode_auto; flang = get_frame_language (); if (flang != language_unknown) set_language (flang); + else + set_initial_language (); expected_language = current_language; return; } Index: Makefile.in =================================================================== --- Makefile.in (revision 45) +++ Makefile.in (revision 46) @@ -2323,7 +2323,7 @@ jv-valprint.o: jv-valprint.c $(defs_h) $ $(language_h) $(jv_lang_h) $(c_lang_h) $(annotate_h) $(gdb_string_h) language.o: language.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \ $(value_h) $(gdbcmd_h) $(expression_h) $(language_h) $(target_h) \ - $(parser_defs_h) $(jv_lang_h) $(demangle_h) + $(parser_defs_h) $(jv_lang_h) $(demangle_h) $(symfile_h) libunwind-frame.o: libunwind-frame.c $(defs_h) $(inferior_h) $(frame_h) \ $(frame_base_h) $(frame_unwind_h) $(gdbcore_h) $(gdbtypes_h) \ $(symtab_h) $(objfiles_h) $(regcache_h) $(gdb_assert_h) \ --O3RTKUHj+75w1tg5 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="set_lang_auto-testcase.diff" Content-length: 2458 Index: gdb.base/set_lang_auto.exp =================================================================== --- gdb.base/set_lang_auto.exp (revision 0) +++ gdb.base/set_lang_auto.exp (revision 47) @@ -0,0 +1,70 @@ +# Copyright 2008 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 +} + +set prms_id 0 +set bug_id 0 + +set testfile start +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# Do not run the inferior as the purpose of this testcase is to test +# the behavior of the "set language" command when there is no inferior. + +# Check the language after the binary has been loaded. It should be +# "auto; currently c". +gdb_test "show lang" \ + "The current source language is \"auto; currently c\"\\." \ + "show lang after loading binary" + +# Now, switch the language to a specific language, instead of leaving it +# on auto. +gdb_test "set lang ada" \ + "" \ + "forcing the language to ada" + +# Verify that the language is now "ada". +gdb_test "show lang" \ + "The current source language is \"ada\"\\." \ + "show lang after switching language to ada" + +# Then, switch back to auto... +gdb_test "set lang auto" \ + "" \ + "switching the language back to auto" + +# ... And verify that the language mode is back to auto *and* that +# the selected language is C. + +gdb_test "show lang" \ + "The current source language is \"auto; currently c\"\\." \ + "show lang after having switched back to auto" + + --O3RTKUHj+75w1tg5--