aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-11-13 20:56:34 -0700
committerTom Tromey <tom@tromey.com>2016-12-02 09:11:47 -0700
commit0c1b455e294c6debb4efedc7f1346f3c43249f15 (patch)
tree99ae140e176b22fcf27a04f7d538e721d5810482 /gdb/testsuite
parentf5ac6ab387ef0974f6348ac7febc691fbb6c0eb4 (diff)
downloadgdb-0c1b455e294c6debb4efedc7f1346f3c43249f15.zip
gdb-0c1b455e294c6debb4efedc7f1346f3c43249f15.tar.gz
gdb-0c1b455e294c6debb4efedc7f1346f3c43249f15.tar.bz2
PR symtab/16264 - support DW_AT_main_subprogram
This patch adds support for DW_AT_main_subprogram. This is PR symtab/16264. DW_AT_main_subprogram is used to mark a program's entry point. GCC can emit this, and I hope to change the Rust compiler to emit it as well. GDB already supports an older, pre-DWARF 4 convention adopted by FORTRAN compilers, namely to emit DW_AT_calling_convention for the "main" function. However, I think this support in GDB had a small bug, in that it seems to rely on the DW_AT_name being read before DW_AT_calling_convention. This patch fixes this as well. Built and regtested on x86-64 Fedora 24 and the buildbot. New test case included. 2016-12-02 Tom Tromey <tom@tromey.com> PR symtab/16264: * dwarf2read.c (struct partial_die_info) <main_subprogram>: New member. (add_partial_symbol): Call set_objfile_main_name. (read_partial_die): Handle DW_AT_main_subprogram. <DW_AT_calling_convention>: don't call set_objfile_main_name, but set main_subprogram flag. 2016-12-02 Tom Tromey <tom@tromey.com> * gdb.dwarf2/main-subprogram.c: New file. * gdb.dwarf2/main-subprogram.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.dwarf2/main-subprogram.c29
-rw-r--r--gdb/testsuite/gdb.dwarf2/main-subprogram.exp73
3 files changed, 107 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0ec07ae..0e06d9e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-02 Tom Tromey <tom@tromey.com>
+
+ * gdb.dwarf2/main-subprogram.c: New file.
+ * gdb.dwarf2/main-subprogram.exp: New file.
+
2016-12-01 Luis Machado <lgustavo@codesourcery.com>
* gdb.base/maint.exp: Remove timeout handling for gdb_test_multiple.
diff --git a/gdb/testsuite/gdb.dwarf2/main-subprogram.c b/gdb/testsuite/gdb.dwarf2/main-subprogram.c
new file mode 100644
index 0000000..97ca22e
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/main-subprogram.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2016 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
+mymain ()
+{
+ asm ("mymain_label: .globl mymain_label");
+ return 0;
+}
+
+int
+main()
+{
+ return mymain ();
+}
diff --git a/gdb/testsuite/gdb.dwarf2/main-subprogram.exp b/gdb/testsuite/gdb.dwarf2/main-subprogram.exp
new file mode 100644
index 0000000..08c076b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/main-subprogram.exp
@@ -0,0 +1,73 @@
+# Copyright 2016 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 dwarf.exp
+
+# This test can only be run on targets which support DWARF-4 and use gas.
+if {![dwarf2_support]} {
+ return 0
+}
+
+standard_testfile main-subprogram.c enum-type-dw.S
+
+# Make some DWARF for the test.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ global srcdir subdir srcfile
+
+ set range [function_range mymain ${srcdir}/${subdir}/${srcfile}]
+ set mymain_start [lindex $range 0]
+ set mymain_length [lindex $range 1]
+
+ cu {} {
+ DW_TAG_compile_unit {
+ {DW_AT_language @DW_LANG_C}
+ {DW_AT_name main-subprogram.c}
+ {DW_AT_comp_dir /tmp}
+ } {
+ declare_labels type
+
+ type: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_signed}
+ {DW_AT_name int}
+ }
+
+ DW_TAG_subprogram {
+ {name mymain}
+ {low_pc $mymain_start addr}
+ {high_pc "$mymain_start + $mymain_length" addr}
+ {type :$type}
+ {DW_AT_main_subprogram 1 flag}
+ } {
+ }
+ }
+ }
+}
+
+if {[prepare_for_testing ${testfile}.exp ${testfile} \
+ [list $srcfile $asm_file] {nodebug}]} {
+ return -1
+}
+
+# Test that the "start" command stops in the "mymain" function.
+# This should happen because we used DW_AT_main_subprogram to tell gdb
+# that this was the real "main".
+
+if {[gdb_start_cmd] < 0} {
+ untested "could not start ${testfile}"
+ return -1
+}
+
+gdb_test "" "Temporary breakpoint .* mymain.*" "stopped at mymain"