diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4ba96baeb43..17bb500ad49 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-11-09 Tom de Vries + + * symtab.c (symbol_set_names): Call symbol_find_demangled_name + unconditionally, to set the language of the symbol. Manage freeing + returned pointer using gdb::unique_xmalloc_ptr. + 2018-11-08 Tom Tromey * record.c (require_record_target): Upper-case "". diff --git a/gdb/symtab.c b/gdb/symtab.c index 7649908d9c9..2e9e6325ad9 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -818,6 +818,11 @@ symbol_set_names (struct general_symbol_info *gsymbol, else linkage_name_copy = linkage_name; + /* Set the symbol language. */ + char *demangled_name_ptr + = symbol_find_demangled_name (gsymbol, linkage_name_copy); + gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); + entry.mangled = linkage_name_copy; slot = ((struct demangled_name_entry **) htab_find_slot (per_bfd->demangled_names_hash, @@ -830,9 +835,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, || (gsymbol->language == language_go && (*slot)->demangled[0] == '\0')) { - char *demangled_name = symbol_find_demangled_name (gsymbol, - linkage_name_copy); - int demangled_len = demangled_name ? strlen (demangled_name) : 0; + int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; /* Suppose we have demangled_name==NULL, copy_name==0, and linkage_name_copy==linkage_name. In this case, we already have the @@ -870,10 +873,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, } if (demangled_name != NULL) - { - strcpy ((*slot)->demangled, demangled_name); - xfree (demangled_name); - } + strcpy ((*slot)->demangled, demangled_name.get()); else (*slot)->demangled[0] = '\0'; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a0e614fbde0..015028c1db5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-11-09 Tom de Vries + + * gdb.base/msym-lang.c: New test. + * gdb.base/msym-lang.exp: New file. + * gdb.base/msym-lang-main.c: New test. + 2018-11-08 Tom Tromey PR gdb/23555: diff --git a/gdb/testsuite/gdb.base/msym-lang-main.c b/gdb/testsuite/gdb.base/msym-lang-main.c new file mode 100644 index 00000000000..f093f71ca40 --- /dev/null +++ b/gdb/testsuite/gdb.base/msym-lang-main.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 . */ + +static int +foo (void) +{ + return 2; +} + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/msym-lang.c b/gdb/testsuite/gdb.base/msym-lang.c new file mode 100644 index 00000000000..c9610154dd8 --- /dev/null +++ b/gdb/testsuite/gdb.base/msym-lang.c @@ -0,0 +1,22 @@ +/* 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 . */ + +static int +foo (void) +{ + return 1; +} diff --git a/gdb/testsuite/gdb.base/msym-lang.exp b/gdb/testsuite/gdb.base/msym-lang.exp new file mode 100644 index 00000000000..993225c9d65 --- /dev/null +++ b/gdb/testsuite/gdb.base/msym-lang.exp @@ -0,0 +1,25 @@ +# Copyright (C) 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 . + +standard_testfile msym-lang-main.c msym-lang.c + +if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \ + {c++}]} { + return -1 +} + +clean_restart ${testfile} + +gdb_test "info func foo" ".* foo\\(\\).* foo\\(\\).*"