Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH][gdb/testsuite] Add gdb.dwarf2/fission-multi-cu-clang.exp
Date: Thu, 5 Nov 2020 17:40:18 +0100	[thread overview]
Message-ID: <20201105164017.GA26390@delia> (raw)

Hi,

Test-case gdb.dwarf2/fission-multi-cu.exp uses an .S file that is
intended to represent output of clang -g -gsplit-dwarf -flto.

PR26834 - "[gsplit-dwarf] Sharing .debug_line entry between CUs results in too
many symtabs" is open about the fact that the test-case doesn't seem to be
properly handled atm.

The question is how serious that is:  the actual output of clang-10 -g
-gsplit-dwarf -flto seems to be handled ok.  What seems more serious is that
there's currently no test-case exercising the actual clang output.

Add a dwarf assembly test-case that resembles clang-10 -g -gsplit-dwarf -flto
output.

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Add gdb.dwarf2/fission-multi-cu-clang.exp

gdb/testsuite/ChangeLog:

2020-11-05  Tom de Vries  <tdevries@suse.de>

	* lib/dwarf.exp (_handle_DW_FORM): Add handling of
	DW_FORM_GNU_addr_index.
	(_default_form): Add handling of DW_AT_GNU_dwo_name,
	DW_AT_GNU_addr_base, DW_AT_GNU_pubnames and DW_AT_GNU_dwo_id.
	* gdb.dwarf2/fission-multi-cu-clang.c: New test.
	* gdb.dwarf2/fission-multi-cu-clang.exp: New file.

---
 gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.c  |  34 +++
 .../gdb.dwarf2/fission-multi-cu-clang.exp          | 285 +++++++++++++++++++++
 gdb/testsuite/lib/dwarf.exp                        |  16 +-
 3 files changed, 332 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.c b/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.c
