From: Weimin Pan <weimin.pan@oracle.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/5] CTF: fix incorrect function return type
Date: Mon, 1 Feb 2021 20:48:44 -0500 [thread overview]
Message-ID: <1612230528-25905-2-git-send-email-weimin.pan@oracle.com> (raw)
In-Reply-To: <1612230528-25905-1-git-send-email-weimin.pan@oracle.com>
The problems can be illustrated, with any program, below:
(gdb) print main
$1 = {main} 0x0
The return type was incorrectly set in read_func_kind_type, with
the name of the function, which leads c_type_print_base_1 to print
it. In addition, the address of a new function needs to be set with
that info in its minimal symtab entry, when the new function is added.
After the fix:
(gdb) print main
$1 = {int ()} 0x4004b7 <main>
A new test, gdb.base/ctf-funcreturn.exp, is added to the testsuite.
---
gdb/ctfread.c | 5 +-
gdb/testsuite/gdb.base/ctf-funcreturn.exp | 190 ++++++++++++++++++++++++++++++
2 files changed, 191 insertions(+), 4 deletions(-)
create mode 100644 gdb/testsuite/gdb.base/ctf-funcreturn.exp
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 866977a..5a68d9c 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -462,6 +462,7 @@ struct ctf_tid_and_type
break;
case CTF_K_FUNCTION:
SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
+ set_symbol_address (objfile, sym, sym->linkage_name ());
break;
case CTF_K_CONST:
if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_VOID)
@@ -656,10 +657,6 @@ struct ctf_tid_and_type
type = alloc_type (of);
- gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
- if (name != NULL && strlen (name.get ()) != 0)
- type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
-
type->set_code (TYPE_CODE_FUNC);
ctf_func_type_info (fp, tid, &cfi);
rettype = get_tid_type (of, cfi.ctc_return);
diff --git a/gdb/testsuite/gdb.base/ctf-funcreturn.exp b/gdb/testsuite/gdb.base/ctf-funcreturn.exp
new file mode 100644
index 0000000..874160e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/ctf-funcreturn.exp
@@ -0,0 +1,190 @@
+# Copyright 2021 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_ctf_tests] {
+ unsupported "no CTF debug format support, or CTF disabled in GDB"
+ return 0
+}
+
+if [target_info exists no_long_long] {
+ set exec_opts [list debug additional_flags=-DNO_LONG_LONG]
+} else {
+ set exec_opts [list debug]
+}
+
+standard_testfile whatis.c
+
+# Using `-gt` generates full-fledged CTF debug information.
+set opts "additional_flags=-gt -Wl,--export-dynamic"
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile] [list $opts nowarnings]] } {
+ return 0
+}
+
+# Create and source the file that provides information about the compiler
+# used to compile the test case.
+if [get_compiler_info] {
+ return -1
+}
+
+# test print command with functions return type
+set void "(void|)"
+gdb_test "print v_char_func" \
+ "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" \
+ "print char function"
+
+gdb_test "print v_signed_char_func" \
+ "$decimal = \{signed char \\(\\)\} 0x\[0-9a-z\]+ <v_signed_char_func>.*" \
+ "print signed char function"
+
+gdb_test "print v_unsigned_char_func" \
+ "$decimal = \{unsigned char \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_char_func>.*" \
+ "print unsigned char function"
+
+gdb_test "print v_short_func" \
+ "$decimal = \{short \\(\\)\} 0x\[0-9a-z\]+ <v_short_func>.*" \
+ "print short function"
+
+gdb_test "print v_signed_short_func" \
+ "$decimal = \{signed short|short \\(\\)\} 0x\[0-9a-z\]+ <v_signed_short_func>.*" \
+ "print signed short function"
+
+gdb_test "print v_unsigned_short_func" \
+ "$decimal = \{unsigned short \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_short_func>.*" \
+ "print unsigned short function"
+
+gdb_test "print v_int_func" \
+ "$decimal = \{int \\(\\)\} 0x\[0-9a-z\]+ <v_int_func>.*" \
+ "print int function"
+
+gdb_test "print v_signed_int_func" \
+ "$decimal = \{signed int|int \\(\\)\} 0x\[0-9a-z\]+ <v_signed_int_func>.*" \
+ "print signed int function"
+
+gdb_test "print v_unsigned_int_func" \
+ "$decimal = \{unsigned int \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_int_func>.*" \
+ "print unsigned int function"
+
+gdb_test "print v_long_func" \
+ "$decimal = \{long \\(\\)\} 0x\[0-9a-z\]+ <v_long_func>.*" \
+ "print long function"
+
+gdb_test "print v_signed_long_func" \
+ "$decimal = \{signed long|long \\(\\)\} 0x\[0-9a-z\]+ <v_signed_long_func>.*" \
+ "print signed long function"
+
+gdb_test "print v_unsigned_long_func" \
+ "$decimal = \{unsigned long|long \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_long_func>.*" \
+ "print unsigned long function"
+
+if ![target_info exists no_long_long] {
+ gdb_test "print v_long_long_func" \
+ "$decimal = \{long long \\(\\)\} 0x\[0-9a-z\]+ <v_long_long_func>.*" \
+ "print long long function"
+
+ gdb_test "print v_signed_long_long_func" \
+ "$decimal = \{long long \\(\\)\} 0x\[0-9a-z\]+ <v_signed_long_long_func>.*" \
+ "print signed long long function"
+
+ gdb_test "print v_unsigned_long_long_func" \
+ "$decimal = \{unsigned long long \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_long_long_func>.*" \
+ "print unsigned long long function"
+}
+
+# Sun /bin/cc calls this a function returning double.
+if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
+ gdb_test "print v_float_func" \
+ "$decimal = \{float \\(\\)\} 0x\[0-9a-z\]+.*" \
+ "print float function"
+
+ gdb_test "print v_double_func" \
+ "$decimal = \{double \\(\\)\} 0x\[0-9a-z\]+.*" \
+ "print double function" \
+}
+
+# test whatis command with functions return type
+gdb_test "whatis v_char_func" \
+ "type = (signed |unsigned |)char \\($void\\)" \
+ "whatis char function"
+
+gdb_test "whatis v_signed_char_func" \
+ "type = (signed |unsigned |)char \\($void\\)" \
+ "whatis signed char function"
+
+gdb_test "whatis v_unsigned_char_func" \
+ "type = unsigned char \\($void\\)" \
+ "whatis unsigned char function"
+
+gdb_test "whatis v_short_func" \
+ "type = short (int |)\\($void\\)" \
+ "whatis short function"
+
+gdb_test "whatis v_signed_short_func" \
+ "type = (signed |)short (int |)\\($void\\)" \
+ "whatis signed short function"
+
+gdb_test "whatis v_unsigned_short_func" \
+ "type = (unsigned short|short unsigned int) \\($void\\)" \
+ "whatis unsigned short function"
+
+gdb_test "whatis v_int_func" \
+ "type = int \\($void\\)" \
+ "whatis int function"
+
+gdb_test "whatis v_signed_int_func" \
+ "type = (signed |)int \\($void\\)" \
+ "whatis signed int function"
+
+gdb_test "whatis v_unsigned_int_func" \
+ "type = unsigned int \\($void\\)" \
+ "whatis unsigned int function"
+
+gdb_test "whatis v_long_func" \
+ "type = (long|int|long int) \\($void\\)" \
+ "whatis long function"
+
+gdb_test "whatis v_signed_long_func" \
+ "type = (signed |)(int|long|long int) \\($void\\)" \
+ "whatis signed long function"
+
+gdb_test "whatis v_unsigned_long_func" \
+ "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
+ "whatis unsigned long function"
+
+if ![target_info exists no_long_long] {
+ gdb_test "whatis v_long_long_func" \
+ "type = long long(| int) \\($void\\)" \
+ "whatis long long function"
+
+ gdb_test "whatis v_signed_long_long_func" \
+ "type = (signed |)long long(| int) \\($void\\)" \
+ "whatis signed long long function"
+
+ gdb_test "whatis v_unsigned_long_long_func" \
+ "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
+ "whatis unsigned long long function"
+}
+
+# Sun /bin/cc calls this a function returning double.
+if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
+ gdb_test "whatis v_float_func" \
+ "type = float \\($void\\)" \
+ "whatis float function"
+
+ gdb_test "whatis v_double_func" \
+ "type = double \\($void\\)" \
+ "whatis double function" \
+}
--
1.8.3.1
next prev parent reply other threads:[~2021-02-02 1:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 1:48 [PATCH 0/5] CTF: bug fixes and new features Weimin Pan
2021-02-02 1:48 ` Weimin Pan [this message]
2021-02-02 1:48 ` [PATCH 2/5] CTF: set up debug info for function arguments Weimin Pan
2021-02-02 1:48 ` [PATCH 3/5] CTF: handle forward reference type Weimin Pan
2021-02-02 1:48 ` [PATCH 4/5] CTF: add all members of an enum type to psymtab Weimin Pan
2021-02-02 1:48 ` [PATCH 5/5] CTF: multi-CU and archive support Weimin Pan
2021-02-05 15:42 ` [PATCH 3/5] CTF: handle forward reference type Tom Tromey
2021-02-05 19:33 ` Wei-min Pan
2021-02-05 15:40 ` [PATCH 2/5] CTF: set up debug info for function arguments Tom Tromey
2021-02-05 19:21 ` Wei-min Pan
2021-02-05 15:33 ` [PATCH 1/5] CTF: fix incorrect function return type Tom Tromey
2021-02-05 19:12 ` Wei-min Pan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1612230528-25905-2-git-send-email-weimin.pan@oracle.com \
--to=weimin.pan@oracle.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).