From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29307 invoked by alias); 28 Feb 2020 15:15:03 -0000 Mailing-List: contact gdb-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: gdb-cvs-owner@sourceware.org List-Subscribe: Sender: gdb-cvs-owner@sourceware.org Received: (qmail 29226 invoked by uid 9882); 28 Feb 2020 15:15:02 -0000 Date: Fri, 28 Feb 2020 15:15:00 -0000 Message-ID: <20200228151502.29224.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb] Don't set initial language using previous language X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 4ebe487749c5a3bac19ccaf36fc734a0d29a990e X-Git-Newrev: 658dadf0b02b618fe81e7b09ad930479941f2236 X-SW-Source: 2020-02/txt/msg00249.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=658dadf0b02b618fe81e7b09ad930479941f2236 commit 658dadf0b02b618fe81e7b09ad930479941f2236 Author: Tom de Vries Date: Fri Feb 28 16:14:53 2020 +0100 [gdb] Don't set initial language using previous language When language is set to auto, part of loading an executable is to update the language accordingly. This is implemented by set_initial_language. In case of a c++ executable without DW_AT_main_subprogram, set_initial_language finds "main" in the minimal symbols, and does a lookup of "main" in the symbol tables to determine the language of the symbol, and uses that as initial language. The symbol lookup is done using lookup_symbol which is a wrapper around lookup_symbol_in_language, using the current language. So, consider two c++ executables a.out and b.out, which we'll load one after another. If we track the resulting lookup_symbol_in_language calls: ... $ gdb -batch \ -ex "b lookup_symbol_in_language" \ -ex r -ex c -ex c \ --args gdb ... we find that indeed lookup_symbol_in_language is called once using language_c, and once using language_c_plus: ... (gdb) file a.out Reading symbols from a.out... Breakpoint 1, lookup_symbol_in_language (name=0x5555568c2050 "main", \ block=0x0, domain=VAR_DOMAIN, lang=language_c, is_a_field_of_this=0x0) \ at ../../gdb/symtab.c:1905 1905 { (gdb) file b.out Load new symbol table from "b.out"? (y or n) y Reading symbols from b.out... Breakpoint 1, lookup_symbol_in_language (name=0x5555568c2030 "main", \ block=0x0, domain=VAR_DOMAIN, lang=language_cplus, is_a_field_of_this=0x0) \ at ../../gdb/symtab.c:1905 1905 { (gdb) ... It seems like a bad idea to have the previous language play a role in determining the executable language. Fix this by using lookup_symbol_in_language in set_initial_language with the default language c as argument. Tested on x86_64-linux. gdb/ChangeLog: 2020-02-28 Tom de Vries * symfile.c (set_initial_language): Use default language for lookup. Diff: --- gdb/ChangeLog | 4 ++++ gdb/symfile.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fce2a03..5f49542 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-02-28 Tom de Vries + + * symfile.c (set_initial_language): Use default language for lookup. + 2020-02-28 Simon Marchi * dwarf2/read.c (cutu_reader::init_tu_and_read_dwo_dies): Remove diff --git a/gdb/symfile.c b/gdb/symfile.c index f1edf2d..01c3f5a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1684,11 +1684,15 @@ set_initial_language (void) if (language_mode == language_mode_manual) return; enum language lang = main_language (); + /* Make C the default language. */ + enum language default_lang = language_c; if (lang == language_unknown) { const char *name = main_name (); - struct symbol *sym = lookup_symbol (name, NULL, VAR_DOMAIN, NULL).symbol; + struct symbol *sym + = lookup_symbol_in_language (name, NULL, VAR_DOMAIN, default_lang, + NULL).symbol; if (sym != NULL) lang = sym->language (); @@ -1696,8 +1700,7 @@ set_initial_language (void) if (lang == language_unknown) { - /* Make C the default language */ - lang = language_c; + lang = default_lang; } set_language (lang);