new file mode 100644
index 0000000000..d7ecef3c65
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.c
@@ -0,0 +1,34 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020 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
+func (int arg)
+{
+  asm ("func_label: .globl func_label");
+  int res = arg + 1;
+  asm ("func_label_2: .globl func_label_2");
+  return res;
+}
+
+int
+main (void)
+{
+  asm ("main_label: .globl main_label");
+  int res = func (-1);
+  asm ("main_label_2: .globl main_label_2");
+  return res;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.exp b/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.exp
new file mode 100644
index 0000000000..db8ef09f21
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu-clang.exp
@@ -0,0 +1,285 @@
+# Copyright 2020 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
+
+# We run objcopy locally to split out the .dwo file.
+if [is_remote host] {
+    return 0
+}
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if ![dwarf2_support] {
+    return 0
+}
+
+# This test can only be run on x86-64 targets.
+if {![istarget x86_64-*] || ![is_lp64_target]} {
+    return 0
+}
+
+standard_testfile .c -dw.S
+
+# The sources we're pretending to compile.
+set src1 fission-multi-cu1.c
+set src2 fission-multi-cu2.c
+
+lassign \
+    [function_range main \
+	 "${srcdir}/${subdir}/${srcfile}"] \
+    main_start main_length
+
+lassign \
+    [function_range func \
+	 "${srcdir}/${subdir}/${srcfile}"] \
+    func_start func_length
+
+set debug_addr \
+    [list \
+	 ".Laddr_table_base0:" \
+         "  .quad $func_start" \
+         "  .quad $main_start"]
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    declare_labels Llines1 Llines2 int_type_cu1 int_type_cu2 Lmain Lfunc
+    global srcdir subdir srcfile src1 src2
+    global main_start main_length
+    global func_start func_length
+
+    set dwo_file "fission-multi-cu-clang-dw.dwo"
+
+    set debug_gnu_pubtypes \
+	[list \
+	     ".long   .LpubTypes_end0-.LpubTypes_begin0" \
+	     ".LpubTypes_begin0:" \
+	     ".short  2                       # DWARF Version" \
+	     ".long   .Lcu1_begin             # Offset of Compilation Unit Info" \
+	     ".long   .Lcu1_end - .Lcu1_begin # Compilation Unit Length" \
+	     \
+	     ".long   $int_type_cu1 - .Lcu3_begin    # DIE offset" \
+	     ".byte   144                     # Attributes: TYPE, STATIC" \
+	     ".asciz  \"int\"                 # External Name" \
+	     \
+	     ".long   0                       # End Mark" \
+	     ".LpubTypes_end0:" \
+	     \
+	     ".long   .LpubTypes_end1-.LpubTypes_begin1" \
+	     ".LpubTypes_begin1:" \
+	     ".short  2                       # DWARF Version" \
+	     ".long   .Lcu2_begin             # Offset of Compilation Unit Info" \
+	     ".long   .Lcu2_end - .Lcu2_begin # Compilation Unit Length" \
+	     \
+	     ".long   $int_type_cu2 - .Lcu4_begin    # DIE offset" \
+	     ".byte   144                     # Attributes: TYPE, STATIC" \
+	     ".asciz  \"int\"                 # External Name" \
+	     \
+	     ".long   0                       # End Mark" \
+	     ".LpubTypes_end1:"]
+
+    set debug_gnu_pubnames \
+	[list \
+	     ".long   .LpubNames_end0-.LpubNames_begin0" \
+	     ".LpubNames_begin0:" \
+	     ".short  2                       # DWARF Version" \
+	     ".long   .Lcu1_begin             # Offset of Compilation Unit Info" \
+	     ".long   .Lcu1_end - .Lcu1_begin # Compilation Unit Length" \
+	     \
+	     ".long   $Lfunc - .Lcu3_begin     # DIE offset" \
+	     ".byte   48                      # Attributes: FUNCTION, EXTERNAL" \
+	     ".asciz  \"func\"                # External Name" \
+	     \
+	     ".long   0                       # End Mark" \
+	     ".LpubNames_end0:" \
+	     \
+	     ".long   .LpubNames_end1-.LpubNames_begin1" \
+	     ".LpubNames_begin1:" \
+	     ".short  2                       # DWARF Version" \
+	     ".long   .Lcu2_begin             # Offset of Compilation Unit Info" \
+	     ".long   .Lcu2_end - .Lcu2_begin # Compilation Unit Length" \
+	     \
+	     ".long   $Lmain - .Lcu4_begin     # DIE offset" \
+	     ".byte   48                      # Attributes: FUNCTION, EXTERNAL" \
+	     ".asciz  \"main\"                # External Name" \
+	     \
+	     ".long   0                       # End Mark" \
+	     ".LpubNames_end1:" \
+	    ]
+
+    cu { } {
+	compile_unit {
+	    {language @DW_LANG_C}
+	    {name $src1}
+	    {stmt_list $Llines1 DW_FORM_sec_offset}
+	    {MACRO_AT_range {func}}
+	    {GNU_addr_base .Laddr_table_base0}
+	    {GNU_pubnames 1}
+	    {GNU_dwo_name $dwo_file}
+	    {DW_AT_GNU_dwo_id 0x1df972c106d3763d}
+	} {
+	}
+    }
+
+    cu {} {
+	compile_unit {
+	    {language @DW_LANG_C}
+	    {name $src2}
+	    {stmt_list $Llines2 DW_FORM_sec_offset}
+	    {MACRO_AT_range {main}}
+	    {GNU_addr_base .Laddr_table_base0}
+	    {GNU_pubnames 1}
+	    {GNU_dwo_name $dwo_file}
+	    {DW_AT_GNU_dwo_id  0xa9964b563d050e18}
+	} {
+	}
+    }
+
+    lines {version 2} Llines1 {
+	include_dir "${srcdir}/${subdir}"
+	file_name $src1 1
+
+	program {
+	    {DW_LNE_set_address $func_start}
+	    {line 20}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address func_label}
+	    {line 21}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address func_label_2}
+	    {DW_LNE_end_sequence}
+	}
+    }
+
+    lines {version 2} Llines2 {
+	include_dir "${srcdir}/${subdir}"
+	file_name $src2 1
+
+	program {
+	    {DW_LNE_set_address $main_start}
+	    {line 22}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address main_label}
+	    {line 23}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address main_label_2}
+	    {DW_LNE_end_sequence}
+	}
+    }
+
+    _defer_output .debug_addr {
+	global debug_addr
+	_emit [join $debug_addr "\n"]
+    }
+
+    _defer_output .debug_gnu_pubnames {
+	_emit [join $debug_gnu_pubnames "\n"]
+    }
+
+    _defer_output .debug_gnu_pubtype {
+	_emit [join $debug_gnu_pubtypes "\n"]
+    }
+
+    cu { fission first } {
+	compile_unit {
+	    {language @DW_LANG_C}
+	    {name $src1}
+	    {GNU_dwo_name $dwo_file}
+	    {DW_AT_GNU_dwo_id  0x1df972c106d3763d}
+	} {
+	    Lfunc: subprogram {
+		{external 1 flag}
+		{name func}
+		{low_pc 0 DW_FORM_GNU_addr_index}
+		{high_pc $func_length DW_FORM_data4}
+		{type :$int_type_cu1}
+		{decl_file 1 udata}
+	    } {
+                DW_TAG_formal_parameter {
+                    {type :$int_type_cu1}
+                    {name arg}
+		    {DW_AT_const_value -1 DW_FORM_sdata}
+                }
+	    }
+	    int_type_cu1: base_type {
+		{name "int"}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+	}
+    }
+
+    cu { fission last } {
+	compile_unit {
+	    {language @DW_LANG_C}
+	    {name $src2}
+	    {GNU_dwo_name $dwo_file}
+	    {DW_AT_GNU_dwo_id  0xa9964b563d050e18}
+	} {
+	    Lmain: subprogram {
+		{external 1 flag}
+		{name main}
+		{low_pc 1 DW_FORM_GNU_addr_index}
+		{high_pc $main_length DW_FORM_data4}
+		{type :$int_type_cu2}
+		{decl_file 1 udata}
+	    }
+	    int_type_cu2: base_type {
+		{name "int"}
+		{encoding @DW_ATE_signed}
+		{byte_size 4 DW_FORM_sdata}
+	    }
+	}
+    }
+
+}
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" [list $asm_file] [list $srcfile] {nodebug}] {
+    return -1
+}
+
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+# Make sure we can find the .dwo file, regardless of whether we're
+# running in parallel mode.
+gdb_test_no_output "set debug-file-directory [file dirname $binfile]" \
+    "set debug-file-directory"
+gdb_load $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Do a few basic things to verify we're finding the DWO debug info.
+
+gdb_test "ptype main" "type = int \\(\\)"
+gdb_test "ptype func" "type = int \\(int\\)"
+
+gdb_test "frame" "#0 *main \\(\\) at .*$src2:$decimal.*" \
+    "frame in main"
+
+gdb_test "break func" "Breakpoint.*at.* file .*$src1, line .*"
+
+gdb_test "continue" "Breakpoint.* func \\(arg=-1\\).*" \
+    "continue to func"
+
+gdb_test "frame" "#0 *func \\(arg=-1\\) at .*$src1:$decimal.*" \
+    "frame in func"
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index c18130b74d..72bc1ee172 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -500,7 +500,8 @@ namespace eval Dwarf {
 	    }
 
 	    DW_FORM_ref_udata -
-	    DW_FORM_udata {
+	    DW_FORM_udata -
+	    DW_FORM_GNU_addr_index {
 		_op .uleb128 $value
 	    }
 
@@ -573,7 +574,6 @@ namespace eval Dwarf {
 	    DW_FORM_strx3 -
 	    DW_FORM_strx4 -
 
-	    DW_FORM_GNU_addr_index -
 	    DW_FORM_GNU_str_index -
 	    DW_FORM_GNU_ref_alt -
 	    DW_FORM_GNU_strp_alt -
@@ -628,9 +628,19 @@ namespace eval Dwarf {
 	    DW_AT_comp_dir -
 	    DW_AT_linkage_name -
 	    DW_AT_MIPS_linkage_name -
-	    DW_AT_name {
+	    DW_AT_name -
+	    DW_AT_GNU_dwo_name {
 		return DW_FORM_string
 	    }
+	    DW_AT_GNU_addr_base {
+		return DW_FORM_sec_offset
+	    }
+	    DW_AT_GNU_pubnames {
+		return DW_FORM_flag_present
+	    }
+	    DW_AT_GNU_dwo_id {
+		return DW_FORM_data8
+	    }
 	}
 	return ""
     }

             reply	other threads:[~2020-11-05 16:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 16:40 Tom de Vries [this message]
2020-11-10 19:21 ` Simon Marchi
2020-11-11  9:18   ` [PATCH][gdb/testsuite] Use clean_restart where possible Tom de Vries
2020-11-11 15:49     ` Simon Marchi

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=20201105164017.GA26390@delia \
    --to=tdevries@suse.de \
    --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