public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add directory containing executable to relative search paths for .dwo files.
@ 2021-03-03  0:42 Caroline Tice
  2021-03-03  9:53 ` Andrew Burgess
  0 siblings, 1 reply; 17+ messages in thread
From: Caroline Tice @ 2021-03-03  0:42 UTC (permalink / raw)
  To: Caroline Tice via Gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]

DWARF allows .dwo file paths to be relative rather than absolute. When
they are relative, DWARF uses DW_AT_comp_dir to find the .dwo file.
DW_AT_comp_dir can also be relative, making the entire search patch
for the .dwo file relative. In this case, GDB currently searches
relative to its current working directory, i.e. the directory from
which the debugger was launched, but not relative to the directory
containing the built binary.  This cannot be right, as the compiler,
when generating the relative paths, knows where it's building the
binary but can have no idea where the debugger will be launched. The
correct thing is to add the directory containing the binary to the
search paths used for resolving relative locations of dwo files. That
is what this patch does.

I have run this through the regression testsuite with no regressions,
and I have verified that my new testcase passes with
this patch and fails without it.

Is this patch OK to commit?

-- Caroline Tice
cmtice@google.com

gdb/ChangeLog

2021-03-02  Caroline Tice  <cmtice@google.com>

        * dwarf2/read.c (try_open_dwop_file): Add path for the binary
        to the search paths used resolve relative location of .dwo file.

gdb/testsuite/ChangeLog

2021-03-02  Caroline Tice <cmtice@google.com>

        * gdb.dwarf2/fission-relative-dwo.c: New file.
        * gdb.dwarf2/fission-relative-dwo.S: New file.
        * gdb.dwarf2/fission-relative-dwo.exp: New file.

[-- Attachment #2: 0001-Add-directory-containing-executable-to-relative-sear.patch --]
[-- Type: application/octet-stream, Size: 11036 bytes --]

From 83056b931839107f131c0059377a011876df051b Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice@google.com>
Date: Tue, 2 Mar 2021 16:15:54 -0800
Subject: [PATCH] Add directory containing executable to relative search paths
 for .dwo files.

DWARF allows .dwo file paths to be relative rather than absolute. When
they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
file. DW_AT_comp_dir can also be relative, making the entire search
patch for the .dwo file relative. In this case, GDB currently searches
relative to its current working directory, i.e. the directory from
which the debugger was launched, but not relative to the directory
containing the built binary.  This cannot be right, as the compiler,
which generating the relative paths, knows where it's building the
binary but can have no idea where the debugger will be launched. The
correct thing is to add the directory containing the binary to the
search paths used for resolving relative locations of dwo files. That
is what this patch does.
---
 gdb/dwarf2/read.c                             |   6 +
 .../gdb.dwarf2/fission-relative-dwo.S         | 407 ++++++++++++++++++
 .../gdb.dwarf2/fission-relative-dwo.c         |  10 +
 .../gdb.dwarf2/fission-relative-dwo.exp       |  52 +++
 4 files changed, 475 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d4f13229ced..7cac5027d41 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12809,6 +12809,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
   else
     search_path = debug_file_directory;
 
+  /* Add the path for the executable binary to the list of search paths.  */
+  search_path_holder.reset(
+      concat(ldirname(per_objfile->objfile->original_name).c_str(),
+	     dirname_separator_string, search_path, (char *) NULL));
+  search_path = search_path_holder.get();
+
   openp_flags flags = OPF_RETURN_REALPATH;
   if (is_dwp)
     flags |= OPF_SEARCH_IN_PATH;
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
new file mode 100644
index 00000000000..b1541c13bdf
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
@@ -0,0 +1,407 @@
+	.file	"fission-relative-dwo.c"
+	.text
+.Ltext0:
+	.globl	main
+	.type	main, @function
+main:
+.LFB0:
+	.file 1 "fission-relative-dwo.c"
+	.loc 1 3 1
+	.cfi_startproc
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset 6, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register 6
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	.loc 1 4 7
+	movl	$10, -4(%rbp)
+	.loc 1 5 8
+	movw	$25185, -7(%rbp)
+	movb	$99, -5(%rbp)
+	.loc 1 7 15
+	movzbl	-7(%rbp), %eax
+	.loc 1 7 8
+	movsbl	%al, %edx
+	.loc 1 7 28
+	movzbl	-6(%rbp), %eax
+	.loc 1 7 21
+	movsbl	%al, %eax
+	.loc 1 7 19
+	addl	%edx, %eax
+	.loc 1 7 5
+	addl	%eax, -4(%rbp)
+	.loc 1 9 10
+	movl	$0, %eax
+	.loc 1 10 1
+	popq	%rbp
+	.cfi_def_cfa 7, 8
+	ret
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+.Letext0:
+	.section	.debug_addr,"",@progbits
+.Ldebug_addr0:
+	.quad	.LFB0
+	.section	.debug_info.dwo,"e",@progbits
+.Ldebug_info0:
+	.long	0x8c
+	.value	0x4
+	.long	.Ldebug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.uleb128 0x2
+	.byte	0xc
+	.uleb128 0x3
+	.string	"."
+	.byte	0xf6
+	.byte	0xc
+	.byte	0xa7
+	.byte	0x6d
+	.byte	0x40
+	.byte	0x43
+	.byte	0xfa
+	.byte	0x71
+	.uleb128 0x2
+	.uleb128 0x4
+	.byte	0x1
+	.byte	0x2
+	.byte	0x5
+	.long	0x64
+	.uleb128 0
+	.quad	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.long	0x64
+	.uleb128 0x3
+	.uleb128 0x6
+	.byte	0x1
+	.byte	0x2
+	.byte	0xf
+	.long	0x64
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -36
+	.uleb128 0x3
+	.uleb128 0x1
+	.byte	0x1
+	.byte	0x2
+	.byte	0x1c
+	.long	0x6b
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -48
+	.uleb128 0x4
+	.string	"x"
+	.byte	0x1
+	.byte	0x4
+	.byte	0x7
+	.long	0x64
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -20
+	.uleb128 0x4
+	.string	"y"
+	.byte	0x1
+	.byte	0x5
+	.byte	0x8
+	.long	0x7b
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -23
+	.byte	0
+	.uleb128 0x5
+	.byte	0x4
+	.byte	0x5
+	.string	"int"
+	.uleb128 0x6
+	.byte	0x8
+	.long	0x71
+	.uleb128 0x6
+	.byte	0x8
+	.long	0x77
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x6
+	.uleb128 0x5
+	.uleb128 0x8
+	.long	0x77
+	.long	0x8b
+	.uleb128 0x9
+	.long	0x8b
+	.byte	0x2
+	.byte	0
+	.uleb128 0x7
+	.byte	0x8
+	.byte	0x7
+	.uleb128 0
+	.byte	0
+	.section	.debug_info,"",@progbits
+.Lskeleton_debug_info0:
+	.long	0x2e
+	.value	0x4
+	.long	.Lskeleton_debug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.quad	.Ltext0
+	.quad	.Letext0-.Ltext0
+	.long	.Ldebug_line0
+	.long	.LASF0
+	.string	"."
+	.long	.Ldebug_addr0
+	.byte	0xf6
+	.byte	0xc
+	.byte	0xa7
+	.byte	0x6d
+	.byte	0x40
+	.byte	0x43
+	.byte	0xfa
+	.byte	0x71
+	.section	.debug_abbrev,"",@progbits
+.Lskeleton_debug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x10
+	.uleb128 0x17
+	.uleb128 0x2130
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2134
+	.uleb128 0x19
+	.uleb128 0x2133
+	.uleb128 0x17
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_abbrev.dwo,"e",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0x1f02
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0x19
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1f01
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2117
+	.uleb128 0x19
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x4
+	.uleb128 0x34
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x5
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0
+	.byte	0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.byte	0
+	.byte	0
+	.uleb128 0x8
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x9
+	.uleb128 0x21
+	.byte	0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_gnu_pubnames,"",@progbits
+	.long	0x18
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x90
+	.long	0x19
+	.byte	0x30
+	.string	"main"
+	.long	0
+	.section	.debug_gnu_pubtypes,"",@progbits
+	.long	0x38
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x90
+	.long	0x64
+	.byte	0x90
+	.string	"int"
+	.long	0x77
+	.byte	0x90
+	.string	"char"
+	.long	0x8b
+	.byte	0x90
+	.string	"long unsigned int"
+	.long	0
+	.section	.debug_aranges,"",@progbits
+	.long	0x2c
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.byte	0x8
+	.byte	0
+	.value	0
+	.value	0
+	.quad	.Ltext0
+	.quad	.Letext0-.Ltext0
+	.quad	0
+	.quad	0
+	.section	.debug_line,"",@progbits
+.Ldebug_line0:
+	.section	.debug_line.dwo,"e",@progbits
+.Lskeleton_debug_line0:
+	.long	.LELT0-.LSLT0
+.LSLT0:
+	.value	0x4
+	.long	.LELTP0-.LASLTP0
+.LASLTP0:
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0xf6
+	.byte	0xf2
+	.byte	0xd
+	.byte	0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.string	"fission-relative-dwo.c"
+	.uleb128 0
+	.uleb128 0
+	.uleb128 0
+	.byte	0
+.LELTP0:
+.LELT0:
+	.section	.debug_str,"MS",@progbits,1
+.LASF0:
+	.string	"fission-relative-dwo.dwo"
+	.section	.debug_str_offsets.dwo,"e",@progbits
+	.long	0
+	.long	0x12
+	.long	0x17
+	.long	0x7b
+	.long	0x92
+	.long	0x97
+	.long	0x9c
+	.section	.debug_str.dwo,"e",@progbits
+	.string	"long unsigned int"
+	.string	"argv"
+	.string	"GNU C17 10.2.1 20210110 -mtune=generic -march=x86-64 -gsplit-dwarf -O0 -fasynchronous-unwind-tables"
+	.string	"fission-relative-dwo.c"
+	.string	"main"
+	.string	"char"
+	.string	"argc"
+	.ident	"GCC: (Debian 10.2.1-6+build1) 10.2.1 20210110"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
new file mode 100644
index 00000000000..4c5f0b88b0b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
@@ -0,0 +1,10 @@
+
+int main (int argc, char **argv)
+{
+  int x = 10;
+  char y[3] = { 'a', 'b', 'c' };
+  
+  x += (int) y[0] + (int) y[1];
+  
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
new file mode 100644
index 00000000000..3d0b9b9fb5f
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
@@ -0,0 +1,52 @@
+# Copyright 2013-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/>.
+
+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 .S
+
+set dwo [standard_output_file "fission-relative-dwo.dwo"]
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" "$srcfile" \
+	[list nodebug additional_flags=-DDWO=$dwo]] {
+    return -1
+}
+
+clean_restart $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Verify gdb can find argc.
+
+gdb_test "p argc" " = 1"
+
-- 
2.30.1.766.gb4fecdf3b7-goog


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Add directory containing executable to relative search paths for .dwo files.
  2021-03-03  0:42 [PATCH] Add directory containing executable to relative search paths for .dwo files Caroline Tice
@ 2021-03-03  9:53 ` Andrew Burgess
  2021-03-04 15:48   ` [PATCH, v2] " Caroline Tice
  0 siblings, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2021-03-03  9:53 UTC (permalink / raw)
  To: Caroline Tice; +Cc: Caroline Tice via Gdb-patches

* Caroline Tice via Gdb-patches <gdb-patches@sourceware.org> [2021-03-02 16:42:08 -0800]:

> DWARF allows .dwo file paths to be relative rather than absolute. When
> they are relative, DWARF uses DW_AT_comp_dir to find the .dwo file.
> DW_AT_comp_dir can also be relative, making the entire search patch
> for the .dwo file relative. In this case, GDB currently searches
> relative to its current working directory, i.e. the directory from
> which the debugger was launched, but not relative to the directory
> containing the built binary.  This cannot be right, as the compiler,
> when generating the relative paths, knows where it's building the
> binary but can have no idea where the debugger will be launched. The
> correct thing is to add the directory containing the binary to the
> search paths used for resolving relative locations of dwo files. That
> is what this patch does.
> 
> I have run this through the regression testsuite with no regressions,
> and I have verified that my new testcase passes with
> this patch and fails without it.
> 
> Is this patch OK to commit?
> 
> -- Caroline Tice
> cmtice@google.com
> 
> gdb/ChangeLog
> 
> 2021-03-02  Caroline Tice  <cmtice@google.com>
> 
>         * dwarf2/read.c (try_open_dwop_file): Add path for the binary
>         to the search paths used resolve relative location of .dwo file.
> 
> gdb/testsuite/ChangeLog
> 
> 2021-03-02  Caroline Tice <cmtice@google.com>
> 
>         * gdb.dwarf2/fission-relative-dwo.c: New file.
>         * gdb.dwarf2/fission-relative-dwo.S: New file.
>         * gdb.dwarf2/fission-relative-dwo.exp: New file.

> From 83056b931839107f131c0059377a011876df051b Mon Sep 17 00:00:00 2001
> From: Caroline Tice <cmtice@google.com>
> Date: Tue, 2 Mar 2021 16:15:54 -0800
> Subject: [PATCH] Add directory containing executable to relative search paths
>  for .dwo files.
> 
> DWARF allows .dwo file paths to be relative rather than absolute. When
> they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
> file. DW_AT_comp_dir can also be relative, making the entire search
> patch for the .dwo file relative. In this case, GDB currently searches
> relative to its current working directory, i.e. the directory from
> which the debugger was launched, but not relative to the directory
> containing the built binary.  This cannot be right, as the compiler,
> which generating the relative paths, knows where it's building the
> binary but can have no idea where the debugger will be launched. The
> correct thing is to add the directory containing the binary to the
> search paths used for resolving relative locations of dwo files. That
> is what this patch does.
> ---
>  gdb/dwarf2/read.c                             |   6 +
>  .../gdb.dwarf2/fission-relative-dwo.S         | 407 ++++++++++++++++++
>  .../gdb.dwarf2/fission-relative-dwo.c         |  10 +
>  .../gdb.dwarf2/fission-relative-dwo.exp       |  52 +++
>  4 files changed, 475 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> 
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index d4f13229ced..7cac5027d41 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -12809,6 +12809,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
>    else
>      search_path = debug_file_directory;
>  
> +  /* Add the path for the executable binary to the list of search paths.  */
> +  search_path_holder.reset(
> +      concat(ldirname(per_objfile->objfile->original_name).c_str(),
> +	     dirname_separator_string, search_path, (char *) NULL));
> +  search_path = search_path_holder.get();

Missing whitespace before many of the '(' in this code.  Also I think
you should replace '(char *) NULL' with just 'nullptr'.

> +
>    openp_flags flags = OPF_RETURN_REALPATH;
>    if (is_dwp)
>      flags |= OPF_SEARCH_IN_PATH;
> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> new file mode 100644
> index 00000000000..4c5f0b88b0b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> @@ -0,0 +1,10 @@
> +
> +int main (int argc, char **argv)
> +{
> +  int x = 10;
> +  char y[3] = { 'a', 'b', 'c' };
> +  
> +  x += (int) y[0] + (int) y[1];
> +  
> +  return 0;
> +}

Test source files should include a copyright header, and should follow
GNU/GDB coding standard, unless the deviation is critical for the test
(which is not the case here).


> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> new file mode 100644
> index 00000000000..3d0b9b9fb5f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> @@ -0,0 +1,52 @@
> +# Copyright 2013-2021 Free Software Foundation, Inc.

The from date should represent the first time you posted this patch to
the mailing list.  I didn't check to see if this patch was posted in
2013.

> +
> +# 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 .S
> +
> +set dwo [standard_output_file "fission-relative-dwo.dwo"]
> +
> +if [build_executable_from_fission_assembler \
> +	"$testfile.exp" "$binfile" "$srcfile" \
> +	[list nodebug additional_flags=-DDWO=$dwo]] {
> +    return -1
> +}

Rather than using a fixed assembler file I would like to suggest you
write this test using GDB's DWARF assembler functionality.  This will
allow the test to run for any target, not just x86-64.

It's certainly easy to set the DW_AT_comp_dir to any value you need
using that tool.  From your patch description I don't know what else
you would need to modify in the DWARF, maybe nothing?

If you look for .exp files containing 'Dwarf::assemble' you'll find
loads of examples that you can draw inspiration from, but feel free to
ask if you have specific questions.

> +
> +clean_restart $binfile
> +
> +if ![runto_main] {
> +    return -1
> +}
> +
> +# Verify gdb can find argc.
> +
> +gdb_test "p argc" " = 1"

I guess you're looking for argc just to prove that GDB has found the
DWO file.

If you switch to GDB's DWARF assembler then generating debug
information to find a local variable is harder.  I would suggest that
instead, you make the test file something like this:

  int global_var;

  int
  main (void)
  {
    asm ("main_label: .globl main_label");
    return 0;
  }

Then in the generated DWARF give global_var a typedef type, your test
then becomes something like:

  gdb_test "ptype global_var" "type = ....."

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-03  9:53 ` Andrew Burgess
@ 2021-03-04 15:48   ` Caroline Tice
  2021-03-11 15:33     ` Caroline Tice
  2021-03-18  0:26     ` Andrew Burgess
  0 siblings, 2 replies; 17+ messages in thread
From: Caroline Tice @ 2021-03-04 15:48 UTC (permalink / raw)
  To: Andrew Burgess, Caroline Tice via Gdb-patches

[-- Attachment #1: Type: text/plain, Size: 9853 bytes --]

Hi Andrew,

I updated my change to gdb/dwarf2/read.c as you suggested (spaces
before '(' and use nullptr).

I spent a long time looking into using Dwarf::assemble in my testcase,
to make it hardware agnostic (although I'd like to point out
that most of the rest of the fission tests specifically only work for
x86_64), but in the end found that it would not work for me.   The
problems that I was unable to make this work for was that I needed to
generate not only the binary but the .dwo file; I needed reasonably
valid DWARF in both of them; and the path name for the .dwo file had
to be relative not absolute -- the way gdb compiles the test suites it
always uses complete absolute paths for all of its files.

As an alternative I created 4 different versions of the test: x86_64,
i386,  arm32 and aarch64.   I have attached a new version of the patch
with these changes.

 Is this ok to commit now?

-- Caroline
cmtice@google.com

gdb/ChangeLog

2021-03-04  Caroline Tice  <cmtice@google.com>

        * dwarf2/read.c (try_open_dwop_file): Add path for the binary
        to the search paths used resolve relative location of .dwo file.

gdb/testsuite/ChangeLog

2021-03-04  Caroline Tice <cmtice@google.com>

        * gdb.dwarf2/fission-relative-dwo.c: New file.
        * gdb.dwarf2/fission-relative-dwo-x86_64.S: New file.
        * gdb.dwarf2/fission-relative-dwo-x86_64.exp: New file.
        * gdb.dwarf2/fission-relative-dwo-i386.S: New file.
        * gdb.dwarf2/fission-relative-dwo-i386.exp: New file.
        * gdb.dwarf2/fission-relative-dwo-aarch64.S: New file.
        * gdb.dwarf2/fission-relative-dwo-aarch64.exp: New file.
        * gdb.dwarf2/fission-relative-dwo-arm32.S: New file.
        * gdb.dwarf2/fission-relative-dwo-arm32.exp: New file.



On Wed, Mar 3, 2021 at 1:53 AM Andrew Burgess
<andrew.burgess@embecosm.com> wrote:
>
> * Caroline Tice via Gdb-patches <gdb-patches@sourceware.org> [2021-03-02 16:42:08 -0800]:
>
> > DWARF allows .dwo file paths to be relative rather than absolute. When
> > they are relative, DWARF uses DW_AT_comp_dir to find the .dwo file.
> > DW_AT_comp_dir can also be relative, making the entire search patch
> > for the .dwo file relative. In this case, GDB currently searches
> > relative to its current working directory, i.e. the directory from
> > which the debugger was launched, but not relative to the directory
> > containing the built binary.  This cannot be right, as the compiler,
> > when generating the relative paths, knows where it's building the
> > binary but can have no idea where the debugger will be launched. The
> > correct thing is to add the directory containing the binary to the
> > search paths used for resolving relative locations of dwo files. That
> > is what this patch does.
> >
> > I have run this through the regression testsuite with no regressions,
> > and I have verified that my new testcase passes with
> > this patch and fails without it.
> >
> > Is this patch OK to commit?
> >
> > -- Caroline Tice
> > cmtice@google.com
> >
> > gdb/ChangeLog
> >
> > 2021-03-02  Caroline Tice  <cmtice@google.com>
> >
> >         * dwarf2/read.c (try_open_dwop_file): Add path for the binary
> >         to the search paths used resolve relative location of .dwo file.
> >
> > gdb/testsuite/ChangeLog
> >
> > 2021-03-02  Caroline Tice <cmtice@google.com>
> >
> >         * gdb.dwarf2/fission-relative-dwo.c: New file.
> >         * gdb.dwarf2/fission-relative-dwo.S: New file.
> >         * gdb.dwarf2/fission-relative-dwo.exp: New file.
>
> > From 83056b931839107f131c0059377a011876df051b Mon Sep 17 00:00:00 2001
> > From: Caroline Tice <cmtice@google.com>
> > Date: Tue, 2 Mar 2021 16:15:54 -0800
> > Subject: [PATCH] Add directory containing executable to relative search paths
> >  for .dwo files.
> >
> > DWARF allows .dwo file paths to be relative rather than absolute. When
> > they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
> > file. DW_AT_comp_dir can also be relative, making the entire search
> > patch for the .dwo file relative. In this case, GDB currently searches
> > relative to its current working directory, i.e. the directory from
> > which the debugger was launched, but not relative to the directory
> > containing the built binary.  This cannot be right, as the compiler,
> > which generating the relative paths, knows where it's building the
> > binary but can have no idea where the debugger will be launched. The
> > correct thing is to add the directory containing the binary to the
> > search paths used for resolving relative locations of dwo files. That
> > is what this patch does.
> > ---
> >  gdb/dwarf2/read.c                             |   6 +
> >  .../gdb.dwarf2/fission-relative-dwo.S         | 407 ++++++++++++++++++
> >  .../gdb.dwarf2/fission-relative-dwo.c         |  10 +
> >  .../gdb.dwarf2/fission-relative-dwo.exp       |  52 +++
> >  4 files changed, 475 insertions(+)
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> >
> > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> > index d4f13229ced..7cac5027d41 100644
> > --- a/gdb/dwarf2/read.c
> > +++ b/gdb/dwarf2/read.c
> > @@ -12809,6 +12809,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
> >    else
> >      search_path = debug_file_directory;
> >
> > +  /* Add the path for the executable binary to the list of search paths.  */
> > +  search_path_holder.reset(
> > +      concat(ldirname(per_objfile->objfile->original_name).c_str(),
> > +          dirname_separator_string, search_path, (char *) NULL));
> > +  search_path = search_path_holder.get();
>
> Missing whitespace before many of the '(' in this code.  Also I think
> you should replace '(char *) NULL' with just 'nullptr'.
>
> > +
> >    openp_flags flags = OPF_RETURN_REALPATH;
> >    if (is_dwp)
> >      flags |= OPF_SEARCH_IN_PATH;
> > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > new file mode 100644
> > index 00000000000..4c5f0b88b0b
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > @@ -0,0 +1,10 @@
> > +
> > +int main (int argc, char **argv)
> > +{
> > +  int x = 10;
> > +  char y[3] = { 'a', 'b', 'c' };
> > +
> > +  x += (int) y[0] + (int) y[1];
> > +
> > +  return 0;
> > +}
>
> Test source files should include a copyright header, and should follow
> GNU/GDB coding standard, unless the deviation is critical for the test
> (which is not the case here).
>
>
> > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > new file mode 100644
> > index 00000000000..3d0b9b9fb5f
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > @@ -0,0 +1,52 @@
> > +# Copyright 2013-2021 Free Software Foundation, Inc.
>
> The from date should represent the first time you posted this patch to
> the mailing list.  I didn't check to see if this patch was posted in
> 2013.
>
> > +
> > +# 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 .S
> > +
> > +set dwo [standard_output_file "fission-relative-dwo.dwo"]
> > +
> > +if [build_executable_from_fission_assembler \
> > +     "$testfile.exp" "$binfile" "$srcfile" \
> > +     [list nodebug additional_flags=-DDWO=$dwo]] {
> > +    return -1
> > +}
>
> Rather than using a fixed assembler file I would like to suggest you
> write this test using GDB's DWARF assembler functionality.  This will
> allow the test to run for any target, not just x86-64.
>
> It's certainly easy to set the DW_AT_comp_dir to any value you need
> using that tool.  From your patch description I don't know what else
> you would need to modify in the DWARF, maybe nothing?
>
> If you look for .exp files containing 'Dwarf::assemble' you'll find
> loads of examples that you can draw inspiration from, but feel free to
> ask if you have specific questions.
>
> > +
> > +clean_restart $binfile
> > +
> > +if ![runto_main] {
> > +    return -1
> > +}
> > +
> > +# Verify gdb can find argc.
> > +
> > +gdb_test "p argc" " = 1"
>
> I guess you're looking for argc just to prove that GDB has found the
> DWO file.
>
> If you switch to GDB's DWARF assembler then generating debug
> information to find a local variable is harder.  I would suggest that
> instead, you make the test file something like this:
>
>   int global_var;
>
>   int
>   main (void)
>   {
>     asm ("main_label: .globl main_label");
>     return 0;
>   }
>
> Then in the generated DWARF give global_var a typedef type, your test
> then becomes something like:
>
>   gdb_test "ptype global_var" "type = ....."
>
> Thanks,
> Andrew

[-- Attachment #2: v2-0001-Add-directory-containing-executable-to-relative-s.patch --]
[-- Type: application/octet-stream, Size: 41066 bytes --]

From 7f1e09f72bb230be48acb9dca29bdc5fbc28fb82 Mon Sep 17 00:00:00 2001
From: Caroline Tice <cmtice@google.com>
Date: Tue, 2 Mar 2021 16:15:54 -0800
Subject: [PATCH v2] Add directory containing executable to relative search
 paths for .dwo files.

DWARF allows .dwo file paths to be relative rather than absolute. When
they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
file. DW_AT_comp_dir can also be relative, making the entire search
patch for the .dwo file relative. In this case, GDB currently searches
relative to its current working directory, i.e. the directory from
which the debugger was launched, but not relative to the directory
containing the built binary.  This cannot be right, as the compiler,
which generating the relative paths, knows where it's building the
binary but can have no idea where the debugger will be launched. The
correct thing is to add the directory containing the binary to the
search paths used for resolving relative locations of dwo files. That
is what this patch does.
---
 gdb/dwarf2/read.c                             |   6 +
 .../gdb.dwarf2/fission-relative-dwo-aarch64.S | 421 +++++++++++++++
 .../fission-relative-dwo-aarch64.exp          |  52 ++
 .../gdb.dwarf2/fission-relative-dwo-arm32.S   | 479 ++++++++++++++++++
 .../gdb.dwarf2/fission-relative-dwo-arm32.exp |  52 ++
 .../gdb.dwarf2/fission-relative-dwo-i386.S    | 445 ++++++++++++++++
 .../gdb.dwarf2/fission-relative-dwo-i386.exp  |  52 ++
 .../gdb.dwarf2/fission-relative-dwo-x86_64.S  | 407 +++++++++++++++
 .../fission-relative-dwo-x86_64.exp           |  52 ++
 .../gdb.dwarf2/fission-relative-dwo.c         |  28 +
 10 files changed, 1994 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.exp
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.exp
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.exp
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.S
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.exp
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d4f13229ced..adf65a55b09 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12809,6 +12809,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
   else
     search_path = debug_file_directory;
 
+  /* Add the path for the executable binary to the list of search paths.  */
+  search_path_holder.reset (
+      concat (ldirname (per_objfile->objfile->original_name).c_str (),
+	      dirname_separator_string, search_path, nullptr));
+  search_path = search_path_holder.get ();
+
   openp_flags flags = OPF_RETURN_REALPATH;
   if (is_dwp)
     flags |= OPF_SEARCH_IN_PATH;
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.S b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.S
new file mode 100644
index 00000000000..c932a9c4d22
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.S
@@ -0,0 +1,421 @@
+	.cpu generic+fp+simd
+	.file	"fission-relative-dwo.c"
+	.text
+.Ltext0:
+	.cfi_sections	.debug_frame
+	.align	2
+	.global	main
+	.type	main, %function
+main:
+.LFB0:
+	.file 1 "fission-relative-dwo.c"
+	.loc 1 21 0
+	.cfi_startproc
+	stp	x29, x30, [sp, -64]!
+	.cfi_def_cfa_offset 64
+	.cfi_offset 29, -64
+	.cfi_offset 30, -56
+	add	x29, sp, 0
+	.cfi_def_cfa_register 29
+	str	w0, [x29,28]
+	str	x1, [x29,16]
+	.loc 1 21 0
+	adrp	x0, :got:__stack_chk_guard
+	ldr	x0, [x0, #:got_lo12:__stack_chk_guard]
+	ldr	x0, [x0]
+	str	x0, [x29,56]
+	.loc 1 22 0
+	mov	w0, 10
+	str	w0, [x29,44]
+	.loc 1 23 0
+	add	x0, x29, 48
+	mov	w1, 97
+	strb	w1, [x0]
+	add	x0, x29, 48
+	mov	w1, 98
+	strb	w1, [x0,1]
+	add	x0, x29, 48
+	mov	w1, 99
+	strb	w1, [x0,2]
+	.loc 1 25 0
+	add	x0, x29, 48
+	ldrb	w0, [x0]
+	mov	w1, w0
+	add	x0, x29, 48
+	ldrb	w0, [x0,1]
+	add	w0, w1, w0
+	ldr	w1, [x29,44]
+	add	w0, w1, w0
+	str	w0, [x29,44]
+	.loc 1 27 0
+	mov	w0, 0
+	.loc 1 28 0
+	adrp	x1, :got:__stack_chk_guard
+	ldr	x1, [x1, #:got_lo12:__stack_chk_guard]
+	ldr	x2, [x29,56]
+	ldr	x1, [x1]
+	cmp	x2, x1
+	beq	.L3
+	bl	__stack_chk_fail
+.L3:
+	ldp	x29, x30, [sp], 64
+	.cfi_restore 30
+	.cfi_restore 29
+	.cfi_def_cfa 31, 0
+	ret
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+.Letext0:
+	.section	.debug_addr,"",%progbits
+.Ldebug_addr0:
+	.8byte	.LFB0
+	.section	.debug_info.dwo,"",%progbits
+.Ldebug_info0:
+	.4byte	0x87
+	.2byte	0x4
+	.4byte	.Ldebug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.uleb128 0x2
+	.byte	0x1
+	.uleb128 0x3
+	.string	"."
+	.byte	0x96
+	.byte	0x6d
+	.byte	0x89
+	.byte	0x5c
+	.byte	0x8c
+	.byte	0x15
+	.byte	0xf
+	.byte	0x97
+	.uleb128 0x2
+	.uleb128 0x5
+	.byte	0x1
+	.byte	0x14
+	.4byte	0x5f
+	.uleb128 0
+	.8byte	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.4byte	0x5f
+	.uleb128 0x3
+	.uleb128 0x1
+	.byte	0x1
+	.byte	0x14
+	.4byte	0x5f
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -36
+	.uleb128 0x3
+	.uleb128 0
+	.byte	0x1
+	.byte	0x14
+	.4byte	0x66
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -48
+	.uleb128 0x4
+	.string	"x"
+	.byte	0x1
+	.byte	0x16
+	.4byte	0x5f
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -20
+	.uleb128 0x4
+	.string	"y"
+	.byte	0x1
+	.byte	0x17
+	.4byte	0x76
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -16
+	.byte	0
+	.uleb128 0x5
+	.byte	0x4
+	.byte	0x5
+	.string	"int"
+	.uleb128 0x6
+	.byte	0x8
+	.4byte	0x6c
+	.uleb128 0x6
+	.byte	0x8
+	.4byte	0x72
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x8
+	.uleb128 0x6
+	.uleb128 0x8
+	.4byte	0x72
+	.4byte	0x86
+	.uleb128 0x9
+	.4byte	0x86
+	.byte	0x2
+	.byte	0
+	.uleb128 0x7
+	.byte	0x8
+	.byte	0x7
+	.uleb128 0x4
+	.byte	0
+	.section	.debug_info,"",%progbits
+.Lskeleton_debug_info0:
+	.4byte	0x2e
+	.2byte	0x4
+	.4byte	.Lskeleton_debug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.8byte	.Ltext0
+	.8byte	.Letext0-.Ltext0
+	.4byte	.Ldebug_line0
+	.4byte	.LASF0
+	.string	"."
+	.4byte	.Ldebug_addr0
+	.byte	0x96
+	.byte	0x6d
+	.byte	0x89
+	.byte	0x5c
+	.byte	0x8c
+	.byte	0x15
+	.byte	0xf
+	.byte	0x97
+	.section	.debug_abbrev,"",%progbits
+.Lskeleton_debug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x10
+	.uleb128 0x17
+	.uleb128 0x2130
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2134
+	.uleb128 0x19
+	.uleb128 0x2133
+	.uleb128 0x17
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_abbrev.dwo,"",%progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0x1f02
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0x19
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1f01
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2116
+	.uleb128 0x19
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x4
+	.uleb128 0x34
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x5
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0
+	.byte	0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.byte	0
+	.byte	0
+	.uleb128 0x8
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x9
+	.uleb128 0x21
+	.byte	0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_gnu_pubnames,"",%progbits
+	.4byte	0x18
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.4byte	0x8b
+	.4byte	0x19
+	.byte	0x30
+	.string	"main"
+	.4byte	0
+	.section	.debug_gnu_pubtypes,"",%progbits
+	.4byte	0x2f
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.4byte	0x8b
+	.4byte	0x5f
+	.byte	0x90
+	.string	"int"
+	.4byte	0x72
+	.byte	0x90
+	.string	"char"
+	.4byte	0x86
+	.byte	0x90
+	.string	"sizetype"
+	.4byte	0
+	.section	.debug_aranges,"",%progbits
+	.4byte	0x2c
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.byte	0x8
+	.byte	0
+	.2byte	0
+	.2byte	0
+	.8byte	.Ltext0
+	.8byte	.Letext0-.Ltext0
+	.8byte	0
+	.8byte	0
+	.section	.debug_line,"",%progbits
+.Ldebug_line0:
+	.section	.debug_line.dwo,"",%progbits
+.Lskeleton_debug_line0:
+	.4byte	.LELT0-.LSLT0
+.LSLT0:
+	.2byte	0x4
+	.4byte	.LELTP0-.LASLTP0
+.LASLTP0:
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0xf6
+	.byte	0xf2
+	.byte	0xd
+	.byte	0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.string	"fission-relative-dwo.c"
+	.uleb128 0
+	.uleb128 0
+	.uleb128 0
+	.byte	0
+.LELTP0:
+.LELT0:
+	.section	.debug_str,"MS",%progbits,1
+.LASF0:
+	.string	"fission-relative-dwo-aarch64.dwo"
+	.section	.debug_str_offsets.dwo,"",%progbits
+	.4byte	0
+	.4byte	0x5
+	.4byte	0xa
+	.4byte	0xf5
+	.4byte	0x10c
+	.4byte	0x115
+	.4byte	0x11a
+	.section	.debug_str.dwo,"",%progbits
+	.string	"argv"
+	.string	"argc"
+	.string	"GNU C 4.9.x 20150123 (prerelease) -fpreprocessed -mlittle-endian -mabi=lp64 -gsplit-dwarf -O0 -fno-reorder-blocks-and-partition -fstack-protector-strong -fPIE -fno-omit-frame-pointer -fdebug-prefix-map=/home/cmtice/gdb-fission-tests=."
+	.string	"fission-relative-dwo.c"
+	.string	"sizetype"
+	.string	"main"
+	.string	"char"
+	.ident	"GCC: (4.9.2_cos_gg_4.9.2-r278-ac6128e0a17a52f011797f33ac3e7d6273a9368d_4.9.2-r278) 4.9.x 20150123 (prerelease)"
+	.section	.note.GNU-stack,"",%progbits
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.exp
new file mode 100644
index 00000000000..1142cdf56a5
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-aarch64.exp
@@ -0,0 +1,52 @@
+# 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/>.
+
+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 aarch64 targets.
+if {![istarget "aarch64*-*-linux*"] } {
+    return 0
+}
+
+standard_testfile .S
+
+set dwo [standard_output_file "fission-relative-dwo.dwo"]
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" "$srcfile" \
+	[list nodebug additional_flags=-DDWO=$dwo]] {
+    return -1
+}
+
+clean_restart $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Verify gdb can find argc.
+
+gdb_test "p argc" " = 1"
+
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.S b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.S
new file mode 100644
index 00000000000..13745e7162b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.S
@@ -0,0 +1,479 @@
+	.arch armv7-a
+	.eabi_attribute 28, 1
+	.eabi_attribute 20, 1
+	.eabi_attribute 21, 1
+	.eabi_attribute 23, 3
+	.eabi_attribute 24, 1
+	.eabi_attribute 25, 1
+	.eabi_attribute 26, 2
+	.eabi_attribute 30, 6
+	.eabi_attribute 34, 1
+	.eabi_attribute 18, 4
+	.file	"fission-relative-dwo.c"
+	.text
+.Ltext0:
+	.cfi_sections	.debug_frame
+	.section	.rodata
+	.align	2
+.LC0:
+	.ascii	"abc"
+	.text
+	.align	1
+	.global	main
+	.arch armv7-a
+	.syntax unified
+	.thumb
+	.thumb_func
+	.fpu vfpv3
+	.type	main, %function
+main:
+.LFB0:
+	.file 1 "fission-relative-dwo.c"
+	.loc 1 21 1
+	.cfi_startproc
+	@ args = 0, pretend = 0, frame = 24
+	@ frame_needed = 1, uses_anonymous_args = 0
+	push	{r7, lr}
+	.cfi_def_cfa_offset 8
+	.cfi_offset 7, -8
+	.cfi_offset 14, -4
+	sub	sp, sp, #24
+	.cfi_def_cfa_offset 32
+	add	r7, sp, #0
+	.cfi_def_cfa_register 7
+	str	r0, [r7, #4]
+	str	r1, [r7]
+	.loc 1 21 1
+	ldr	r2, .L4
+.LPIC1:
+	add	r2, pc
+	ldr	r3, .L4+4
+	ldr	r3, [r2, r3]
+	ldr	r3, [r3]
+	str	r3, [r7, #20]
+	mov	r3, #0
+	.loc 1 22 7
+	movs	r3, #10
+	str	r3, [r7, #12]
+	.loc 1 23 8
+	ldr	r2, .L4+8
+.LPIC0:
+	add	r2, pc
+	add	r3, r7, #16
+	ldr	r2, [r2]
+	mov	r1, r2	@ movhi
+	strh	r1, [r3]	@ movhi
+	adds	r3, r3, #2
+	lsrs	r2, r2, #16
+	strb	r2, [r3]
+	.loc 1 25 15
+	ldrb	r3, [r7, #16]	@ zero_extendqisi2
+	.loc 1 25 8
+	mov	r2, r3
+	.loc 1 25 28
+	ldrb	r3, [r7, #17]	@ zero_extendqisi2
+	.loc 1 25 19
+	add	r3, r3, r2
+	.loc 1 25 5
+	ldr	r2, [r7, #12]
+	add	r3, r3, r2
+	str	r3, [r7, #12]
+	.loc 1 27 10
+	movs	r3, #0
+	.loc 1 21 1
+	ldr	r1, .L4+12
+.LPIC2:
+	add	r1, pc
+	.loc 1 28 1
+	ldr	r2, .L4+4
+	ldr	r2, [r1, r2]
+	ldr	r1, [r2]
+	ldr	r2, [r7, #20]
+	eors	r1, r2, r1
+	beq	.L3
+	bl	__stack_chk_fail(PLT)
+.L3:
+	mov	r0, r3
+	adds	r7, r7, #24
+	.cfi_def_cfa_offset 8
+	mov	sp, r7
+	.cfi_def_cfa_register 13
+	@ sp needed
+	pop	{r7, pc}
+.L5:
+	.align	2
+.L4:
+	.word	_GLOBAL_OFFSET_TABLE_-(.LPIC1+4)
+	.word	__stack_chk_guard(GOT)
+	.word	.LC0-(.LPIC0+4)
+	.word	_GLOBAL_OFFSET_TABLE_-(.LPIC2+4)
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+.Letext0:
+	.section	.debug_addr,"",%progbits
+.Ldebug_addr0:
+	.4byte	.LFB0
+	.section	.debug_info.dwo,"e",%progbits
+.Ldebug_info0:
+	.4byte	0x88
+	.2byte	0x4
+	.4byte	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.uleb128 0x4
+	.byte	0xc
+	.uleb128 0x3
+	.ascii	".\000"
+	.byte	0x24
+	.byte	0x50
+	.byte	0xad
+	.byte	0xa5
+	.byte	0xcc
+	.byte	0xc5
+	.byte	0xb6
+	.byte	0x78
+	.uleb128 0x2
+	.uleb128 0x5
+	.byte	0x1
+	.byte	0x14
+	.byte	0x1
+	.4byte	0x60
+	.uleb128 0
+	.4byte	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.4byte	0x60
+	.uleb128 0x3
+	.uleb128 0x2
+	.byte	0x1
+	.byte	0x14
+	.byte	0xb
+	.4byte	0x60
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -28
+	.uleb128 0x3
+	.uleb128 0x1
+	.byte	0x1
+	.byte	0x14
+	.byte	0x18
+	.4byte	0x67
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -32
+	.uleb128 0x4
+	.ascii	"x\000"
+	.byte	0x1
+	.byte	0x16
+	.byte	0x7
+	.4byte	0x60
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -20
+	.uleb128 0x4
+	.ascii	"y\000"
+	.byte	0x1
+	.byte	0x17
+	.byte	0x8
+	.4byte	0x77
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -16
+	.byte	0
+	.uleb128 0x5
+	.byte	0x4
+	.byte	0x5
+	.ascii	"int\000"
+	.uleb128 0x6
+	.byte	0x4
+	.4byte	0x6d
+	.uleb128 0x6
+	.byte	0x4
+	.4byte	0x73
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x8
+	.uleb128 0x6
+	.uleb128 0x8
+	.4byte	0x73
+	.4byte	0x87
+	.uleb128 0x9
+	.4byte	0x87
+	.byte	0x2
+	.byte	0
+	.uleb128 0x7
+	.byte	0x4
+	.byte	0x7
+	.uleb128 0
+	.byte	0
+	.section	.debug_info,"",%progbits
+.Lskeleton_debug_info0:
+	.4byte	0x26
+	.2byte	0x4
+	.4byte	.Lskeleton_debug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.4byte	.Ltext0
+	.4byte	.Letext0-.Ltext0
+	.4byte	.Ldebug_line0
+	.4byte	.LASF0
+	.ascii	".\000"
+	.4byte	.Ldebug_addr0
+	.byte	0x24
+	.byte	0x50
+	.byte	0xad
+	.byte	0xa5
+	.byte	0xcc
+	.byte	0xc5
+	.byte	0xb6
+	.byte	0x78
+	.section	.debug_abbrev,"",%progbits
+.Lskeleton_debug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x6
+	.uleb128 0x10
+	.uleb128 0x17
+	.uleb128 0x2130
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2134
+	.uleb128 0x19
+	.uleb128 0x2133
+	.uleb128 0x17
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_abbrev.dwo,"e",%progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0x1f02
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0x19
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1f01
+	.uleb128 0x12
+	.uleb128 0x6
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2116
+	.uleb128 0x19
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x4
+	.uleb128 0x34
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x5
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0
+	.byte	0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.byte	0
+	.byte	0
+	.uleb128 0x8
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x9
+	.uleb128 0x21
+	.byte	0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_gnu_pubnames,"",%progbits
+	.4byte	0x18
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.4byte	0x8c
+	.4byte	0x19
+	.byte	0x30
+	.ascii	"main\000"
+	.4byte	0
+	.section	.debug_gnu_pubtypes,"",%progbits
+	.4byte	0x33
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.4byte	0x8c
+	.4byte	0x60
+	.byte	0x90
+	.ascii	"int\000"
+	.4byte	0x73
+	.byte	0x90
+	.ascii	"char\000"
+	.4byte	0x87
+	.byte	0x90
+	.ascii	"unsigned int\000"
+	.4byte	0
+	.section	.debug_aranges,"",%progbits
+	.4byte	0x1c
+	.2byte	0x2
+	.4byte	.Lskeleton_debug_info0
+	.byte	0x4
+	.byte	0
+	.2byte	0
+	.2byte	0
+	.4byte	.Ltext0
+	.4byte	.Letext0-.Ltext0
+	.4byte	0
+	.4byte	0
+	.section	.debug_line,"",%progbits
+.Ldebug_line0:
+	.section	.debug_line.dwo,"e",%progbits
+.Lskeleton_debug_line0:
+	.4byte	.LELT0-.LSLT0
+.LSLT0:
+	.2byte	0x4
+	.4byte	.LELTP0-.LASLTP0
+.LASLTP0:
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0xf6
+	.byte	0xf2
+	.byte	0xd
+	.byte	0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.ascii	"fission-relative-dwo.c\000"
+	.uleb128 0
+	.uleb128 0
+	.uleb128 0
+	.byte	0
+.LELTP0:
+.LELT0:
+	.section	.debug_str,"MS",%progbits,1
+.LASF0:
+	.ascii	"fission-relative-dwo-arm32.dwo\000"
+	.section	.debug_str_offsets.dwo,"e",%progbits
+	.4byte	0
+	.4byte	0xd
+	.4byte	0x12
+	.4byte	0x17
+	.4byte	0x2e
+	.4byte	0xe5
+	.4byte	0xea
+	.section	.debug_str.dwo,"e",%progbits
+	.ascii	"unsigned int\000"
+	.ascii	"argv\000"
+	.ascii	"argc\000"
+	.ascii	"fission-relative-dwo.c\000"
+	.ascii	"GNU C17 10.2.0 -mthumb -mfloat-abi=hard -mfpu=vfpv3"
+	.ascii	" -mtls-dialect=gnu -march=armv7-a+vfpv3 -gsplit-dwa"
+	.ascii	"rf -O0 -fno-reorder-blocks-and-partition -fcommon -"
+	.ascii	"fstack-protector-strong -fPIE\000"
+	.ascii	"main\000"
+	.ascii	"char\000"
+	.ident	"GCC: (GNU) 10.2.0"
+	.section	.note.GNU-stack,"",%progbits
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.exp
new file mode 100644
index 00000000000..ddc9edfa009
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-arm32.exp
@@ -0,0 +1,52 @@
+# 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/>.
+
+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 arm32 targets.
+if {![istarget "arm*-*-linux*"] || [istarget "aarch64*-*-*"] } {
+    return 0
+}
+
+standard_testfile .S
+
+set dwo [standard_output_file "fission-relative-dwo.dwo"]
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" "$srcfile" \
+	[list nodebug additional_flags=-DDWO=$dwo]] {
+    return -1
+}
+
+clean_restart $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Verify gdb can find argc.
+
+gdb_test "p argc" " = 1"
+
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.S b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.S
new file mode 100644
index 00000000000..101d0005a9a
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.S
@@ -0,0 +1,445 @@
+	.file	"fission-relative-dwo.c"
+	.text
+.Ltext0:
+	.cfi_sections	.debug_frame
+	.globl	main
+	.type	main, @function
+main:
+.LFB0:
+	.file 1 "fission-relative-dwo.c"
+	.loc 1 21 1
+	.cfi_startproc
+	pushl	%ebp
+	.cfi_def_cfa_offset 8
+	.cfi_offset 5, -8
+	movl	%esp, %ebp
+	.cfi_def_cfa_register 5
+	andl	$-16, %esp
+	leal	-32(%esp), %esp
+	call	__x86.get_pc_thunk.ax
+	addl	$_GLOBAL_OFFSET_TABLE_, %eax
+	movl	12(%ebp), %eax
+	movl	%eax, 12(%esp)
+	.loc 1 21 1
+	movl	%gs:20, %eax
+	movl	%eax, 28(%esp)
+	xorl	%eax, %eax
+	.loc 1 22 7
+	movl	$10, 20(%esp)
+	.loc 1 23 8
+	movw	$25185, 25(%esp)
+	movb	$99, 27(%esp)
+	.loc 1 25 15
+	movzbl	25(%esp), %eax
+	.loc 1 25 8
+	movsbl	%al, %edx
+	.loc 1 25 28
+	movzbl	26(%esp), %eax
+	.loc 1 25 21
+	movsbl	%al, %eax
+	.loc 1 25 19
+	addl	%edx, %eax
+	.loc 1 25 5
+	addl	%eax, 20(%esp)
+	.loc 1 27 10
+	movl	$0, %eax
+	.loc 1 28 1
+	movl	28(%esp), %ecx
+	subl	%gs:20, %ecx
+	je	.L3
+	call	__stack_chk_fail_local
+.L3:
+	movl	%ebp, %esp
+	.cfi_def_cfa_register 4
+	popl	%ebp
+	.cfi_restore 5
+	.cfi_def_cfa_offset 4
+	ret
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+	.section	.text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
+	.globl	__x86.get_pc_thunk.ax
+	.hidden	__x86.get_pc_thunk.ax
+	.type	__x86.get_pc_thunk.ax, @function
+__x86.get_pc_thunk.ax:
+.LFB1:
+	.cfi_startproc
+	nop
+	nop
+	nop
+	nop
+	nop
+	nop
+	nop
+	nop
+	movl	(%esp), %eax
+	ret
+	.cfi_endproc
+.LFE1:
+	.text
+.Letext0:
+	.section	.debug_addr,"",@progbits
+.Ldebug_addr0:
+	.long	.LFB0
+	.section	.debug_info.dwo,"e",@progbits
+.Ldebug_info0:
+	.long	0x88
+	.value	0x4
+	.long	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.uleb128 0x5
+	.byte	0xc
+	.uleb128 0x3
+	.string	"."
+	.byte	0x80
+	.byte	0xa9
+	.byte	0xc6
+	.byte	0x66
+	.byte	0xb2
+	.byte	0xec
+	.byte	0xb8
+	.byte	0x15
+	.uleb128 0x2
+	.uleb128 0x4
+	.byte	0x1
+	.byte	0x14
+	.byte	0x1
+	.long	0x60
+	.uleb128 0
+	.long	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.long	0x60
+	.uleb128 0x3
+	.uleb128 0x2
+	.byte	0x1
+	.byte	0x14
+	.byte	0xb
+	.long	0x60
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 0
+	.uleb128 0x3
+	.uleb128 0x1
+	.byte	0x1
+	.byte	0x14
+	.byte	0x18
+	.long	0x67
+	.uleb128 0x2
+	.byte	0x74
+	.sleb128 12
+	.uleb128 0x4
+	.string	"x"
+	.byte	0x1
+	.byte	0x16
+	.byte	0x7
+	.long	0x60
+	.uleb128 0x2
+	.byte	0x74
+	.sleb128 20
+	.uleb128 0x4
+	.string	"y"
+	.byte	0x1
+	.byte	0x17
+	.byte	0x8
+	.long	0x77
+	.uleb128 0x2
+	.byte	0x74
+	.sleb128 25
+	.byte	0
+	.uleb128 0x5
+	.byte	0x4
+	.byte	0x5
+	.string	"int"
+	.uleb128 0x6
+	.byte	0x4
+	.long	0x6d
+	.uleb128 0x6
+	.byte	0x4
+	.long	0x73
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x6
+	.uleb128 0x6
+	.uleb128 0x8
+	.long	0x73
+	.long	0x87
+	.uleb128 0x9
+	.long	0x87
+	.byte	0x2
+	.byte	0
+	.uleb128 0x7
+	.byte	0x4
+	.byte	0x7
+	.uleb128 0
+	.byte	0
+	.section	.debug_info,"",@progbits
+.Lskeleton_debug_info0:
+	.long	0x26
+	.value	0x4
+	.long	.Lskeleton_debug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+	.long	.Ltext0
+	.long	.Letext0-.Ltext0
+	.long	.Ldebug_line0
+	.long	.LASF0
+	.string	"."
+	.long	.Ldebug_addr0
+	.byte	0x80
+	.byte	0xa9
+	.byte	0xc6
+	.byte	0x66
+	.byte	0xb2
+	.byte	0xec
+	.byte	0xb8
+	.byte	0x15
+	.section	.debug_abbrev,"",@progbits
+.Lskeleton_debug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x6
+	.uleb128 0x10
+	.uleb128 0x17
+	.uleb128 0x2130
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2134
+	.uleb128 0x19
+	.uleb128 0x2133
+	.uleb128 0x17
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_abbrev.dwo,"e",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0x1f02
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0x19
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1f01
+	.uleb128 0x12
+	.uleb128 0x6
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2116
+	.uleb128 0x19
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x4
+	.uleb128 0x34
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x5
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0
+	.byte	0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.byte	0
+	.byte	0
+	.uleb128 0x8
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x9
+	.uleb128 0x21
+	.byte	0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_gnu_pubnames,"",@progbits
+	.long	0x18
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x8c
+	.long	0x19
+	.byte	0x30
+	.string	"main"
+	.long	0
+	.section	.debug_gnu_pubtypes,"",@progbits
+	.long	0x33
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x8c
+	.long	0x60
+	.byte	0x90
+	.string	"int"
+	.long	0x73
+	.byte	0x90
+	.string	"char"
+	.long	0x87
+	.byte	0x90
+	.string	"unsigned int"
+	.long	0
+	.section	.debug_aranges,"",@progbits
+	.long	0x1c
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.byte	0x4
+	.byte	0
+	.value	0
+	.value	0
+	.long	.Ltext0
+	.long	.Letext0-.Ltext0
+	.long	0
+	.long	0
+	.section	.debug_line,"",@progbits
+.Ldebug_line0:
+	.section	.debug_line.dwo,"e",@progbits
+.Lskeleton_debug_line0:
+	.long	.LELT0-.LSLT0
+.LSLT0:
+	.value	0x4
+	.long	.LELTP0-.LASLTP0
+.LASLTP0:
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0xf6
+	.byte	0xf2
+	.byte	0xd
+	.byte	0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.string	"fission-relative-dwo.c"
+	.uleb128 0
+	.uleb128 0
+	.uleb128 0
+	.byte	0
+.LELTP0:
+.LELT0:
+	.section	.debug_str,"MS",@progbits,1
+.LASF0:
+	.string	"fission-relative-dwo-i386.dwo"
+	.section	.debug_str_offsets.dwo,"e",@progbits
+	.long	0
+	.long	0xd
+	.long	0x12
+	.long	0x17
+	.long	0x2e
+	.long	0x33
+	.long	0xd9
+	.section	.debug_str.dwo,"e",@progbits
+	.string	"unsigned int"
+	.string	"argv"
+	.string	"argc"
+	.string	"fission-relative-dwo.c"
+	.string	"main"
+	.string	"GNU C17 10.2.0 -mno-movbe -mtune=atom -march=atom -gsplit-dwarf -O0 -fno-reorder-blocks-and-partition -fcommon -fstack-protector-strong -fPIE -fno-omit-frame-pointer"
+	.string	"char"
+	.hidden	__stack_chk_fail_local
+	.ident	"GCC: (GNU) 10.2.0"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.exp
new file mode 100644
index 00000000000..1006a785547
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-i386.exp
@@ -0,0 +1,52 @@
+# 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/>.
+
+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 32-bit x86 targets.
+if {![istarget "*86*-*linux*"] } {
+    return 0
+}
+
+standard_testfile .S
+
+set dwo [standard_output_file "fission-relative-dwo.dwo"]
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" "$srcfile" \
+	[list nodebug additional_flags=-DDWO=$dwo additional_flags=-m32]] {
+    return -1
+}
+
+clean_restart $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Verify gdb can find argc.
+
+gdb_test "p argc" " = 1"
+
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.S b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.S
new file mode 100644
index 00000000000..49fb51d8431
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.S
@@ -0,0 +1,407 @@
+	.file	"fission-relative-dwo.c"
+	.text
+.Ltext0:
+	.globl	main
+	.type	main, @function
+main:
+.LFB0:
+	.file 1 "fission-relative-dwo.c"
+	.loc 1 3 1
+	.cfi_startproc
+	pushq	%rbp
+	.cfi_def_cfa_offset 16
+	.cfi_offset 6, -16
+	movq	%rsp, %rbp
+	.cfi_def_cfa_register 6
+	movl	%edi, -20(%rbp)
+	movq	%rsi, -32(%rbp)
+	.loc 1 4 7
+	movl	$10, -4(%rbp)
+	.loc 1 5 8
+	movw	$25185, -7(%rbp)
+	movb	$99, -5(%rbp)
+	.loc 1 7 15
+	movzbl	-7(%rbp), %eax
+	.loc 1 7 8
+	movsbl	%al, %edx
+	.loc 1 7 28
+	movzbl	-6(%rbp), %eax
+	.loc 1 7 21
+	movsbl	%al, %eax
+	.loc 1 7 19
+	addl	%edx, %eax
+	.loc 1 7 5
+	addl	%eax, -4(%rbp)
+	.loc 1 9 10
+	movl	$0, %eax
+	.loc 1 10 1
+	popq	%rbp
+	.cfi_def_cfa 7, 8
+	ret
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+.Letext0:
+	.section	.debug_addr,"",@progbits
+.Ldebug_addr0:
+	.quad	.LFB0
+	.section	.debug_info.dwo,"e",@progbits
+.Ldebug_info0:
+	.long	0x8c
+	.value	0x4
+	.long	.Ldebug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.uleb128 0x2
+	.byte	0xc
+	.uleb128 0x3
+	.string	"."
+	.byte	0xf6
+	.byte	0xc
+	.byte	0xa7
+	.byte	0x6d
+	.byte	0x40
+	.byte	0x43
+	.byte	0xfa
+	.byte	0x71
+	.uleb128 0x2
+	.uleb128 0x4
+	.byte	0x1
+	.byte	0x2
+	.byte	0x5
+	.long	0x64
+	.uleb128 0
+	.quad	.LFE0-.LFB0
+	.uleb128 0x1
+	.byte	0x9c
+	.long	0x64
+	.uleb128 0x3
+	.uleb128 0x6
+	.byte	0x1
+	.byte	0x2
+	.byte	0xf
+	.long	0x64
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -36
+	.uleb128 0x3
+	.uleb128 0x1
+	.byte	0x1
+	.byte	0x2
+	.byte	0x1c
+	.long	0x6b
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -48
+	.uleb128 0x4
+	.string	"x"
+	.byte	0x1
+	.byte	0x4
+	.byte	0x7
+	.long	0x64
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -20
+	.uleb128 0x4
+	.string	"y"
+	.byte	0x1
+	.byte	0x5
+	.byte	0x8
+	.long	0x7b
+	.uleb128 0x2
+	.byte	0x91
+	.sleb128 -23
+	.byte	0
+	.uleb128 0x5
+	.byte	0x4
+	.byte	0x5
+	.string	"int"
+	.uleb128 0x6
+	.byte	0x8
+	.long	0x71
+	.uleb128 0x6
+	.byte	0x8
+	.long	0x77
+	.uleb128 0x7
+	.byte	0x1
+	.byte	0x6
+	.uleb128 0x5
+	.uleb128 0x8
+	.long	0x77
+	.long	0x8b
+	.uleb128 0x9
+	.long	0x8b
+	.byte	0x2
+	.byte	0
+	.uleb128 0x7
+	.byte	0x8
+	.byte	0x7
+	.uleb128 0
+	.byte	0
+	.section	.debug_info,"",@progbits
+.Lskeleton_debug_info0:
+	.long	0x2e
+	.value	0x4
+	.long	.Lskeleton_debug_abbrev0
+	.byte	0x8
+	.uleb128 0x1
+	.quad	.Ltext0
+	.quad	.Letext0-.Ltext0
+	.long	.Ldebug_line0
+	.long	.LASF0
+	.string	"."
+	.long	.Ldebug_addr0
+	.byte	0xf6
+	.byte	0xc
+	.byte	0xa7
+	.byte	0x6d
+	.byte	0x40
+	.byte	0x43
+	.byte	0xfa
+	.byte	0x71
+	.section	.debug_abbrev,"",@progbits
+.Lskeleton_debug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0
+	.uleb128 0x11
+	.uleb128 0x1
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x10
+	.uleb128 0x17
+	.uleb128 0x2130
+	.uleb128 0xe
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2134
+	.uleb128 0x19
+	.uleb128 0x2133
+	.uleb128 0x17
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_abbrev.dwo,"e",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1
+	.uleb128 0x11
+	.byte	0x1
+	.uleb128 0x25
+	.uleb128 0x1f02
+	.uleb128 0x13
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x1b
+	.uleb128 0x8
+	.uleb128 0x2131
+	.uleb128 0x7
+	.byte	0
+	.byte	0
+	.uleb128 0x2
+	.uleb128 0x2e
+	.byte	0x1
+	.uleb128 0x3f
+	.uleb128 0x19
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x27
+	.uleb128 0x19
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x11
+	.uleb128 0x1f01
+	.uleb128 0x12
+	.uleb128 0x7
+	.uleb128 0x40
+	.uleb128 0x18
+	.uleb128 0x2117
+	.uleb128 0x19
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x5
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x4
+	.uleb128 0x34
+	.byte	0
+	.uleb128 0x3
+	.uleb128 0x8
+	.uleb128 0x3a
+	.uleb128 0xb
+	.uleb128 0x3b
+	.uleb128 0xb
+	.uleb128 0x39
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2
+	.uleb128 0x18
+	.byte	0
+	.byte	0
+	.uleb128 0x5
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x8
+	.byte	0
+	.byte	0
+	.uleb128 0x6
+	.uleb128 0xf
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x49
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x7
+	.uleb128 0x24
+	.byte	0
+	.uleb128 0xb
+	.uleb128 0xb
+	.uleb128 0x3e
+	.uleb128 0xb
+	.uleb128 0x3
+	.uleb128 0x1f02
+	.byte	0
+	.byte	0
+	.uleb128 0x8
+	.uleb128 0x1
+	.byte	0x1
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x1
+	.uleb128 0x13
+	.byte	0
+	.byte	0
+	.uleb128 0x9
+	.uleb128 0x21
+	.byte	0
+	.uleb128 0x49
+	.uleb128 0x13
+	.uleb128 0x2f
+	.uleb128 0xb
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_gnu_pubnames,"",@progbits
+	.long	0x18
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x90
+	.long	0x19
+	.byte	0x30
+	.string	"main"
+	.long	0
+	.section	.debug_gnu_pubtypes,"",@progbits
+	.long	0x38
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.long	0x90
+	.long	0x64
+	.byte	0x90
+	.string	"int"
+	.long	0x77
+	.byte	0x90
+	.string	"char"
+	.long	0x8b
+	.byte	0x90
+	.string	"long unsigned int"
+	.long	0
+	.section	.debug_aranges,"",@progbits
+	.long	0x2c
+	.value	0x2
+	.long	.Lskeleton_debug_info0
+	.byte	0x8
+	.byte	0
+	.value	0
+	.value	0
+	.quad	.Ltext0
+	.quad	.Letext0-.Ltext0
+	.quad	0
+	.quad	0
+	.section	.debug_line,"",@progbits
+.Ldebug_line0:
+	.section	.debug_line.dwo,"e",@progbits
+.Lskeleton_debug_line0:
+	.long	.LELT0-.LSLT0
+.LSLT0:
+	.value	0x4
+	.long	.LELTP0-.LASLTP0
+.LASLTP0:
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0xf6
+	.byte	0xf2
+	.byte	0xd
+	.byte	0
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.byte	0
+	.byte	0x1
+	.byte	0
+	.string	"fission-relative-dwo.c"
+	.uleb128 0
+	.uleb128 0
+	.uleb128 0
+	.byte	0
+.LELTP0:
+.LELT0:
+	.section	.debug_str,"MS",@progbits,1
+.LASF0:
+	.string	"fission-relative-dwo-x86_64.dwo"
+	.section	.debug_str_offsets.dwo,"e",@progbits
+	.long	0
+	.long	0x12
+	.long	0x17
+	.long	0x7b
+	.long	0x92
+	.long	0x97
+	.long	0x9c
+	.section	.debug_str.dwo,"e",@progbits
+	.string	"long unsigned int"
+	.string	"argv"
+	.string	"GNU C17 10.2.1 20210110 -mtune=generic -march=x86-64 -gsplit-dwarf -O0 -fasynchronous-unwind-tables"
+	.string	"fission-relative-dwo.c"
+	.string	"main"
+	.string	"char"
+	.string	"argc"
+	.ident	"GCC: (Debian 10.2.1-6+build1) 10.2.1 20210110"
+	.section	.note.GNU-stack,"",@progbits
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.exp
new file mode 100644
index 00000000000..91dfd43eab9
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo-x86_64.exp
@@ -0,0 +1,52 @@
+# 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/>.
+
+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 .S
+
+set dwo [standard_output_file "fission-relative-dwo.dwo"]
+
+if [build_executable_from_fission_assembler \
+	"$testfile.exp" "$binfile" "$srcfile" \
+	[list nodebug additional_flags=-DDWO=$dwo]] {
+    return -1
+}
+
+clean_restart $binfile
+
+if ![runto_main] {
+    return -1
+}
+
+# Verify gdb can find argc.
+
+gdb_test "p argc" " = 1"
+
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
new file mode 100644
index 00000000000..c942ad8ce36
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
@@ -0,0 +1,28 @@
+
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012-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/>.  */
+
+int
+main (int argc, char **argv)
+{
+  int x = 10;
+  char y[3] = { 'a', 'b', 'c' };
+
+  x += (int) y[0] + (int) y[1];
+
+  return 0;
+}
-- 
2.30.1.766.gb4fecdf3b7-goog


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-04 15:48   ` [PATCH, v2] " Caroline Tice
@ 2021-03-11 15:33     ` Caroline Tice
  2021-03-18  0:26     ` Andrew Burgess
  1 sibling, 0 replies; 17+ messages in thread
From: Caroline Tice @ 2021-03-11 15:33 UTC (permalink / raw)
  To: Andrew Burgess, Caroline Tice via Gdb-patches

Ping?  Could somebody look at this please?  Thanks!

-- Caroline Tice
cmtice@google.com

On Thu, Mar 4, 2021 at 7:48 AM Caroline Tice <cmtice@google.com> wrote:
>
> Hi Andrew,
>
> I updated my change to gdb/dwarf2/read.c as you suggested (spaces
> before '(' and use nullptr).
>
> I spent a long time looking into using Dwarf::assemble in my testcase,
> to make it hardware agnostic (although I'd like to point out
> that most of the rest of the fission tests specifically only work for
> x86_64), but in the end found that it would not work for me.   The
> problems that I was unable to make this work for was that I needed to
> generate not only the binary but the .dwo file; I needed reasonably
> valid DWARF in both of them; and the path name for the .dwo file had
> to be relative not absolute -- the way gdb compiles the test suites it
> always uses complete absolute paths for all of its files.
>
> As an alternative I created 4 different versions of the test: x86_64,
> i386,  arm32 and aarch64.   I have attached a new version of the patch
> with these changes.
>
>  Is this ok to commit now?
>
> -- Caroline
> cmtice@google.com
>
> gdb/ChangeLog
>
> 2021-03-04  Caroline Tice  <cmtice@google.com>
>
>         * dwarf2/read.c (try_open_dwop_file): Add path for the binary
>         to the search paths used resolve relative location of .dwo file.
>
> gdb/testsuite/ChangeLog
>
> 2021-03-04  Caroline Tice <cmtice@google.com>
>
>         * gdb.dwarf2/fission-relative-dwo.c: New file.
>         * gdb.dwarf2/fission-relative-dwo-x86_64.S: New file.
>         * gdb.dwarf2/fission-relative-dwo-x86_64.exp: New file.
>         * gdb.dwarf2/fission-relative-dwo-i386.S: New file.
>         * gdb.dwarf2/fission-relative-dwo-i386.exp: New file.
>         * gdb.dwarf2/fission-relative-dwo-aarch64.S: New file.
>         * gdb.dwarf2/fission-relative-dwo-aarch64.exp: New file.
>         * gdb.dwarf2/fission-relative-dwo-arm32.S: New file.
>         * gdb.dwarf2/fission-relative-dwo-arm32.exp: New file.
>
>
>
> On Wed, Mar 3, 2021 at 1:53 AM Andrew Burgess
> <andrew.burgess@embecosm.com> wrote:
> >
> > * Caroline Tice via Gdb-patches <gdb-patches@sourceware.org> [2021-03-02 16:42:08 -0800]:
> >
> > > DWARF allows .dwo file paths to be relative rather than absolute. When
> > > they are relative, DWARF uses DW_AT_comp_dir to find the .dwo file.
> > > DW_AT_comp_dir can also be relative, making the entire search patch
> > > for the .dwo file relative. In this case, GDB currently searches
> > > relative to its current working directory, i.e. the directory from
> > > which the debugger was launched, but not relative to the directory
> > > containing the built binary.  This cannot be right, as the compiler,
> > > when generating the relative paths, knows where it's building the
> > > binary but can have no idea where the debugger will be launched. The
> > > correct thing is to add the directory containing the binary to the
> > > search paths used for resolving relative locations of dwo files. That
> > > is what this patch does.
> > >
> > > I have run this through the regression testsuite with no regressions,
> > > and I have verified that my new testcase passes with
> > > this patch and fails without it.
> > >
> > > Is this patch OK to commit?
> > >
> > > -- Caroline Tice
> > > cmtice@google.com
> > >
> > > gdb/ChangeLog
> > >
> > > 2021-03-02  Caroline Tice  <cmtice@google.com>
> > >
> > >         * dwarf2/read.c (try_open_dwop_file): Add path for the binary
> > >         to the search paths used resolve relative location of .dwo file.
> > >
> > > gdb/testsuite/ChangeLog
> > >
> > > 2021-03-02  Caroline Tice <cmtice@google.com>
> > >
> > >         * gdb.dwarf2/fission-relative-dwo.c: New file.
> > >         * gdb.dwarf2/fission-relative-dwo.S: New file.
> > >         * gdb.dwarf2/fission-relative-dwo.exp: New file.
> >
> > > From 83056b931839107f131c0059377a011876df051b Mon Sep 17 00:00:00 2001
> > > From: Caroline Tice <cmtice@google.com>
> > > Date: Tue, 2 Mar 2021 16:15:54 -0800
> > > Subject: [PATCH] Add directory containing executable to relative search paths
> > >  for .dwo files.
> > >
> > > DWARF allows .dwo file paths to be relative rather than absolute. When
> > > they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
> > > file. DW_AT_comp_dir can also be relative, making the entire search
> > > patch for the .dwo file relative. In this case, GDB currently searches
> > > relative to its current working directory, i.e. the directory from
> > > which the debugger was launched, but not relative to the directory
> > > containing the built binary.  This cannot be right, as the compiler,
> > > which generating the relative paths, knows where it's building the
> > > binary but can have no idea where the debugger will be launched. The
> > > correct thing is to add the directory containing the binary to the
> > > search paths used for resolving relative locations of dwo files. That
> > > is what this patch does.
> > > ---
> > >  gdb/dwarf2/read.c                             |   6 +
> > >  .../gdb.dwarf2/fission-relative-dwo.S         | 407 ++++++++++++++++++
> > >  .../gdb.dwarf2/fission-relative-dwo.c         |  10 +
> > >  .../gdb.dwarf2/fission-relative-dwo.exp       |  52 +++
> > >  4 files changed, 475 insertions(+)
> > >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.S
> > >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > >
> > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> > > index d4f13229ced..7cac5027d41 100644
> > > --- a/gdb/dwarf2/read.c
> > > +++ b/gdb/dwarf2/read.c
> > > @@ -12809,6 +12809,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
> > >    else
> > >      search_path = debug_file_directory;
> > >
> > > +  /* Add the path for the executable binary to the list of search paths.  */
> > > +  search_path_holder.reset(
> > > +      concat(ldirname(per_objfile->objfile->original_name).c_str(),
> > > +          dirname_separator_string, search_path, (char *) NULL));
> > > +  search_path = search_path_holder.get();
> >
> > Missing whitespace before many of the '(' in this code.  Also I think
> > you should replace '(char *) NULL' with just 'nullptr'.
> >
> > > +
> > >    openp_flags flags = OPF_RETURN_REALPATH;
> > >    if (is_dwp)
> > >      flags |= OPF_SEARCH_IN_PATH;
> > > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > > new file mode 100644
> > > index 00000000000..4c5f0b88b0b
> > > --- /dev/null
> > > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > > @@ -0,0 +1,10 @@
> > > +
> > > +int main (int argc, char **argv)
> > > +{
> > > +  int x = 10;
> > > +  char y[3] = { 'a', 'b', 'c' };
> > > +
> > > +  x += (int) y[0] + (int) y[1];
> > > +
> > > +  return 0;
> > > +}
> >
> > Test source files should include a copyright header, and should follow
> > GNU/GDB coding standard, unless the deviation is critical for the test
> > (which is not the case here).
> >
> >
> > > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > > new file mode 100644
> > > index 00000000000..3d0b9b9fb5f
> > > --- /dev/null
> > > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > > @@ -0,0 +1,52 @@
> > > +# Copyright 2013-2021 Free Software Foundation, Inc.
> >
> > The from date should represent the first time you posted this patch to
> > the mailing list.  I didn't check to see if this patch was posted in
> > 2013.
> >
> > > +
> > > +# 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 .S
> > > +
> > > +set dwo [standard_output_file "fission-relative-dwo.dwo"]
> > > +
> > > +if [build_executable_from_fission_assembler \
> > > +     "$testfile.exp" "$binfile" "$srcfile" \
> > > +     [list nodebug additional_flags=-DDWO=$dwo]] {
> > > +    return -1
> > > +}
> >
> > Rather than using a fixed assembler file I would like to suggest you
> > write this test using GDB's DWARF assembler functionality.  This will
> > allow the test to run for any target, not just x86-64.
> >
> > It's certainly easy to set the DW_AT_comp_dir to any value you need
> > using that tool.  From your patch description I don't know what else
> > you would need to modify in the DWARF, maybe nothing?
> >
> > If you look for .exp files containing 'Dwarf::assemble' you'll find
> > loads of examples that you can draw inspiration from, but feel free to
> > ask if you have specific questions.
> >
> > > +
> > > +clean_restart $binfile
> > > +
> > > +if ![runto_main] {
> > > +    return -1
> > > +}
> > > +
> > > +# Verify gdb can find argc.
> > > +
> > > +gdb_test "p argc" " = 1"
> >
> > I guess you're looking for argc just to prove that GDB has found the
> > DWO file.
> >
> > If you switch to GDB's DWARF assembler then generating debug
> > information to find a local variable is harder.  I would suggest that
> > instead, you make the test file something like this:
> >
> >   int global_var;
> >
> >   int
> >   main (void)
> >   {
> >     asm ("main_label: .globl main_label");
> >     return 0;
> >   }
> >
> > Then in the generated DWARF give global_var a typedef type, your test
> > then becomes something like:
> >
> >   gdb_test "ptype global_var" "type = ....."
> >
> > Thanks,
> > Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-04 15:48   ` [PATCH, v2] " Caroline Tice
  2021-03-11 15:33     ` Caroline Tice
@ 2021-03-18  0:26     ` Andrew Burgess
       [not found]       ` <CABtf2+RmUPwpmsx+1i+a-QynhZKEpAib=EcFR4jDbr6PgH9t3g@mail.gmail.com>
  2021-03-25 15:09       ` Caroline Tice
  1 sibling, 2 replies; 17+ messages in thread
From: Andrew Burgess @ 2021-03-18  0:26 UTC (permalink / raw)
  To: Caroline Tice; +Cc: Caroline Tice via Gdb-patches

* Caroline Tice <cmtice@google.com> [2021-03-04 07:48:37 -0800]:

> Hi Andrew,
> 
> I updated my change to gdb/dwarf2/read.c as you suggested (spaces
> before '(' and use nullptr).
> 
> I spent a long time looking into using Dwarf::assemble in my testcase,
> to make it hardware agnostic (although I'd like to point out
> that most of the rest of the fission tests specifically only work for
> x86_64),

Most of these were written before the Dwarf assembler was available.
If they were being written today then we'd be using the Dwarf
assembler.

>           but in the end found that it would not work for me.   The
> problems that I was unable to make this work for was that I needed to
> generate not only the binary but the .dwo file; I needed reasonably
> valid DWARF in both of them; and the path name for the .dwo file had
> to be relative not absolute -- the way gdb compiles the test suites it
> always uses complete absolute paths for all of its files.

I don't understand what problem you ran into here.  The path to the
DWO file is encoded into the DWARF of the executable in a
DW_AT_GNU_dwo_name attribute, which would be entirely generated within
the .exp file, and so could contain whatever you like.  Likewise for
the DW_AT_comp_dir.

I made an attempt at writing a test using the dwarf assembler.  You
will need to start by applying this patch to a clean GDB tree:

   https://sourceware.org/pipermail/gdb-patches/2021-March/177049.html

Then grab the patch below and give it a try.  It includes your fix,
and a brand new test case.  Let me know if you don't think this is
covering your change correctly, I'm sure we can get it working as
needed.

Thanks,
Andrew

---

commit 47bf19a7ed4c96a86d67329efb7e5ce983debddd
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Wed Mar 17 22:54:22 2021 +0000

    gdb: handle relative paths to DWO files
    
    **** NOTE ****
    
    The fix in dwarf2/read.c includes a hack to allow the fix to be
    toggled on/off using environment variable GDB_NO_FIX.  This must be
    removed before pushing upstream.
    
    **** END NOTE ****
    
    DWARF allows .dwo file paths to be relative rather than absolute.
    
    When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
    file.  DW_AT_comp_dir can also be relative, making the entire search
    patch for the .dwo file relative.
    
    In this case, GDB currently searches relative to its current working
    directory, i.e. the directory from which the debugger was launched,
    but not relative to the directory containing the built binary.  This
    cannot be right, as the compiler, when generating the relative paths,
    knows where it's building the binary but can have no idea where the
    debugger will be launched.
    
    The correct thing is to add the directory containing the binary to the
    search paths used for resolving relative locations of dwo files. That
    is what this patch does.
    
    gdb/ChangeLog:
    
            * dwarf2/read.c (try_open_dwop_file): Add path for the binary to
            the search paths used resolve relative location of .dwo file.
    
    gdb/testsuite/ChangeLog:
    
            * gdb.dwarf2/fission-relative-dwo.c: New file.
            * gdb.dwarf2/fission-relative-dwo.exp: New file.
            * lib/dwarf.exp (extract_dwo_information): New proc.
            (strip_dwo_information): New proc.
            (build_executable_from_fission_assembler): Use
            extract_dwo_information and strip_dwo_information.
            (Dwarf::_debug_addr_index): New variable.
            (Dwarf::_cu_is_fission): New variable.
            (Dwarf::_handle_DW_FORM): Handle DW_OP_GNU_addr_index.
            (Dwarf::_default_form): Supply a default for DW_AT_GNU_addr_base.
            (Dwarf::_handle_macro_at_range): Use form DW_FORM_GNU_addr_index
            if this is a fission CU.
            (Dwarf::_location): Handle DW_OP_GNU_addr_index.
            (Dwarf::debug_addr_index): New proc.
            (Dwarf::cu): Initialise _cu_is_fission.
            (Dwarf::tu): Likewise.
            (Dwarf::assemble): Initialise _debug_addr_index.

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d6881300fa6..522ccc2506e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12581,6 +12581,15 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
   else
     search_path = debug_file_directory;
 
+  if (getenv ("GDB_NO_FIX") == nullptr)
+    {
+      /* Add the path for the executable binary to the list of search paths.  */
+      search_path_holder.reset
+	(concat (ldirname (per_objfile->objfile->original_name).c_str (),
+		 dirname_separator_string, search_path, nullptr));
+      search_path = search_path_holder.get ();
+    }
+
   openp_flags flags = OPF_RETURN_REALPATH;
   if (is_dwp)
     flags |= OPF_SEARCH_IN_PATH;
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
new file mode 100644
index 00000000000..27f7f0dfb4b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   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/>.  */
+
+/* Our fake object.  */
+int global_var[100];
+
+int
+main (int argc, char **argv)
+{
+  asm ("main_label: .globl main_label");
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
new file mode 100644
index 00000000000..f9ab3b8c6a4
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
@@ -0,0 +1,145 @@
+# 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/>.
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+standard_testfile .c -dw.S
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    global srcfile gdb_test_file_name
+
+    set debug_addr_base -1
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture the current index into .debug_addr so we can fill in
+	# DW_AT_GNU_addr_base later.
+	set debug_addr_base [debug_addr_index]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir .}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+        } {
+	    declare_labels int4_type struct_type
+
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      integer}
+	    }
+
+	    struct_type: DW_TAG_structure_type {
+		{DW_AT_name "foo_t"}
+		{DW_AT_byte_size 12 DW_FORM_sdata}
+	    } {
+		member {
+		    {name "aa"}
+		    {type :$int4_type}
+		    {data_member_location 0 data1}
+		}
+		member {
+		    {name "bb"}
+		    {type :$int4_type}
+		    {data_member_location 4 data1}
+		}
+		member {
+		    {name "cc"}
+		    {type :$int4_type}
+		    {data_member_location 8 data1}
+		}
+	    }
+
+	    DW_TAG_variable {
+		{DW_AT_name global_var}
+		{DW_AT_type :$struct_type}
+		{DW_AT_location {
+		    DW_OP_GNU_addr_index [gdb_target_symbol global_var]
+		} SPECIAL_expr}
+		{external 1 flag}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name main DW_FORM_string}
+		{MACRO_AT_func {main}}
+	    }
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${gdb_test_file_name}.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir .}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_base}
+        } {
+	    # Nothing.
+	}
+    }
+}
+
+# Assemble the file containing the .dwo information, we can then split
+# this out into a separate .dwo file.  Once we've extracted the DWO
+# information from this object file we're done with it, we recompile
+# this again in the BUILD_EXECUTABLE call below.
+set object_file [standard_output_file ${binfile}-dwo.o]
+if { [gdb_compile $asm_file $object_file object {nodebug}] != "" } {
+    return -1
+}
+
+# Split out the dwo sections into a dwo file.
+if { [extract_dwo_information $object_file ${binfile}.dwo] == -1 } {
+    perror "failed to extract dwo information"
+    return -1
+}
+
+# Build the executable, but don't use prepare_for_testing as we don't
+# want to start GDB just yet.
+if { [build_executable "failed to prepare" "${testfile}" \
+	  [list $srcfile $asm_file] {nodebug}] } {
+    return -1
+}
+
+# Just so we can't be found cheating, strip all the dwo information
+# from the executable.
+if { [strip_dwo_information ${binfile}] == -1 } {
+    perror "failed to strip dwo information"
+    return -1
+}
+
+# Now we can start GDB.
+clean_restart ${testfile}
+
+if ![runto_main] {
+    return -1
+}
+
+# Print the type of global_var.  This type information is entirely
+# fictional, it only exists in the DWARF.  If we don't have the DWARF
+# information then there's no way we can print this.
+gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 4cd5e16c604..a41366f1747 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -28,6 +28,38 @@ proc dwarf2_support {} {
     return 0
 }
 
+# Use 'objcopy --extract-dwo to extract DWO information from
+# OBJECT_FILE and place it into DWO_FILE.
+#
+# Return 0 on success, otherwise, return -1.
+proc extract_dwo_information { object_file dwo_file } {
+    set objcopy [gdb_find_objcopy]
+    set command "$objcopy --extract-dwo $object_file $dwo_file"
+    verbose -log "Executing $command"
+    set result [catch "exec $command" output]
+    verbose -log "objcopy --extract-dwo output: $output"
+    if { $result == 1 } {
+	return -1
+    }
+    return 0
+}
+
+# Use 'objcopy --strip-dwo to remove DWO information from
+# FILENAME.
+#
+# Return 0 on success, otherwise, return -1.
+proc strip_dwo_information { filename } {
+   set objcopy [gdb_find_objcopy]
+    set command "$objcopy --strip-dwo $filename"
+    verbose -log "Executing $command"
+    set result [catch "exec $command" output]
+    verbose -log "objcopy --strip-dwo output: $output"
+    if { $result == 1 } {
+	return -1
+    }
+    return 0
+}
+
 # Build an executable from a fission-based .S file.
 # This handles the extra work of splitting the .o into non-dwo and dwo
 # pieces, making sure the .dwo is available if we're using cc-with-tweaks.sh
@@ -54,26 +86,17 @@ proc build_executable_from_fission_assembler { testname executable sources optio
     set object_file ${output_base}.o
     set dwo_file ${output_base}.dwo
     set object_options "object $options"
-    set objcopy [gdb_find_objcopy]
 
     set result [gdb_compile $source_file $object_file object $options]
     if { "$result" != "" } {
 	return -1
     }
 
-    set command "$objcopy --extract-dwo $object_file $dwo_file"
-    verbose -log "Executing $command"
-    set result [catch "exec $command" output]
-    verbose -log "objcopy --extract-dwo output: $output"
-    if { $result == 1 } {
+    if { [extract_dwo_information $object_file $dwo_file] == -1 } {
 	return -1
     }
 
-    set command "$objcopy --strip-dwo $object_file"
-    verbose -log "Executing $command"
-    set result [catch "exec $command" output]
-    verbose -log "objcopy --strip-dwo output: $output"
-    if { $result == 1 } {
+    if { [strip_dwo_information $object_file] == -1 } {
 	return -1
     }
 
@@ -329,6 +352,14 @@ namespace eval Dwarf {
     # The address size for debug ranges section.
     variable _debug_ranges_64_bit
 
+    # The index into the .debug_addr section (used for fission
+    # generation).
+    variable _debug_addr_index
+
+    # Flag, true if the current CU is contains fission information,
+    # otherwise false.
+    variable _cu_is_fission
+
     proc _process_one_constant {name value} {
 	variable _constants
 	variable _AT
@@ -486,6 +517,18 @@ namespace eval Dwarf {
 		_op .${_cu_addr_size}byte $value
 	    }
 
+	    DW_FORM_GNU_addr_index {
+		variable _debug_addr_index
+		variable _cu_addr_size
+
+		_op .uleb128 ${_debug_addr_index}
+		incr _debug_addr_index
+
+		_defer_output .debug_addr {
+		    _op .${_cu_addr_size}byte $value
+		}
+	    }
+
 	    DW_FORM_data2 -
 	    DW_FORM_ref2 {
 		_op .2byte $value
@@ -553,7 +596,6 @@ namespace eval Dwarf {
 	    DW_FORM_strx3 -
 	    DW_FORM_strx4 -
 
-	    DW_FORM_GNU_addr_index -
 	    DW_FORM_GNU_str_index -
 
 	    default {
@@ -609,6 +651,9 @@ namespace eval Dwarf {
 	    DW_AT_name {
 		return DW_FORM_string
 	    }
+	    DW_AT_GNU_addr_base {
+		return DW_FORM_sec_offset
+	    }
 	}
 	return ""
     }
@@ -649,6 +694,8 @@ namespace eval Dwarf {
     # Handle macro attribute MACRO_AT_range.
 
     proc _handle_macro_at_range { attr_value } {
+	variable _cu_is_fission
+
 	if {[llength $attr_value] != 1} {
 	    error "usage: MACRO_AT_range { func }"
 	}
@@ -658,10 +705,14 @@ namespace eval Dwarf {
 	set src ${srcdir}/${subdir}/${srcfile}
 	set result [function_range $func $src]
 
-	_handle_attribute DW_AT_low_pc [lindex $result 0] \
-	    DW_FORM_addr
+	set form DW_FORM_addr
+	if { $_cu_is_fission } {
+	    set form DW_FORM_GNU_addr_index
+	}
+
+	_handle_attribute DW_AT_low_pc [lindex $result 0] $form
 	_handle_attribute DW_AT_high_pc \
-	    "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
+	    "[lindex $result 0] + [lindex $result 1]" $form
     }
 
     # Handle macro attribute MACRO_AT_func.
@@ -929,6 +980,18 @@ namespace eval Dwarf {
 		    _op .${addr_size}byte [lindex $line 1]
 		}
 
+		DW_OP_GNU_addr_index {
+		    variable _debug_addr_index
+		    variable _cu_addr_size
+
+		    _op .uleb128 ${_debug_addr_index}
+		    incr _debug_addr_index
+
+		    _defer_output .debug_addr {
+			_op .${_cu_addr_size}byte [lindex $line 1]
+		    }
+		}
+
 		DW_OP_regx {
 		    _op .uleb128 [lindex $line 1]
 		}
@@ -1050,6 +1113,14 @@ namespace eval Dwarf {
 	}
     }
 
+    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
+    # of this function can be used for the value of
+    # DW_AT_GNU_addr_base.
+    proc debug_addr_index {} {
+	variable _debug_addr_index
+	return ${_debug_addr_index}
+    }
+
     # Emit a DWARF CU.
     # OPTIONS is a list with an even number of elements containing
     # option-name and option-value pairs.
@@ -1073,12 +1144,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_info"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1088,7 +1160,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1100,7 +1172,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_info.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -1180,12 +1252,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_types"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1194,7 +1267,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1206,7 +1279,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_types.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -2056,6 +2129,7 @@ namespace eval Dwarf {
 	variable _line_saw_program
 	variable _line_header_end_label
 	variable _debug_ranges_64_bit
+	variable _debug_addr_index
 
 	if {!$_initialized} {
 	    _read_constants
@@ -2074,6 +2148,8 @@ namespace eval Dwarf {
 	set _line_saw_program 0
 	set _debug_ranges_64_bit [is_64_target]
 
+	set _debug_addr_index 0
+
 	# Not "uplevel" here, because we want to evaluate in this
 	# namespace.  This is somewhat bad because it means we can't
 	# readily refer to outer variables.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
       [not found]       ` <CABtf2+RmUPwpmsx+1i+a-QynhZKEpAib=EcFR4jDbr6PgH9t3g@mail.gmail.com>
@ 2021-03-21  2:33         ` Caroline Tice
  0 siblings, 0 replies; 17+ messages in thread
From: Caroline Tice @ 2021-03-21  2:33 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Caroline Tice via Gdb-patches

+ gdb-patches list (somehow got dropped from this thread)


On Thu, Mar 18, 2021 at 11:02 AM Caroline Tice <cmtice@google.com> wrote:
>
> Hi Andrew,
>
> Thank you so much!  I really tried to make it work with the dwarf assembler but I couldn't figure out how to do it.  Your patch works exactly right.  I did have some trouble applying it: even after applying the other patch that you said to apply first, the second patch did not apply cleanly for me.  But I was able to apply it via hand edits, then built GDB & ran the test.  I double-checked with dwarfdump to make sure the DWARF was correct for the relative tests: the DWARF was correct and the test passed.
>
> So at this point, what do you want me to do about submitting the patch.  Should I submit it with your changes and attribute it to you?  Or do you want to submit it yourself directly?
>
> -- Caroline
> cmtice@google.com
>
>
> On Wed, Mar 17, 2021 at 5:26 PM Andrew Burgess <andrew.burgess@embecosm.com> wrote:
>>
>> * Caroline Tice <cmtice@google.com> [2021-03-04 07:48:37 -0800]:
>>
>> > Hi Andrew,
>> >
>> > I updated my change to gdb/dwarf2/read.c as you suggested (spaces
>> > before '(' and use nullptr).
>> >
>> > I spent a long time looking into using Dwarf::assemble in my testcase,
>> > to make it hardware agnostic (although I'd like to point out
>> > that most of the rest of the fission tests specifically only work for
>> > x86_64),
>>
>> Most of these were written before the Dwarf assembler was available.
>> If they were being written today then we'd be using the Dwarf
>> assembler.
>>
>> >           but in the end found that it would not work for me.   The
>> > problems that I was unable to make this work for was that I needed to
>> > generate not only the binary but the .dwo file; I needed reasonably
>> > valid DWARF in both of them; and the path name for the .dwo file had
>> > to be relative not absolute -- the way gdb compiles the test suites it
>> > always uses complete absolute paths for all of its files.
>>
>> I don't understand what problem you ran into here.  The path to the
>> DWO file is encoded into the DWARF of the executable in a
>> DW_AT_GNU_dwo_name attribute, which would be entirely generated within
>> the .exp file, and so could contain whatever you like.  Likewise for
>> the DW_AT_comp_dir.
>>
>> I made an attempt at writing a test using the dwarf assembler.  You
>> will need to start by applying this patch to a clean GDB tree:
>>
>>    https://sourceware.org/pipermail/gdb-patches/2021-March/177049.html
>>
>> Then grab the patch below and give it a try.  It includes your fix,
>> and a brand new test case.  Let me know if you don't think this is
>> covering your change correctly, I'm sure we can get it working as
>> needed.
>>
>> Thanks,
>> Andrew
>>
>> ---
>>
>> commit 47bf19a7ed4c96a86d67329efb7e5ce983debddd
>> Author: Andrew Burgess <andrew.burgess@embecosm.com>
>> Date:   Wed Mar 17 22:54:22 2021 +0000
>>
>>     gdb: handle relative paths to DWO files
>>
>>     **** NOTE ****
>>
>>     The fix in dwarf2/read.c includes a hack to allow the fix to be
>>     toggled on/off using environment variable GDB_NO_FIX.  This must be
>>     removed before pushing upstream.
>>
>>     **** END NOTE ****
>>
>>     DWARF allows .dwo file paths to be relative rather than absolute.
>>
>>     When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
>>     file.  DW_AT_comp_dir can also be relative, making the entire search
>>     patch for the .dwo file relative.
>>
>>     In this case, GDB currently searches relative to its current working
>>     directory, i.e. the directory from which the debugger was launched,
>>     but not relative to the directory containing the built binary.  This
>>     cannot be right, as the compiler, when generating the relative paths,
>>     knows where it's building the binary but can have no idea where the
>>     debugger will be launched.
>>
>>     The correct thing is to add the directory containing the binary to the
>>     search paths used for resolving relative locations of dwo files. That
>>     is what this patch does.
>>
>>     gdb/ChangeLog:
>>
>>             * dwarf2/read.c (try_open_dwop_file): Add path for the binary to
>>             the search paths used resolve relative location of .dwo file.
>>
>>     gdb/testsuite/ChangeLog:
>>
>>             * gdb.dwarf2/fission-relative-dwo.c: New file.
>>             * gdb.dwarf2/fission-relative-dwo.exp: New file.
>>             * lib/dwarf.exp (extract_dwo_information): New proc.
>>             (strip_dwo_information): New proc.
>>             (build_executable_from_fission_assembler): Use
>>             extract_dwo_information and strip_dwo_information.
>>             (Dwarf::_debug_addr_index): New variable.
>>             (Dwarf::_cu_is_fission): New variable.
>>             (Dwarf::_handle_DW_FORM): Handle DW_OP_GNU_addr_index.
>>             (Dwarf::_default_form): Supply a default for DW_AT_GNU_addr_base.
>>             (Dwarf::_handle_macro_at_range): Use form DW_FORM_GNU_addr_index
>>             if this is a fission CU.
>>             (Dwarf::_location): Handle DW_OP_GNU_addr_index.
>>             (Dwarf::debug_addr_index): New proc.
>>             (Dwarf::cu): Initialise _cu_is_fission.
>>             (Dwarf::tu): Likewise.
>>             (Dwarf::assemble): Initialise _debug_addr_index.
>>
>> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
>> index d6881300fa6..522ccc2506e 100644
>> --- a/gdb/dwarf2/read.c
>> +++ b/gdb/dwarf2/read.c
>> @@ -12581,6 +12581,15 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
>>    else
>>      search_path = debug_file_directory;
>>
>> +  if (getenv ("GDB_NO_FIX") == nullptr)
>> +    {
>> +      /* Add the path for the executable binary to the list of search paths.  */
>> +      search_path_holder.reset
>> +       (concat (ldirname (per_objfile->objfile->original_name).c_str (),
>> +                dirname_separator_string, search_path, nullptr));
>> +      search_path = search_path_holder.get ();
>> +    }
>> +
>>    openp_flags flags = OPF_RETURN_REALPATH;
>>    if (is_dwp)
>>      flags |= OPF_SEARCH_IN_PATH;
>> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
>> new file mode 100644
>> index 00000000000..27f7f0dfb4b
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
>> @@ -0,0 +1,28 @@
>> +/* This testcase is part of GDB, the GNU debugger.
>> +
>> +   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/>.  */
>> +
>> +/* Our fake object.  */
>> +int global_var[100];
>> +
>> +int
>> +main (int argc, char **argv)
>> +{
>> +  asm ("main_label: .globl main_label");
>> +
>> +  return 0;
>> +}
>> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
>> new file mode 100644
>> index 00000000000..f9ab3b8c6a4
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
>> @@ -0,0 +1,145 @@
>> +# 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/>.
>> +load_lib dwarf.exp
>> +
>> +# This test can only be run on targets which support DWARF-2 and use gas.
>> +if {![dwarf2_support]} {
>> +    return 0
>> +}
>> +
>> +standard_testfile .c -dw.S
>> +
>> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
>> +    return -1
>> +}
>> +
>> +set asm_file [standard_output_file $srcfile2]
>> +Dwarf::assemble $asm_file {
>> +    global srcfile gdb_test_file_name
>> +
>> +    set debug_addr_base -1
>> +
>> +    # The information that will be split out into the .dwo file.
>> +    cu {fission 1} {
>> +
>> +       # Capture the current index into .debug_addr so we can fill in
>> +       # DW_AT_GNU_addr_base later.
>> +       set debug_addr_base [debug_addr_index]
>> +
>> +       compile_unit {
>> +            {language @DW_LANG_C}
>> +            {name ${srcfile}}
>> +           {DW_AT_comp_dir .}
>> +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
>> +        } {
>> +           declare_labels int4_type struct_type
>> +
>> +           int4_type: DW_TAG_base_type {
>> +               {DW_AT_byte_size 4 DW_FORM_sdata}
>> +               {DW_AT_encoding  @DW_ATE_signed}
>> +               {DW_AT_name      integer}
>> +           }
>> +
>> +           struct_type: DW_TAG_structure_type {
>> +               {DW_AT_name "foo_t"}
>> +               {DW_AT_byte_size 12 DW_FORM_sdata}
>> +           } {
>> +               member {
>> +                   {name "aa"}
>> +                   {type :$int4_type}
>> +                   {data_member_location 0 data1}
>> +               }
>> +               member {
>> +                   {name "bb"}
>> +                   {type :$int4_type}
>> +                   {data_member_location 4 data1}
>> +               }
>> +               member {
>> +                   {name "cc"}
>> +                   {type :$int4_type}
>> +                   {data_member_location 8 data1}
>> +               }
>> +           }
>> +
>> +           DW_TAG_variable {
>> +               {DW_AT_name global_var}
>> +               {DW_AT_type :$struct_type}
>> +               {DW_AT_location {
>> +                   DW_OP_GNU_addr_index [gdb_target_symbol global_var]
>> +               } SPECIAL_expr}
>> +               {external 1 flag}
>> +           }
>> +
>> +           subprogram {
>> +               {external 1 flag}
>> +               {DW_AT_name main DW_FORM_string}
>> +               {MACRO_AT_func {main}}
>> +           }
>> +       }
>> +    }
>> +
>> +    # The information that will remain in the .o file.
>> +    cu {} {
>> +       compile_unit {
>> +            {DW_AT_GNU_dwo_name ${gdb_test_file_name}.dwo DW_FORM_strp}
>> +           {DW_AT_comp_dir .}
>> +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
>> +           {DW_AT_GNU_addr_base $debug_addr_base}
>> +        } {
>> +           # Nothing.
>> +       }
>> +    }
>> +}
>> +
>> +# Assemble the file containing the .dwo information, we can then split
>> +# this out into a separate .dwo file.  Once we've extracted the DWO
>> +# information from this object file we're done with it, we recompile
>> +# this again in the BUILD_EXECUTABLE call below.
>> +set object_file [standard_output_file ${binfile}-dwo.o]
>> +if { [gdb_compile $asm_file $object_file object {nodebug}] != "" } {
>> +    return -1
>> +}
>> +
>> +# Split out the dwo sections into a dwo file.
>> +if { [extract_dwo_information $object_file ${binfile}.dwo] == -1 } {
>> +    perror "failed to extract dwo information"
>> +    return -1
>> +}
>> +
>> +# Build the executable, but don't use prepare_for_testing as we don't
>> +# want to start GDB just yet.
>> +if { [build_executable "failed to prepare" "${testfile}" \
>> +         [list $srcfile $asm_file] {nodebug}] } {
>> +    return -1
>> +}
>> +
>> +# Just so we can't be found cheating, strip all the dwo information
>> +# from the executable.
>> +if { [strip_dwo_information ${binfile}] == -1 } {
>> +    perror "failed to strip dwo information"
>> +    return -1
>> +}
>> +
>> +# Now we can start GDB.
>> +clean_restart ${testfile}
>> +
>> +if ![runto_main] {
>> +    return -1
>> +}
>> +
>> +# Print the type of global_var.  This type information is entirely
>> +# fictional, it only exists in the DWARF.  If we don't have the DWARF
>> +# information then there's no way we can print this.
>> +gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
>> diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
>> index 4cd5e16c604..a41366f1747 100644
>> --- a/gdb/testsuite/lib/dwarf.exp
>> +++ b/gdb/testsuite/lib/dwarf.exp
>> @@ -28,6 +28,38 @@ proc dwarf2_support {} {
>>      return 0
>>  }
>>
>> +# Use 'objcopy --extract-dwo to extract DWO information from
>> +# OBJECT_FILE and place it into DWO_FILE.
>> +#
>> +# Return 0 on success, otherwise, return -1.
>> +proc extract_dwo_information { object_file dwo_file } {
>> +    set objcopy [gdb_find_objcopy]
>> +    set command "$objcopy --extract-dwo $object_file $dwo_file"
>> +    verbose -log "Executing $command"
>> +    set result [catch "exec $command" output]
>> +    verbose -log "objcopy --extract-dwo output: $output"
>> +    if { $result == 1 } {
>> +       return -1
>> +    }
>> +    return 0
>> +}
>> +
>> +# Use 'objcopy --strip-dwo to remove DWO information from
>> +# FILENAME.
>> +#
>> +# Return 0 on success, otherwise, return -1.
>> +proc strip_dwo_information { filename } {
>> +   set objcopy [gdb_find_objcopy]
>> +    set command "$objcopy --strip-dwo $filename"
>> +    verbose -log "Executing $command"
>> +    set result [catch "exec $command" output]
>> +    verbose -log "objcopy --strip-dwo output: $output"
>> +    if { $result == 1 } {
>> +       return -1
>> +    }
>> +    return 0
>> +}
>> +
>>  # Build an executable from a fission-based .S file.
>>  # This handles the extra work of splitting the .o into non-dwo and dwo
>>  # pieces, making sure the .dwo is available if we're using cc-with-tweaks.sh
>> @@ -54,26 +86,17 @@ proc build_executable_from_fission_assembler { testname executable sources optio
>>      set object_file ${output_base}.o
>>      set dwo_file ${output_base}.dwo
>>      set object_options "object $options"
>> -    set objcopy [gdb_find_objcopy]
>>
>>      set result [gdb_compile $source_file $object_file object $options]
>>      if { "$result" != "" } {
>>         return -1
>>      }
>>
>> -    set command "$objcopy --extract-dwo $object_file $dwo_file"
>> -    verbose -log "Executing $command"
>> -    set result [catch "exec $command" output]
>> -    verbose -log "objcopy --extract-dwo output: $output"
>> -    if { $result == 1 } {
>> +    if { [extract_dwo_information $object_file $dwo_file] == -1 } {
>>         return -1
>>      }
>>
>> -    set command "$objcopy --strip-dwo $object_file"
>> -    verbose -log "Executing $command"
>> -    set result [catch "exec $command" output]
>> -    verbose -log "objcopy --strip-dwo output: $output"
>> -    if { $result == 1 } {
>> +    if { [strip_dwo_information $object_file] == -1 } {
>>         return -1
>>      }
>>
>> @@ -329,6 +352,14 @@ namespace eval Dwarf {
>>      # The address size for debug ranges section.
>>      variable _debug_ranges_64_bit
>>
>> +    # The index into the .debug_addr section (used for fission
>> +    # generation).
>> +    variable _debug_addr_index
>> +
>> +    # Flag, true if the current CU is contains fission information,
>> +    # otherwise false.
>> +    variable _cu_is_fission
>> +
>>      proc _process_one_constant {name value} {
>>         variable _constants
>>         variable _AT
>> @@ -486,6 +517,18 @@ namespace eval Dwarf {
>>                 _op .${_cu_addr_size}byte $value
>>             }
>>
>> +           DW_FORM_GNU_addr_index {
>> +               variable _debug_addr_index
>> +               variable _cu_addr_size
>> +
>> +               _op .uleb128 ${_debug_addr_index}
>> +               incr _debug_addr_index
>> +
>> +               _defer_output .debug_addr {
>> +                   _op .${_cu_addr_size}byte $value
>> +               }
>> +           }
>> +
>>             DW_FORM_data2 -
>>             DW_FORM_ref2 {
>>                 _op .2byte $value
>> @@ -553,7 +596,6 @@ namespace eval Dwarf {
>>             DW_FORM_strx3 -
>>             DW_FORM_strx4 -
>>
>> -           DW_FORM_GNU_addr_index -
>>             DW_FORM_GNU_str_index -
>>
>>             default {
>> @@ -609,6 +651,9 @@ namespace eval Dwarf {
>>             DW_AT_name {
>>                 return DW_FORM_string
>>             }
>> +           DW_AT_GNU_addr_base {
>> +               return DW_FORM_sec_offset
>> +           }
>>         }
>>         return ""
>>      }
>> @@ -649,6 +694,8 @@ namespace eval Dwarf {
>>      # Handle macro attribute MACRO_AT_range.
>>
>>      proc _handle_macro_at_range { attr_value } {
>> +       variable _cu_is_fission
>> +
>>         if {[llength $attr_value] != 1} {
>>             error "usage: MACRO_AT_range { func }"
>>         }
>> @@ -658,10 +705,14 @@ namespace eval Dwarf {
>>         set src ${srcdir}/${subdir}/${srcfile}
>>         set result [function_range $func $src]
>>
>> -       _handle_attribute DW_AT_low_pc [lindex $result 0] \
>> -           DW_FORM_addr
>> +       set form DW_FORM_addr
>> +       if { $_cu_is_fission } {
>> +           set form DW_FORM_GNU_addr_index
>> +       }
>> +
>> +       _handle_attribute DW_AT_low_pc [lindex $result 0] $form
>>         _handle_attribute DW_AT_high_pc \
>> -           "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
>> +           "[lindex $result 0] + [lindex $result 1]" $form
>>      }
>>
>>      # Handle macro attribute MACRO_AT_func.
>> @@ -929,6 +980,18 @@ namespace eval Dwarf {
>>                     _op .${addr_size}byte [lindex $line 1]
>>                 }
>>
>> +               DW_OP_GNU_addr_index {
>> +                   variable _debug_addr_index
>> +                   variable _cu_addr_size
>> +
>> +                   _op .uleb128 ${_debug_addr_index}
>> +                   incr _debug_addr_index
>> +
>> +                   _defer_output .debug_addr {
>> +                       _op .${_cu_addr_size}byte [lindex $line 1]
>> +                   }
>> +               }
>> +
>>                 DW_OP_regx {
>>                     _op .uleb128 [lindex $line 1]
>>                 }
>> @@ -1050,6 +1113,14 @@ namespace eval Dwarf {
>>         }
>>      }
>>
>> +    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
>> +    # of this function can be used for the value of
>> +    # DW_AT_GNU_addr_base.
>> +    proc debug_addr_index {} {
>> +       variable _debug_addr_index
>> +       return ${_debug_addr_index}
>> +    }
>> +
>>      # Emit a DWARF CU.
>>      # OPTIONS is a list with an even number of elements containing
>>      # option-name and option-value pairs.
>> @@ -1073,12 +1144,13 @@ namespace eval Dwarf {
>>         variable _cu_version
>>         variable _cu_addr_size
>>         variable _cu_offset_size
>> +       variable _cu_is_fission
>>
>>         # Establish the defaults.
>>         set is_64 0
>>         set _cu_version 4
>>         set _cu_addr_size default
>> -       set fission 0
>> +       set _cu_is_fission 0
>>         set section ".debug_info"
>>         set _abbrev_section ".debug_abbrev"
>>
>> @@ -1088,7 +1160,7 @@ namespace eval Dwarf {
>>                 is_64 { set is_64 $value }
>>                 version { set _cu_version $value }
>>                 addr_size { set _cu_addr_size $value }
>> -               fission { set fission $value }
>> +               fission { set _cu_is_fission $value }
>>                 default { error "unknown option $name" }
>>             }
>>         }
>> @@ -1100,7 +1172,7 @@ namespace eval Dwarf {
>>             }
>>         }
>>         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
>> -       if { $fission } {
>> +       if { $_cu_is_fission } {
>>             set section ".debug_info.dwo"
>>             set _abbrev_section ".debug_abbrev.dwo"
>>         }
>> @@ -1180,12 +1252,13 @@ namespace eval Dwarf {
>>         variable _cu_version
>>         variable _cu_addr_size
>>         variable _cu_offset_size
>> +       variable _cu_is_fission
>>
>>         # Establish the defaults.
>>         set is_64 0
>>         set _cu_version 4
>>         set _cu_addr_size default
>> -       set fission 0
>> +       set _cu_is_fission 0
>>         set section ".debug_types"
>>         set _abbrev_section ".debug_abbrev"
>>
>> @@ -1194,7 +1267,7 @@ namespace eval Dwarf {
>>                 is_64 { set is_64 $value }
>>                 version { set _cu_version $value }
>>                 addr_size { set _cu_addr_size $value }
>> -               fission { set fission $value }
>> +               fission { set _cu_is_fission $value }
>>                 default { error "unknown option $name" }
>>             }
>>         }
>> @@ -1206,7 +1279,7 @@ namespace eval Dwarf {
>>             }
>>         }
>>         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
>> -       if { $fission } {
>> +       if { $_cu_is_fission } {
>>             set section ".debug_types.dwo"
>>             set _abbrev_section ".debug_abbrev.dwo"
>>         }
>> @@ -2056,6 +2129,7 @@ namespace eval Dwarf {
>>         variable _line_saw_program
>>         variable _line_header_end_label
>>         variable _debug_ranges_64_bit
>> +       variable _debug_addr_index
>>
>>         if {!$_initialized} {
>>             _read_constants
>> @@ -2074,6 +2148,8 @@ namespace eval Dwarf {
>>         set _line_saw_program 0
>>         set _debug_ranges_64_bit [is_64_target]
>>
>> +       set _debug_addr_index 0
>> +
>>         # Not "uplevel" here, because we want to evaluate in this
>>         # namespace.  This is somewhat bad because it means we can't
>>         # readily refer to outer variables.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-18  0:26     ` Andrew Burgess
       [not found]       ` <CABtf2+RmUPwpmsx+1i+a-QynhZKEpAib=EcFR4jDbr6PgH9t3g@mail.gmail.com>
@ 2021-03-25 15:09       ` Caroline Tice
  2021-03-25 17:46         ` Andrew Burgess
  1 sibling, 1 reply; 17+ messages in thread
From: Caroline Tice @ 2021-03-25 15:09 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Caroline Tice via Gdb-patches

Hi Andrew,

As I said previously, your suggested patch works well and fixes the
problem.  I thought you were going to submit it, but I have not seen it  go
out for review or be committed.  Is there something else you need me to
do?  I would be happy to send your version for review if you would like?

-- Caroline
cmtice@google.com


On Wed, Mar 17, 2021 at 5:26 PM Andrew Burgess <andrew.burgess@embecosm.com>
wrote:

> * Caroline Tice <cmtice@google.com> [2021-03-04 07:48:37 -0800]:
>
> > Hi Andrew,
> >
> > I updated my change to gdb/dwarf2/read.c as you suggested (spaces
> > before '(' and use nullptr).
> >
> > I spent a long time looking into using Dwarf::assemble in my testcase,
> > to make it hardware agnostic (although I'd like to point out
> > that most of the rest of the fission tests specifically only work for
> > x86_64),
>
> Most of these were written before the Dwarf assembler was available.
> If they were being written today then we'd be using the Dwarf
> assembler.
>
> >           but in the end found that it would not work for me.   The
> > problems that I was unable to make this work for was that I needed to
> > generate not only the binary but the .dwo file; I needed reasonably
> > valid DWARF in both of them; and the path name for the .dwo file had
> > to be relative not absolute -- the way gdb compiles the test suites it
> > always uses complete absolute paths for all of its files.
>
> I don't understand what problem you ran into here.  The path to the
> DWO file is encoded into the DWARF of the executable in a
> DW_AT_GNU_dwo_name attribute, which would be entirely generated within
> the .exp file, and so could contain whatever you like.  Likewise for
> the DW_AT_comp_dir.
>
> I made an attempt at writing a test using the dwarf assembler.  You
> will need to start by applying this patch to a clean GDB tree:
>
>    https://sourceware.org/pipermail/gdb-patches/2021-March/177049.html
>
> Then grab the patch below and give it a try.  It includes your fix,
> and a brand new test case.  Let me know if you don't think this is
> covering your change correctly, I'm sure we can get it working as
> needed.
>
> Thanks,
> Andrew
>
> ---
>
> commit 47bf19a7ed4c96a86d67329efb7e5ce983debddd
> Author: Andrew Burgess <andrew.burgess@embecosm.com>
> Date:   Wed Mar 17 22:54:22 2021 +0000
>
>     gdb: handle relative paths to DWO files
>
>     **** NOTE ****
>
>     The fix in dwarf2/read.c includes a hack to allow the fix to be
>     toggled on/off using environment variable GDB_NO_FIX.  This must be
>     removed before pushing upstream.
>
>     **** END NOTE ****
>
>     DWARF allows .dwo file paths to be relative rather than absolute.
>
>     When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
>     file.  DW_AT_comp_dir can also be relative, making the entire search
>     patch for the .dwo file relative.
>
>     In this case, GDB currently searches relative to its current working
>     directory, i.e. the directory from which the debugger was launched,
>     but not relative to the directory containing the built binary.  This
>     cannot be right, as the compiler, when generating the relative paths,
>     knows where it's building the binary but can have no idea where the
>     debugger will be launched.
>
>     The correct thing is to add the directory containing the binary to the
>     search paths used for resolving relative locations of dwo files. That
>     is what this patch does.
>
>     gdb/ChangeLog:
>
>             * dwarf2/read.c (try_open_dwop_file): Add path for the binary
> to
>             the search paths used resolve relative location of .dwo file.
>
>     gdb/testsuite/ChangeLog:
>
>             * gdb.dwarf2/fission-relative-dwo.c: New file.
>             * gdb.dwarf2/fission-relative-dwo.exp: New file.
>             * lib/dwarf.exp (extract_dwo_information): New proc.
>             (strip_dwo_information): New proc.
>             (build_executable_from_fission_assembler): Use
>             extract_dwo_information and strip_dwo_information.
>             (Dwarf::_debug_addr_index): New variable.
>             (Dwarf::_cu_is_fission): New variable.
>             (Dwarf::_handle_DW_FORM): Handle DW_OP_GNU_addr_index.
>             (Dwarf::_default_form): Supply a default for
> DW_AT_GNU_addr_base.
>             (Dwarf::_handle_macro_at_range): Use form
> DW_FORM_GNU_addr_index
>             if this is a fission CU.
>             (Dwarf::_location): Handle DW_OP_GNU_addr_index.
>             (Dwarf::debug_addr_index): New proc.
>             (Dwarf::cu): Initialise _cu_is_fission.
>             (Dwarf::tu): Likewise.
>             (Dwarf::assemble): Initialise _debug_addr_index.
>
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index d6881300fa6..522ccc2506e 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -12581,6 +12581,15 @@ try_open_dwop_file (dwarf2_per_objfile
> *per_objfile,
>    else
>      search_path = debug_file_directory;
>
> +  if (getenv ("GDB_NO_FIX") == nullptr)
> +    {
> +      /* Add the path for the executable binary to the list of search
> paths.  */
> +      search_path_holder.reset
> +       (concat (ldirname (per_objfile->objfile->original_name).c_str (),
> +                dirname_separator_string, search_path, nullptr));
> +      search_path = search_path_holder.get ();
> +    }
> +
>    openp_flags flags = OPF_RETURN_REALPATH;
>    if (is_dwp)
>      flags |= OPF_SEARCH_IN_PATH;
> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> new file mode 100644
> index 00000000000..27f7f0dfb4b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> @@ -0,0 +1,28 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   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/>.  */
> +
> +/* Our fake object.  */
> +int global_var[100];
> +
> +int
> +main (int argc, char **argv)
> +{
> +  asm ("main_label: .globl main_label");
> +
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> new file mode 100644
> index 00000000000..f9ab3b8c6a4
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> @@ -0,0 +1,145 @@
> +# 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/>.
> +load_lib dwarf.exp
> +
> +# This test can only be run on targets which support DWARF-2 and use gas.
> +if {![dwarf2_support]} {
> +    return 0
> +}
> +
> +standard_testfile .c -dw.S
> +
> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
> +    return -1
> +}
> +
> +set asm_file [standard_output_file $srcfile2]
> +Dwarf::assemble $asm_file {
> +    global srcfile gdb_test_file_name
> +
> +    set debug_addr_base -1
> +
> +    # The information that will be split out into the .dwo file.
> +    cu {fission 1} {
> +
> +       # Capture the current index into .debug_addr so we can fill in
> +       # DW_AT_GNU_addr_base later.
> +       set debug_addr_base [debug_addr_index]
> +
> +       compile_unit {
> +            {language @DW_LANG_C}
> +            {name ${srcfile}}
> +           {DW_AT_comp_dir .}
> +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
> +        } {
> +           declare_labels int4_type struct_type
> +
> +           int4_type: DW_TAG_base_type {
> +               {DW_AT_byte_size 4 DW_FORM_sdata}
> +               {DW_AT_encoding  @DW_ATE_signed}
> +               {DW_AT_name      integer}
> +           }
> +
> +           struct_type: DW_TAG_structure_type {
> +               {DW_AT_name "foo_t"}
> +               {DW_AT_byte_size 12 DW_FORM_sdata}
> +           } {
> +               member {
> +                   {name "aa"}
> +                   {type :$int4_type}
> +                   {data_member_location 0 data1}
> +               }
> +               member {
> +                   {name "bb"}
> +                   {type :$int4_type}
> +                   {data_member_location 4 data1}
> +               }
> +               member {
> +                   {name "cc"}
> +                   {type :$int4_type}
> +                   {data_member_location 8 data1}
> +               }
> +           }
> +
> +           DW_TAG_variable {
> +               {DW_AT_name global_var}
> +               {DW_AT_type :$struct_type}
> +               {DW_AT_location {
> +                   DW_OP_GNU_addr_index [gdb_target_symbol global_var]
> +               } SPECIAL_expr}
> +               {external 1 flag}
> +           }
> +
> +           subprogram {
> +               {external 1 flag}
> +               {DW_AT_name main DW_FORM_string}
> +               {MACRO_AT_func {main}}
> +           }
> +       }
> +    }
> +
> +    # The information that will remain in the .o file.
> +    cu {} {
> +       compile_unit {
> +            {DW_AT_GNU_dwo_name ${gdb_test_file_name}.dwo DW_FORM_strp}
> +           {DW_AT_comp_dir .}
> +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
> +           {DW_AT_GNU_addr_base $debug_addr_base}
> +        } {
> +           # Nothing.
> +       }
> +    }
> +}
> +
> +# Assemble the file containing the .dwo information, we can then split
> +# this out into a separate .dwo file.  Once we've extracted the DWO
> +# information from this object file we're done with it, we recompile
> +# this again in the BUILD_EXECUTABLE call below.
> +set object_file [standard_output_file ${binfile}-dwo.o]
> +if { [gdb_compile $asm_file $object_file object {nodebug}] != "" } {
> +    return -1
> +}
> +
> +# Split out the dwo sections into a dwo file.
> +if { [extract_dwo_information $object_file ${binfile}.dwo] == -1 } {
> +    perror "failed to extract dwo information"
> +    return -1
> +}
> +
> +# Build the executable, but don't use prepare_for_testing as we don't
> +# want to start GDB just yet.
> +if { [build_executable "failed to prepare" "${testfile}" \
> +         [list $srcfile $asm_file] {nodebug}] } {
> +    return -1
> +}
> +
> +# Just so we can't be found cheating, strip all the dwo information
> +# from the executable.
> +if { [strip_dwo_information ${binfile}] == -1 } {
> +    perror "failed to strip dwo information"
> +    return -1
> +}
> +
> +# Now we can start GDB.
> +clean_restart ${testfile}
> +
> +if ![runto_main] {
> +    return -1
> +}
> +
> +# Print the type of global_var.  This type information is entirely
> +# fictional, it only exists in the DWARF.  If we don't have the DWARF
> +# information then there's no way we can print this.
> +gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
> diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
> index 4cd5e16c604..a41366f1747 100644
> --- a/gdb/testsuite/lib/dwarf.exp
> +++ b/gdb/testsuite/lib/dwarf.exp
> @@ -28,6 +28,38 @@ proc dwarf2_support {} {
>      return 0
>  }
>
> +# Use 'objcopy --extract-dwo to extract DWO information from
> +# OBJECT_FILE and place it into DWO_FILE.
> +#
> +# Return 0 on success, otherwise, return -1.
> +proc extract_dwo_information { object_file dwo_file } {
> +    set objcopy [gdb_find_objcopy]
> +    set command "$objcopy --extract-dwo $object_file $dwo_file"
> +    verbose -log "Executing $command"
> +    set result [catch "exec $command" output]
> +    verbose -log "objcopy --extract-dwo output: $output"
> +    if { $result == 1 } {
> +       return -1
> +    }
> +    return 0
> +}
> +
> +# Use 'objcopy --strip-dwo to remove DWO information from
> +# FILENAME.
> +#
> +# Return 0 on success, otherwise, return -1.
> +proc strip_dwo_information { filename } {
> +   set objcopy [gdb_find_objcopy]
> +    set command "$objcopy --strip-dwo $filename"
> +    verbose -log "Executing $command"
> +    set result [catch "exec $command" output]
> +    verbose -log "objcopy --strip-dwo output: $output"
> +    if { $result == 1 } {
> +       return -1
> +    }
> +    return 0
> +}
> +
>  # Build an executable from a fission-based .S file.
>  # This handles the extra work of splitting the .o into non-dwo and dwo
>  # pieces, making sure the .dwo is available if we're using
> cc-with-tweaks.sh
> @@ -54,26 +86,17 @@ proc build_executable_from_fission_assembler {
> testname executable sources optio
>      set object_file ${output_base}.o
>      set dwo_file ${output_base}.dwo
>      set object_options "object $options"
> -    set objcopy [gdb_find_objcopy]
>
>      set result [gdb_compile $source_file $object_file object $options]
>      if { "$result" != "" } {
>         return -1
>      }
>
> -    set command "$objcopy --extract-dwo $object_file $dwo_file"
> -    verbose -log "Executing $command"
> -    set result [catch "exec $command" output]
> -    verbose -log "objcopy --extract-dwo output: $output"
> -    if { $result == 1 } {
> +    if { [extract_dwo_information $object_file $dwo_file] == -1 } {
>         return -1
>      }
>
> -    set command "$objcopy --strip-dwo $object_file"
> -    verbose -log "Executing $command"
> -    set result [catch "exec $command" output]
> -    verbose -log "objcopy --strip-dwo output: $output"
> -    if { $result == 1 } {
> +    if { [strip_dwo_information $object_file] == -1 } {
>         return -1
>      }
>
> @@ -329,6 +352,14 @@ namespace eval Dwarf {
>      # The address size for debug ranges section.
>      variable _debug_ranges_64_bit
>
> +    # The index into the .debug_addr section (used for fission
> +    # generation).
> +    variable _debug_addr_index
> +
> +    # Flag, true if the current CU is contains fission information,
> +    # otherwise false.
> +    variable _cu_is_fission
> +
>      proc _process_one_constant {name value} {
>         variable _constants
>         variable _AT
> @@ -486,6 +517,18 @@ namespace eval Dwarf {
>                 _op .${_cu_addr_size}byte $value
>             }
>
> +           DW_FORM_GNU_addr_index {
> +               variable _debug_addr_index
> +               variable _cu_addr_size
> +
> +               _op .uleb128 ${_debug_addr_index}
> +               incr _debug_addr_index
> +
> +               _defer_output .debug_addr {
> +                   _op .${_cu_addr_size}byte $value
> +               }
> +           }
> +
>             DW_FORM_data2 -
>             DW_FORM_ref2 {
>                 _op .2byte $value
> @@ -553,7 +596,6 @@ namespace eval Dwarf {
>             DW_FORM_strx3 -
>             DW_FORM_strx4 -
>
> -           DW_FORM_GNU_addr_index -
>             DW_FORM_GNU_str_index -
>
>             default {
> @@ -609,6 +651,9 @@ namespace eval Dwarf {
>             DW_AT_name {
>                 return DW_FORM_string
>             }
> +           DW_AT_GNU_addr_base {
> +               return DW_FORM_sec_offset
> +           }
>         }
>         return ""
>      }
> @@ -649,6 +694,8 @@ namespace eval Dwarf {
>      # Handle macro attribute MACRO_AT_range.
>
>      proc _handle_macro_at_range { attr_value } {
> +       variable _cu_is_fission
> +
>         if {[llength $attr_value] != 1} {
>             error "usage: MACRO_AT_range { func }"
>         }
> @@ -658,10 +705,14 @@ namespace eval Dwarf {
>         set src ${srcdir}/${subdir}/${srcfile}
>         set result [function_range $func $src]
>
> -       _handle_attribute DW_AT_low_pc [lindex $result 0] \
> -           DW_FORM_addr
> +       set form DW_FORM_addr
> +       if { $_cu_is_fission } {
> +           set form DW_FORM_GNU_addr_index
> +       }
> +
> +       _handle_attribute DW_AT_low_pc [lindex $result 0] $form
>         _handle_attribute DW_AT_high_pc \
> -           "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
> +           "[lindex $result 0] + [lindex $result 1]" $form
>      }
>
>      # Handle macro attribute MACRO_AT_func.
> @@ -929,6 +980,18 @@ namespace eval Dwarf {
>                     _op .${addr_size}byte [lindex $line 1]
>                 }
>
> +               DW_OP_GNU_addr_index {
> +                   variable _debug_addr_index
> +                   variable _cu_addr_size
> +
> +                   _op .uleb128 ${_debug_addr_index}
> +                   incr _debug_addr_index
> +
> +                   _defer_output .debug_addr {
> +                       _op .${_cu_addr_size}byte [lindex $line 1]
> +                   }
> +               }
> +
>                 DW_OP_regx {
>                     _op .uleb128 [lindex $line 1]
>                 }
> @@ -1050,6 +1113,14 @@ namespace eval Dwarf {
>         }
>      }
>
> +    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
> +    # of this function can be used for the value of
> +    # DW_AT_GNU_addr_base.
> +    proc debug_addr_index {} {
> +       variable _debug_addr_index
> +       return ${_debug_addr_index}
> +    }
> +
>      # Emit a DWARF CU.
>      # OPTIONS is a list with an even number of elements containing
>      # option-name and option-value pairs.
> @@ -1073,12 +1144,13 @@ namespace eval Dwarf {
>         variable _cu_version
>         variable _cu_addr_size
>         variable _cu_offset_size
> +       variable _cu_is_fission
>
>         # Establish the defaults.
>         set is_64 0
>         set _cu_version 4
>         set _cu_addr_size default
> -       set fission 0
> +       set _cu_is_fission 0
>         set section ".debug_info"
>         set _abbrev_section ".debug_abbrev"
>
> @@ -1088,7 +1160,7 @@ namespace eval Dwarf {
>                 is_64 { set is_64 $value }
>                 version { set _cu_version $value }
>                 addr_size { set _cu_addr_size $value }
> -               fission { set fission $value }
> +               fission { set _cu_is_fission $value }
>                 default { error "unknown option $name" }
>             }
>         }
> @@ -1100,7 +1172,7 @@ namespace eval Dwarf {
>             }
>         }
>         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
> -       if { $fission } {
> +       if { $_cu_is_fission } {
>             set section ".debug_info.dwo"
>             set _abbrev_section ".debug_abbrev.dwo"
>         }
> @@ -1180,12 +1252,13 @@ namespace eval Dwarf {
>         variable _cu_version
>         variable _cu_addr_size
>         variable _cu_offset_size
> +       variable _cu_is_fission
>
>         # Establish the defaults.
>         set is_64 0
>         set _cu_version 4
>         set _cu_addr_size default
> -       set fission 0
> +       set _cu_is_fission 0
>         set section ".debug_types"
>         set _abbrev_section ".debug_abbrev"
>
> @@ -1194,7 +1267,7 @@ namespace eval Dwarf {
>                 is_64 { set is_64 $value }
>                 version { set _cu_version $value }
>                 addr_size { set _cu_addr_size $value }
> -               fission { set fission $value }
> +               fission { set _cu_is_fission $value }
>                 default { error "unknown option $name" }
>             }
>         }
> @@ -1206,7 +1279,7 @@ namespace eval Dwarf {
>             }
>         }
>         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
> -       if { $fission } {
> +       if { $_cu_is_fission } {
>             set section ".debug_types.dwo"
>             set _abbrev_section ".debug_abbrev.dwo"
>         }
> @@ -2056,6 +2129,7 @@ namespace eval Dwarf {
>         variable _line_saw_program
>         variable _line_header_end_label
>         variable _debug_ranges_64_bit
> +       variable _debug_addr_index
>
>         if {!$_initialized} {
>             _read_constants
> @@ -2074,6 +2148,8 @@ namespace eval Dwarf {
>         set _line_saw_program 0
>         set _debug_ranges_64_bit [is_64_target]
>
> +       set _debug_addr_index 0
> +
>         # Not "uplevel" here, because we want to evaluate in this
>         # namespace.  This is somewhat bad because it means we can't
>         # readily refer to outer variables.
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH, v2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-25 15:09       ` Caroline Tice
@ 2021-03-25 17:46         ` Andrew Burgess
  2021-03-26 17:54           ` [PATCHv3 0/2] " Andrew Burgess
  0 siblings, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2021-03-25 17:46 UTC (permalink / raw)
  To: Caroline Tice; +Cc: Caroline Tice via Gdb-patches

* Caroline Tice <cmtice@google.com> [2021-03-25 08:09:21 -0700]:

> Hi Andrew,
> 
> As I said previously, your suggested patch works well and fixes the
> problem.  I thought you were going to submit it, but I have not seen it  go
> out for review or be committed.  Is there something else you need me to
> do?  I would be happy to send your version for review if you would
> like?

I'll take a look at this tomorrow.

Thanks,
Andrew


> 
> -- Caroline
> cmtice@google.com
> 
> 
> On Wed, Mar 17, 2021 at 5:26 PM Andrew Burgess <andrew.burgess@embecosm.com>
> wrote:
> 
> > * Caroline Tice <cmtice@google.com> [2021-03-04 07:48:37 -0800]:
> >
> > > Hi Andrew,
> > >
> > > I updated my change to gdb/dwarf2/read.c as you suggested (spaces
> > > before '(' and use nullptr).
> > >
> > > I spent a long time looking into using Dwarf::assemble in my testcase,
> > > to make it hardware agnostic (although I'd like to point out
> > > that most of the rest of the fission tests specifically only work for
> > > x86_64),
> >
> > Most of these were written before the Dwarf assembler was available.
> > If they were being written today then we'd be using the Dwarf
> > assembler.
> >
> > >           but in the end found that it would not work for me.   The
> > > problems that I was unable to make this work for was that I needed to
> > > generate not only the binary but the .dwo file; I needed reasonably
> > > valid DWARF in both of them; and the path name for the .dwo file had
> > > to be relative not absolute -- the way gdb compiles the test suites it
> > > always uses complete absolute paths for all of its files.
> >
> > I don't understand what problem you ran into here.  The path to the
> > DWO file is encoded into the DWARF of the executable in a
> > DW_AT_GNU_dwo_name attribute, which would be entirely generated within
> > the .exp file, and so could contain whatever you like.  Likewise for
> > the DW_AT_comp_dir.
> >
> > I made an attempt at writing a test using the dwarf assembler.  You
> > will need to start by applying this patch to a clean GDB tree:
> >
> >    https://sourceware.org/pipermail/gdb-patches/2021-March/177049.html
> >
> > Then grab the patch below and give it a try.  It includes your fix,
> > and a brand new test case.  Let me know if you don't think this is
> > covering your change correctly, I'm sure we can get it working as
> > needed.
> >
> > Thanks,
> > Andrew
> >
> > ---
> >
> > commit 47bf19a7ed4c96a86d67329efb7e5ce983debddd
> > Author: Andrew Burgess <andrew.burgess@embecosm.com>
> > Date:   Wed Mar 17 22:54:22 2021 +0000
> >
> >     gdb: handle relative paths to DWO files
> >
> >     **** NOTE ****
> >
> >     The fix in dwarf2/read.c includes a hack to allow the fix to be
> >     toggled on/off using environment variable GDB_NO_FIX.  This must be
> >     removed before pushing upstream.
> >
> >     **** END NOTE ****
> >
> >     DWARF allows .dwo file paths to be relative rather than absolute.
> >
> >     When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
> >     file.  DW_AT_comp_dir can also be relative, making the entire search
> >     patch for the .dwo file relative.
> >
> >     In this case, GDB currently searches relative to its current working
> >     directory, i.e. the directory from which the debugger was launched,
> >     but not relative to the directory containing the built binary.  This
> >     cannot be right, as the compiler, when generating the relative paths,
> >     knows where it's building the binary but can have no idea where the
> >     debugger will be launched.
> >
> >     The correct thing is to add the directory containing the binary to the
> >     search paths used for resolving relative locations of dwo files. That
> >     is what this patch does.
> >
> >     gdb/ChangeLog:
> >
> >             * dwarf2/read.c (try_open_dwop_file): Add path for the binary
> > to
> >             the search paths used resolve relative location of .dwo file.
> >
> >     gdb/testsuite/ChangeLog:
> >
> >             * gdb.dwarf2/fission-relative-dwo.c: New file.
> >             * gdb.dwarf2/fission-relative-dwo.exp: New file.
> >             * lib/dwarf.exp (extract_dwo_information): New proc.
> >             (strip_dwo_information): New proc.
> >             (build_executable_from_fission_assembler): Use
> >             extract_dwo_information and strip_dwo_information.
> >             (Dwarf::_debug_addr_index): New variable.
> >             (Dwarf::_cu_is_fission): New variable.
> >             (Dwarf::_handle_DW_FORM): Handle DW_OP_GNU_addr_index.
> >             (Dwarf::_default_form): Supply a default for
> > DW_AT_GNU_addr_base.
> >             (Dwarf::_handle_macro_at_range): Use form
> > DW_FORM_GNU_addr_index
> >             if this is a fission CU.
> >             (Dwarf::_location): Handle DW_OP_GNU_addr_index.
> >             (Dwarf::debug_addr_index): New proc.
> >             (Dwarf::cu): Initialise _cu_is_fission.
> >             (Dwarf::tu): Likewise.
> >             (Dwarf::assemble): Initialise _debug_addr_index.
> >
> > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> > index d6881300fa6..522ccc2506e 100644
> > --- a/gdb/dwarf2/read.c
> > +++ b/gdb/dwarf2/read.c
> > @@ -12581,6 +12581,15 @@ try_open_dwop_file (dwarf2_per_objfile
> > *per_objfile,
> >    else
> >      search_path = debug_file_directory;
> >
> > +  if (getenv ("GDB_NO_FIX") == nullptr)
> > +    {
> > +      /* Add the path for the executable binary to the list of search
> > paths.  */
> > +      search_path_holder.reset
> > +       (concat (ldirname (per_objfile->objfile->original_name).c_str (),
> > +                dirname_separator_string, search_path, nullptr));
> > +      search_path = search_path_holder.get ();
> > +    }
> > +
> >    openp_flags flags = OPF_RETURN_REALPATH;
> >    if (is_dwp)
> >      flags |= OPF_SEARCH_IN_PATH;
> > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > new file mode 100644
> > index 00000000000..27f7f0dfb4b
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> > @@ -0,0 +1,28 @@
> > +/* This testcase is part of GDB, the GNU debugger.
> > +
> > +   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/>.  */
> > +
> > +/* Our fake object.  */
> > +int global_var[100];
> > +
> > +int
> > +main (int argc, char **argv)
> > +{
> > +  asm ("main_label: .globl main_label");
> > +
> > +  return 0;
> > +}
> > diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > new file mode 100644
> > index 00000000000..f9ab3b8c6a4
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> > @@ -0,0 +1,145 @@
> > +# 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/>.
> > +load_lib dwarf.exp
> > +
> > +# This test can only be run on targets which support DWARF-2 and use gas.
> > +if {![dwarf2_support]} {
> > +    return 0
> > +}
> > +
> > +standard_testfile .c -dw.S
> > +
> > +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
> > +    return -1
> > +}
> > +
> > +set asm_file [standard_output_file $srcfile2]
> > +Dwarf::assemble $asm_file {
> > +    global srcfile gdb_test_file_name
> > +
> > +    set debug_addr_base -1
> > +
> > +    # The information that will be split out into the .dwo file.
> > +    cu {fission 1} {
> > +
> > +       # Capture the current index into .debug_addr so we can fill in
> > +       # DW_AT_GNU_addr_base later.
> > +       set debug_addr_base [debug_addr_index]
> > +
> > +       compile_unit {
> > +            {language @DW_LANG_C}
> > +            {name ${srcfile}}
> > +           {DW_AT_comp_dir .}
> > +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
> > +        } {
> > +           declare_labels int4_type struct_type
> > +
> > +           int4_type: DW_TAG_base_type {
> > +               {DW_AT_byte_size 4 DW_FORM_sdata}
> > +               {DW_AT_encoding  @DW_ATE_signed}
> > +               {DW_AT_name      integer}
> > +           }
> > +
> > +           struct_type: DW_TAG_structure_type {
> > +               {DW_AT_name "foo_t"}
> > +               {DW_AT_byte_size 12 DW_FORM_sdata}
> > +           } {
> > +               member {
> > +                   {name "aa"}
> > +                   {type :$int4_type}
> > +                   {data_member_location 0 data1}
> > +               }
> > +               member {
> > +                   {name "bb"}
> > +                   {type :$int4_type}
> > +                   {data_member_location 4 data1}
> > +               }
> > +               member {
> > +                   {name "cc"}
> > +                   {type :$int4_type}
> > +                   {data_member_location 8 data1}
> > +               }
> > +           }
> > +
> > +           DW_TAG_variable {
> > +               {DW_AT_name global_var}
> > +               {DW_AT_type :$struct_type}
> > +               {DW_AT_location {
> > +                   DW_OP_GNU_addr_index [gdb_target_symbol global_var]
> > +               } SPECIAL_expr}
> > +               {external 1 flag}
> > +           }
> > +
> > +           subprogram {
> > +               {external 1 flag}
> > +               {DW_AT_name main DW_FORM_string}
> > +               {MACRO_AT_func {main}}
> > +           }
> > +       }
> > +    }
> > +
> > +    # The information that will remain in the .o file.
> > +    cu {} {
> > +       compile_unit {
> > +            {DW_AT_GNU_dwo_name ${gdb_test_file_name}.dwo DW_FORM_strp}
> > +           {DW_AT_comp_dir .}
> > +           {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
> > +           {DW_AT_GNU_addr_base $debug_addr_base}
> > +        } {
> > +           # Nothing.
> > +       }
> > +    }
> > +}
> > +
> > +# Assemble the file containing the .dwo information, we can then split
> > +# this out into a separate .dwo file.  Once we've extracted the DWO
> > +# information from this object file we're done with it, we recompile
> > +# this again in the BUILD_EXECUTABLE call below.
> > +set object_file [standard_output_file ${binfile}-dwo.o]
> > +if { [gdb_compile $asm_file $object_file object {nodebug}] != "" } {
> > +    return -1
> > +}
> > +
> > +# Split out the dwo sections into a dwo file.
> > +if { [extract_dwo_information $object_file ${binfile}.dwo] == -1 } {
> > +    perror "failed to extract dwo information"
> > +    return -1
> > +}
> > +
> > +# Build the executable, but don't use prepare_for_testing as we don't
> > +# want to start GDB just yet.
> > +if { [build_executable "failed to prepare" "${testfile}" \
> > +         [list $srcfile $asm_file] {nodebug}] } {
> > +    return -1
> > +}
> > +
> > +# Just so we can't be found cheating, strip all the dwo information
> > +# from the executable.
> > +if { [strip_dwo_information ${binfile}] == -1 } {
> > +    perror "failed to strip dwo information"
> > +    return -1
> > +}
> > +
> > +# Now we can start GDB.
> > +clean_restart ${testfile}
> > +
> > +if ![runto_main] {
> > +    return -1
> > +}
> > +
> > +# Print the type of global_var.  This type information is entirely
> > +# fictional, it only exists in the DWARF.  If we don't have the DWARF
> > +# information then there's no way we can print this.
> > +gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
> > diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
> > index 4cd5e16c604..a41366f1747 100644
> > --- a/gdb/testsuite/lib/dwarf.exp
> > +++ b/gdb/testsuite/lib/dwarf.exp
> > @@ -28,6 +28,38 @@ proc dwarf2_support {} {
> >      return 0
> >  }
> >
> > +# Use 'objcopy --extract-dwo to extract DWO information from
> > +# OBJECT_FILE and place it into DWO_FILE.
> > +#
> > +# Return 0 on success, otherwise, return -1.
> > +proc extract_dwo_information { object_file dwo_file } {
> > +    set objcopy [gdb_find_objcopy]
> > +    set command "$objcopy --extract-dwo $object_file $dwo_file"
> > +    verbose -log "Executing $command"
> > +    set result [catch "exec $command" output]
> > +    verbose -log "objcopy --extract-dwo output: $output"
> > +    if { $result == 1 } {
> > +       return -1
> > +    }
> > +    return 0
> > +}
> > +
> > +# Use 'objcopy --strip-dwo to remove DWO information from
> > +# FILENAME.
> > +#
> > +# Return 0 on success, otherwise, return -1.
> > +proc strip_dwo_information { filename } {
> > +   set objcopy [gdb_find_objcopy]
> > +    set command "$objcopy --strip-dwo $filename"
> > +    verbose -log "Executing $command"
> > +    set result [catch "exec $command" output]
> > +    verbose -log "objcopy --strip-dwo output: $output"
> > +    if { $result == 1 } {
> > +       return -1
> > +    }
> > +    return 0
> > +}
> > +
> >  # Build an executable from a fission-based .S file.
> >  # This handles the extra work of splitting the .o into non-dwo and dwo
> >  # pieces, making sure the .dwo is available if we're using
> > cc-with-tweaks.sh
> > @@ -54,26 +86,17 @@ proc build_executable_from_fission_assembler {
> > testname executable sources optio
> >      set object_file ${output_base}.o
> >      set dwo_file ${output_base}.dwo
> >      set object_options "object $options"
> > -    set objcopy [gdb_find_objcopy]
> >
> >      set result [gdb_compile $source_file $object_file object $options]
> >      if { "$result" != "" } {
> >         return -1
> >      }
> >
> > -    set command "$objcopy --extract-dwo $object_file $dwo_file"
> > -    verbose -log "Executing $command"
> > -    set result [catch "exec $command" output]
> > -    verbose -log "objcopy --extract-dwo output: $output"
> > -    if { $result == 1 } {
> > +    if { [extract_dwo_information $object_file $dwo_file] == -1 } {
> >         return -1
> >      }
> >
> > -    set command "$objcopy --strip-dwo $object_file"
> > -    verbose -log "Executing $command"
> > -    set result [catch "exec $command" output]
> > -    verbose -log "objcopy --strip-dwo output: $output"
> > -    if { $result == 1 } {
> > +    if { [strip_dwo_information $object_file] == -1 } {
> >         return -1
> >      }
> >
> > @@ -329,6 +352,14 @@ namespace eval Dwarf {
> >      # The address size for debug ranges section.
> >      variable _debug_ranges_64_bit
> >
> > +    # The index into the .debug_addr section (used for fission
> > +    # generation).
> > +    variable _debug_addr_index
> > +
> > +    # Flag, true if the current CU is contains fission information,
> > +    # otherwise false.
> > +    variable _cu_is_fission
> > +
> >      proc _process_one_constant {name value} {
> >         variable _constants
> >         variable _AT
> > @@ -486,6 +517,18 @@ namespace eval Dwarf {
> >                 _op .${_cu_addr_size}byte $value
> >             }
> >
> > +           DW_FORM_GNU_addr_index {
> > +               variable _debug_addr_index
> > +               variable _cu_addr_size
> > +
> > +               _op .uleb128 ${_debug_addr_index}
> > +               incr _debug_addr_index
> > +
> > +               _defer_output .debug_addr {
> > +                   _op .${_cu_addr_size}byte $value
> > +               }
> > +           }
> > +
> >             DW_FORM_data2 -
> >             DW_FORM_ref2 {
> >                 _op .2byte $value
> > @@ -553,7 +596,6 @@ namespace eval Dwarf {
> >             DW_FORM_strx3 -
> >             DW_FORM_strx4 -
> >
> > -           DW_FORM_GNU_addr_index -
> >             DW_FORM_GNU_str_index -
> >
> >             default {
> > @@ -609,6 +651,9 @@ namespace eval Dwarf {
> >             DW_AT_name {
> >                 return DW_FORM_string
> >             }
> > +           DW_AT_GNU_addr_base {
> > +               return DW_FORM_sec_offset
> > +           }
> >         }
> >         return ""
> >      }
> > @@ -649,6 +694,8 @@ namespace eval Dwarf {
> >      # Handle macro attribute MACRO_AT_range.
> >
> >      proc _handle_macro_at_range { attr_value } {
> > +       variable _cu_is_fission
> > +
> >         if {[llength $attr_value] != 1} {
> >             error "usage: MACRO_AT_range { func }"
> >         }
> > @@ -658,10 +705,14 @@ namespace eval Dwarf {
> >         set src ${srcdir}/${subdir}/${srcfile}
> >         set result [function_range $func $src]
> >
> > -       _handle_attribute DW_AT_low_pc [lindex $result 0] \
> > -           DW_FORM_addr
> > +       set form DW_FORM_addr
> > +       if { $_cu_is_fission } {
> > +           set form DW_FORM_GNU_addr_index
> > +       }
> > +
> > +       _handle_attribute DW_AT_low_pc [lindex $result 0] $form
> >         _handle_attribute DW_AT_high_pc \
> > -           "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
> > +           "[lindex $result 0] + [lindex $result 1]" $form
> >      }
> >
> >      # Handle macro attribute MACRO_AT_func.
> > @@ -929,6 +980,18 @@ namespace eval Dwarf {
> >                     _op .${addr_size}byte [lindex $line 1]
> >                 }
> >
> > +               DW_OP_GNU_addr_index {
> > +                   variable _debug_addr_index
> > +                   variable _cu_addr_size
> > +
> > +                   _op .uleb128 ${_debug_addr_index}
> > +                   incr _debug_addr_index
> > +
> > +                   _defer_output .debug_addr {
> > +                       _op .${_cu_addr_size}byte [lindex $line 1]
> > +                   }
> > +               }
> > +
> >                 DW_OP_regx {
> >                     _op .uleb128 [lindex $line 1]
> >                 }
> > @@ -1050,6 +1113,14 @@ namespace eval Dwarf {
> >         }
> >      }
> >
> > +    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
> > +    # of this function can be used for the value of
> > +    # DW_AT_GNU_addr_base.
> > +    proc debug_addr_index {} {
> > +       variable _debug_addr_index
> > +       return ${_debug_addr_index}
> > +    }
> > +
> >      # Emit a DWARF CU.
> >      # OPTIONS is a list with an even number of elements containing
> >      # option-name and option-value pairs.
> > @@ -1073,12 +1144,13 @@ namespace eval Dwarf {
> >         variable _cu_version
> >         variable _cu_addr_size
> >         variable _cu_offset_size
> > +       variable _cu_is_fission
> >
> >         # Establish the defaults.
> >         set is_64 0
> >         set _cu_version 4
> >         set _cu_addr_size default
> > -       set fission 0
> > +       set _cu_is_fission 0
> >         set section ".debug_info"
> >         set _abbrev_section ".debug_abbrev"
> >
> > @@ -1088,7 +1160,7 @@ namespace eval Dwarf {
> >                 is_64 { set is_64 $value }
> >                 version { set _cu_version $value }
> >                 addr_size { set _cu_addr_size $value }
> > -               fission { set fission $value }
> > +               fission { set _cu_is_fission $value }
> >                 default { error "unknown option $name" }
> >             }
> >         }
> > @@ -1100,7 +1172,7 @@ namespace eval Dwarf {
> >             }
> >         }
> >         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
> > -       if { $fission } {
> > +       if { $_cu_is_fission } {
> >             set section ".debug_info.dwo"
> >             set _abbrev_section ".debug_abbrev.dwo"
> >         }
> > @@ -1180,12 +1252,13 @@ namespace eval Dwarf {
> >         variable _cu_version
> >         variable _cu_addr_size
> >         variable _cu_offset_size
> > +       variable _cu_is_fission
> >
> >         # Establish the defaults.
> >         set is_64 0
> >         set _cu_version 4
> >         set _cu_addr_size default
> > -       set fission 0
> > +       set _cu_is_fission 0
> >         set section ".debug_types"
> >         set _abbrev_section ".debug_abbrev"
> >
> > @@ -1194,7 +1267,7 @@ namespace eval Dwarf {
> >                 is_64 { set is_64 $value }
> >                 version { set _cu_version $value }
> >                 addr_size { set _cu_addr_size $value }
> > -               fission { set fission $value }
> > +               fission { set _cu_is_fission $value }
> >                 default { error "unknown option $name" }
> >             }
> >         }
> > @@ -1206,7 +1279,7 @@ namespace eval Dwarf {
> >             }
> >         }
> >         set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
> > -       if { $fission } {
> > +       if { $_cu_is_fission } {
> >             set section ".debug_types.dwo"
> >             set _abbrev_section ".debug_abbrev.dwo"
> >         }
> > @@ -2056,6 +2129,7 @@ namespace eval Dwarf {
> >         variable _line_saw_program
> >         variable _line_header_end_label
> >         variable _debug_ranges_64_bit
> > +       variable _debug_addr_index
> >
> >         if {!$_initialized} {
> >             _read_constants
> > @@ -2074,6 +2148,8 @@ namespace eval Dwarf {
> >         set _line_saw_program 0
> >         set _debug_ranges_64_bit [is_64_target]
> >
> > +       set _debug_addr_index 0
> > +
> >         # Not "uplevel" here, because we want to evaluate in this
> >         # namespace.  This is somewhat bad because it means we can't
> >         # readily refer to outer variables.
> >

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-25 17:46         ` Andrew Burgess
@ 2021-03-26 17:54           ` Andrew Burgess
  2021-03-26 17:54             ` [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler Andrew Burgess
                               ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Andrew Burgess @ 2021-03-26 17:54 UTC (permalink / raw)
  To: gdb-patches

Caroline,

I split the testsuite changes out into a separate patch (#1), this
makes the patch containing your change (#2) much smaller, and more
focused.

If there's no feedback I'll push this early next week.

Thanks,
Andrew

---

Andrew Burgess (2):
  gdb/testsuite: fix fission support in the Dwarf assembler
  gdb: handle relative paths to DWO files

 gdb/ChangeLog                                 |   5 +
 gdb/dwarf2/read.c                             |   7 +
 gdb/testsuite/ChangeLog                       |  31 +++
 .../gdb.dwarf2/fission-absolute-dwo.c         |  28 ++
 .../gdb.dwarf2/fission-absolute-dwo.exp       | 132 ++++++++++
 gdb/testsuite/gdb.dwarf2/fission-base.exp     |  11 +-
 .../gdb.dwarf2/fission-loclists-pie.exp       |  11 +-
 gdb/testsuite/gdb.dwarf2/fission-loclists.exp |  11 +-
 gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp |  11 +-
 .../gdb.dwarf2/fission-relative-dwo.c         |  28 ++
 .../gdb.dwarf2/fission-relative-dwo.exp       | 130 +++++++++
 gdb/testsuite/gdb.dwarf2/fission-reread.exp   |  15 +-
 gdb/testsuite/lib/dwarf.exp                   | 248 ++++++++++++++----
 13 files changed, 598 insertions(+), 70 deletions(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp

-- 
2.25.4


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler
  2021-03-26 17:54           ` [PATCHv3 0/2] " Andrew Burgess
@ 2021-03-26 17:54             ` Andrew Burgess
  2021-03-29 16:30               ` Simon Marchi
  2021-03-26 17:54             ` [PATCHv3 2/2] gdb: handle relative paths to DWO files Andrew Burgess
  2021-03-31 15:57             ` [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files Caroline Tice
  2 siblings, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2021-03-26 17:54 UTC (permalink / raw)
  To: gdb-patches

This commit fixes fission support in the Dwarf assembler.  The new
test gdb.dwarf2/fission-absolute-dwo.exp which exercises this
feature.

To better support compiling the assembler files produced by the Dwarf
assembler I have added the new proc build_executable_and_dwo_files in
lib/dwarf.exp, this replaces build_executable_from_fission_assembler,
all the tests that used the old proc have been updated.  Where the old
proc assumed a single .S source file which contained the entire test,
the new proc allows for multiple source files.

The Dwarf assembler already had some fission support, however, this
was not actually used in any tests, and when I tried using it there
were a few issues.

The biggest change is that we now generate DW_FORM_GNU_addr_index
instead of DW_FORM_addr for the low and high pc in
_handle_macro_at_range, support for the DW_FORM_GNU_addr_index is new
in this commit.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/fission-absolute-dwo.c: New file.
	* gdb.dwarf2/fission-absolute-dwo.exp: New file.
	* gdb.dwarf2/fission-base.exp: Use build_executable_and_dwo_files
	instead of build_executable_from_fission_assembler.
	* gdb.dwarf2/fission-loclists-pie.exp: Likewise.
	* gdb.dwarf2/fission-loclists.exp: Likewise.
	* gdb.dwarf2/fission-multi-cu.exp: Likewise.
	* gdb.dwarf2/fission-reread.exp: Likewise.
	* lib/dwarf.exp (extract_dwo_information): New proc.
	(strip_dwo_information): New proc.
	(build_executable_and_dwo_files): New proc.
	(build_executable_from_fission_assembler): Delete.
	(Dwarf::_debug_addr_index): New variable.
	(Dwarf::_cu_is_fission): New variable.
	(Dwarf::_handle_DW_FORM): Handle DW_OP_GNU_addr_index.
	(Dwarf::_default_form): Supply a default for DW_AT_GNU_addr_base.
	(Dwarf::_handle_macro_at_range): Use form DW_FORM_GNU_addr_index
	if this is a fission CU.
	(Dwarf::_location): Handle DW_OP_GNU_addr_index.
	(Dwarf::debug_addr_index): New proc.
	(Dwarf::cu): Initialise _cu_is_fission.
	(Dwarf::tu): Likewise.
	(Dwarf::assemble): Initialise _debug_addr_index.
---
 gdb/testsuite/ChangeLog                       |  26 ++
 .../gdb.dwarf2/fission-absolute-dwo.c         |  28 ++
 .../gdb.dwarf2/fission-absolute-dwo.exp       | 132 ++++++++++
 gdb/testsuite/gdb.dwarf2/fission-base.exp     |  11 +-
 .../gdb.dwarf2/fission-loclists-pie.exp       |  11 +-
 gdb/testsuite/gdb.dwarf2/fission-loclists.exp |  11 +-
 gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp |  11 +-
 gdb/testsuite/gdb.dwarf2/fission-reread.exp   |  15 +-
 gdb/testsuite/lib/dwarf.exp                   | 248 ++++++++++++++----
 9 files changed, 423 insertions(+), 70 deletions(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp

diff --git a/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
new file mode 100644
index 00000000000..27f7f0dfb4b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   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/>.  */
+
+/* Our fake object.  */
+int global_var[100];
+
+int
+main (int argc, char **argv)
+{
+  asm ("main_label: .globl main_label");
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
new file mode 100644
index 00000000000..78c04225144
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
@@ -0,0 +1,132 @@
+# 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/>.
+
+# This is a basic first test for using the testsuite's Dwarf assembler to
+# create split debug information.  There's not unique feature of GDB being
+# tested here, this exists only as a basic test for the testsuite
+# infrastructure.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+standard_testfile .c -dw.S
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    global srcfile binfile objdir
+
+    set debug_addr_base -1
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture the current index into .debug_addr so we can fill in
+	# DW_AT_GNU_addr_base later.
+	set debug_addr_base [debug_addr_index]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+        } {
+	    declare_labels int4_type struct_type
+
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      integer}
+	    }
+
+	    struct_type: DW_TAG_structure_type {
+		{DW_AT_name "foo_t"}
+		{DW_AT_byte_size 12 DW_FORM_sdata}
+	    } {
+		member {
+		    {name "aa"}
+		    {type :$int4_type}
+		    {data_member_location 0 data1}
+		}
+		member {
+		    {name "bb"}
+		    {type :$int4_type}
+		    {data_member_location 4 data1}
+		}
+		member {
+		    {name "cc"}
+		    {type :$int4_type}
+		    {data_member_location 8 data1}
+		}
+	    }
+
+	    DW_TAG_variable {
+		{DW_AT_name global_var}
+		{DW_AT_type :$struct_type}
+		{DW_AT_location {
+		    DW_OP_GNU_addr_index [gdb_target_symbol global_var]
+		} SPECIAL_expr}
+		{external 1 flag}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name main DW_FORM_string}
+		{MACRO_AT_func {main}}
+	    }
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${binfile}.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_base}
+        } {
+	    # Nothing.
+	}
+    }
+}
+
+# Compile both source files to create the executable.  As we compile
+# ASM_FILE we split out the debug information into the dwo file.
+set object_file [standard_output_file ${testfile}.o]
+if { [build_executable_and_dwo_files "${testfile}.exp" ${binfile} {nodebug} \
+	  [list $asm_file {nodebug split-dwo} ${object_file}] \
+	  [list $srcfile {nodebug}]] } {
+    perror "failed to compile ${gdb_test_file_name}"
+    return -1
+}
+
+# Now we can start GDB.
+clean_restart ${testfile}
+
+if ![runto_main] {
+    return -1
+}
+
+# Print the type of global_var.  This type information is entirely
+# fictional, it only exists in the DWARF.  If we don't have the DWARF
+# information then there's no way we can print this.
+gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
diff --git a/gdb/testsuite/gdb.dwarf2/fission-base.exp b/gdb/testsuite/gdb.dwarf2/fission-base.exp
index 40a7e2a4e3c..00eb7fec1b0 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-base.exp
@@ -32,11 +32,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-base.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $srcfile \
+	     [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
index c0a7785985b..21098a24624 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
@@ -37,11 +37,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-loclists-pie.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list "nodebug" "ldflags=-pie" additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" \
+	{nodebug ldflags=-pie} \
+	[list $srcfile [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
index 54eace0496c..c490763982e 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
@@ -32,11 +32,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-loclists.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $srcfile \
+	     [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
index dec754798b6..d3685f883dc 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
@@ -32,11 +32,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-multi-cu.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $srcfile \
+	     [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-reread.exp b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
index 58132794ee7..16a139eb0cd 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-reread.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
@@ -30,17 +30,20 @@ set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-reread.dwo"]
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
 
-set options [list]
-lappend options nodebug
+set options [list nodebug]
 if { $additional_flags != "" } {
     lappend options $additional_flags
 }
-lappend options additional_flags=-DDWO=$dwo
 
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" $options] {
+set dwo_options $options
+lappend dwo_options split-dwo
+lappend dwo_options additional_flags=-DDWO=$dwo
+
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" $options \
+	[list $srcfile $dwo_options $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 4cd5e16c604..d30a6c965d0 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -28,39 +28,12 @@ proc dwarf2_support {} {
     return 0
 }
 
-# Build an executable from a fission-based .S file.
-# This handles the extra work of splitting the .o into non-dwo and dwo
-# pieces, making sure the .dwo is available if we're using cc-with-tweaks.sh
-# to build a .dwp file.
-# The arguments and results are the same as for build_executable.
+# Use 'objcopy --extract-dwo to extract DWO information from
+# OBJECT_FILE and place it into DWO_FILE.
 #
-# Current restrictions:
-# - only supports one source file
-# - cannot be run on remote hosts
-
-proc build_executable_from_fission_assembler { testname executable sources options } {
-    verbose -log "build_executable_from_fission_assembler $testname $executable $sources $options"
-    if { [llength $sources] != 1 } {
-	error "Only one source file supported."
-    }
-    if [is_remote host] {
-	error "Remote hosts are not supported."
-    }
-
-    global srcdir subdir
-    set source_file ${srcdir}/${subdir}/${sources}
-    set root_name [file rootname [file tail $source_file]]
-    set output_base [standard_output_file $root_name]
-    set object_file ${output_base}.o
-    set dwo_file ${output_base}.dwo
-    set object_options "object $options"
+# Return 0 on success, otherwise, return -1.
+proc extract_dwo_information { object_file dwo_file } {
     set objcopy [gdb_find_objcopy]
-
-    set result [gdb_compile $source_file $object_file object $options]
-    if { "$result" != "" } {
-	return -1
-    }
-
     set command "$objcopy --extract-dwo $object_file $dwo_file"
     verbose -log "Executing $command"
     set result [catch "exec $command" output]
@@ -68,20 +41,154 @@ proc build_executable_from_fission_assembler { testname executable sources optio
     if { $result == 1 } {
 	return -1
     }
+    return 0
+}
 
-    set command "$objcopy --strip-dwo $object_file"
+# Use 'objcopy --strip-dwo to remove DWO information from
+# FILENAME.
+#
+# Return 0 on success, otherwise, return -1.
+proc strip_dwo_information { filename } {
+    set objcopy [gdb_find_objcopy]
+    set command "$objcopy --strip-dwo $filename"
     verbose -log "Executing $command"
     set result [catch "exec $command" output]
     verbose -log "objcopy --strip-dwo output: $output"
     if { $result == 1 } {
 	return -1
     }
+    return 0
+}
+
+# Build an executable, with the debug information split out into a
+# separate .dwo file.
+#
+# This function is based on build_executable_from_specs in
+# lib/gdb.exp, but with threading support, and rust support removed.
+#
+# TESTNAME is the name of the test; this is passed to 'untested' if
+# something fails.
+#
+# EXECUTABLE is the executable to create, this can be an absolute
+# path, or a relative path, in which case the EXECUTABLE will be
+# created in the standard output directory.
+#
+# OPTIONS is passed to the final link, using gdb_compile.  If OPTIONS
+# contains any option that indicates threads is required, of if the
+# option rust is included, then this function will return failure.
+#
+# ARGS is a series of lists.  Each list is a spec for one source file
+# that will be compiled to make EXECUTABLE.  Each spec in ARGS has the
+# form:
+#	[ SOURCE OPTIONS ]
+# or:
+#       [ SOURCE OPTIONS OBJFILE ]
+#
+# Where SOURCE is the path to the source file to compile.  This can be
+# absolute, or relative to the standard global ${subdir}/${srcdir}/
+# path.
+#
+# OPTIONS are the options to use when compiling SOURCE into an object
+# file.
+#
+# OBJFILE is optional, if present this is the name of the object file
+# to create for SOURCE.  If this is not provided then a suitable name
+# will be auto-generated.
+#
+# If OPTIONS contains the option 'split-dwo' then the debug
+# information is extracted from the object file created by compiling
+# SOURCE and placed into a file with a dwo extension.  The name of
+# this file is generated based on the name of the object file that was
+# created (with the .o replaced with .dwo).
+proc build_executable_and_dwo_files { testname executable options args } {
+    global subdir
+    global srcdir
+
+    if { ! [regexp "^/" "$executable"] } then {
+	set binfile [standard_output_file $executable]
+    } else {
+	set binfile $executable
+    }
+
+    set info_options ""
+    if { [lsearch -exact $options "c++"] >= 0 } {
+	set info_options "c++"
+    }
+    if [get_compiler_info ${info_options}] {
+        return -1
+    }
+
+    set func gdb_compile
+    if {[lsearch -regexp $options \
+	     {^(pthreads|shlib|shlib_pthreads|openmp)$}] != -1} {
+	# Currently don't support compiling thread based tests here.
+	# If this is required then look to build_executable_from_specs
+	# for inspiration.
+	return -1
+    }
+    if {[lsearch -exact $options rust] != -1} {
+	# Currently don't support compiling rust tests here.  If this
+	# is required then look to build_executable_from_specs for
+	# inspiration.
+	return -1
+    }
 
-    set result [gdb_compile $object_file $executable executable $options]
-    if { "$result" != "" } {
+    # Must be run on local host due to use of objcopy.
+    if [is_remote host] {
 	return -1
     }
 
+    set objects {}
+    set i 0
+    foreach spec $args {
+	if {[llength $spec] < 2} {
+	    error "invalid spec length"
+	    return -1
+	}
+
+	set s [lindex $spec 0]
+	set local_options [lindex $spec 1]
+
+	if { ! [regexp "^/" "$s"] } then {
+	    set s "$srcdir/$subdir/$s"
+	}
+
+	if {[llength $spec] > 2} {
+	    set objfile [lindex $spec 2]
+	} else {
+	    set objfile "${binfile}${i}.o"
+	    incr i
+	}
+
+	if  { [$func "${s}" "${objfile}" object $local_options] != "" } {
+	    untested $testname
+	    return -1
+	}
+
+	lappend objects "$objfile"
+
+	if {[lsearch -exact $local_options "split-dwo"] >= 0} {
+	    # Split out the DWO file.
+	    set dwo_file "[file rootname ${objfile}].dwo"
+
+	    if { [extract_dwo_information $objfile $dwo_file] == -1 } {
+		untested $testname
+		return -1
+	    }
+
+	    if { [strip_dwo_information $objfile] == -1 } {
+		untested $testname
+		return -1
+	    }
+	}
+    }
+
+    set ret [$func $objects "${binfile}" executable $options]
+    if  { $ret != "" } {
+        untested $testname
+        return -1
+    }
+
     return 0
 }
 
@@ -329,6 +436,14 @@ namespace eval Dwarf {
     # The address size for debug ranges section.
     variable _debug_ranges_64_bit
 
+    # The index into the .debug_addr section (used for fission
+    # generation).
+    variable _debug_addr_index
+
+    # Flag, true if the current CU is contains fission information,
+    # otherwise false.
+    variable _cu_is_fission
+
     proc _process_one_constant {name value} {
 	variable _constants
 	variable _AT
@@ -486,6 +601,18 @@ namespace eval Dwarf {
 		_op .${_cu_addr_size}byte $value
 	    }
 
+	    DW_FORM_GNU_addr_index {
+		variable _debug_addr_index
+		variable _cu_addr_size
+
+		_op .uleb128 ${_debug_addr_index}
+		incr _debug_addr_index
+
+		_defer_output .debug_addr {
+		    _op .${_cu_addr_size}byte $value
+		}
+	    }
+
 	    DW_FORM_data2 -
 	    DW_FORM_ref2 {
 		_op .2byte $value
@@ -553,7 +680,6 @@ namespace eval Dwarf {
 	    DW_FORM_strx3 -
 	    DW_FORM_strx4 -
 
-	    DW_FORM_GNU_addr_index -
 	    DW_FORM_GNU_str_index -
 
 	    default {
@@ -609,6 +735,9 @@ namespace eval Dwarf {
 	    DW_AT_name {
 		return DW_FORM_string
 	    }
+	    DW_AT_GNU_addr_base {
+		return DW_FORM_sec_offset
+	    }
 	}
 	return ""
     }
@@ -649,6 +778,8 @@ namespace eval Dwarf {
     # Handle macro attribute MACRO_AT_range.
 
     proc _handle_macro_at_range { attr_value } {
+	variable _cu_is_fission
+
 	if {[llength $attr_value] != 1} {
 	    error "usage: MACRO_AT_range { func }"
 	}
@@ -658,10 +789,14 @@ namespace eval Dwarf {
 	set src ${srcdir}/${subdir}/${srcfile}
 	set result [function_range $func $src]
 
-	_handle_attribute DW_AT_low_pc [lindex $result 0] \
-	    DW_FORM_addr
+	set form DW_FORM_addr
+	if { $_cu_is_fission } {
+	    set form DW_FORM_GNU_addr_index
+	}
+
+	_handle_attribute DW_AT_low_pc [lindex $result 0] $form
 	_handle_attribute DW_AT_high_pc \
-	    "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
+	    "[lindex $result 0] + [lindex $result 1]" $form
     }
 
     # Handle macro attribute MACRO_AT_func.
@@ -929,6 +1064,18 @@ namespace eval Dwarf {
 		    _op .${addr_size}byte [lindex $line 1]
 		}
 
+		DW_OP_GNU_addr_index {
+		    variable _debug_addr_index
+		    variable _cu_addr_size
+
+		    _op .uleb128 ${_debug_addr_index}
+		    incr _debug_addr_index
+
+		    _defer_output .debug_addr {
+			_op .${_cu_addr_size}byte [lindex $line 1]
+		    }
+		}
+
 		DW_OP_regx {
 		    _op .uleb128 [lindex $line 1]
 		}
@@ -1050,6 +1197,14 @@ namespace eval Dwarf {
 	}
     }
 
+    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
+    # of this function can be used for the value of
+    # DW_AT_GNU_addr_base.
+    proc debug_addr_index {} {
+	variable _debug_addr_index
+	return ${_debug_addr_index}
+    }
+
     # Emit a DWARF CU.
     # OPTIONS is a list with an even number of elements containing
     # option-name and option-value pairs.
@@ -1073,12 +1228,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_info"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1088,7 +1244,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1100,7 +1256,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_info.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -1180,12 +1336,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_types"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1194,7 +1351,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1206,7 +1363,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_types.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -2056,6 +2213,7 @@ namespace eval Dwarf {
 	variable _line_saw_program
 	variable _line_header_end_label
 	variable _debug_ranges_64_bit
+	variable _debug_addr_index
 
 	if {!$_initialized} {
 	    _read_constants
@@ -2074,6 +2232,8 @@ namespace eval Dwarf {
 	set _line_saw_program 0
 	set _debug_ranges_64_bit [is_64_target]
 
+	set _debug_addr_index 0
+
 	# Not "uplevel" here, because we want to evaluate in this
 	# namespace.  This is somewhat bad because it means we can't
 	# readily refer to outer variables.
-- 
2.25.4


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCHv3 2/2] gdb: handle relative paths to DWO files
  2021-03-26 17:54           ` [PATCHv3 0/2] " Andrew Burgess
  2021-03-26 17:54             ` [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler Andrew Burgess
@ 2021-03-26 17:54             ` Andrew Burgess
  2021-04-01 16:42               ` Tom Tromey
  2021-03-31 15:57             ` [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files Caroline Tice
  2 siblings, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2021-03-26 17:54 UTC (permalink / raw)
  To: gdb-patches

DWARF allows .dwo file paths to be relative rather than absolute.

When they are relative, DWARF uses DW_AT_comp_dir to find the .dwo
file.  DW_AT_comp_dir can also be relative, making the entire search
patch for the .dwo file relative.

In this case, GDB currently searches relative to its current working
directory, i.e. the directory from which the debugger was launched,
but not relative to the directory containing the built binary.  This
cannot be right, as the compiler, when generating the relative paths,
knows where it's building the binary but can have no idea where the
debugger will be launched.

The correct thing is to add the directory containing the binary to the
search paths used for resolving relative locations of dwo files. That
is what this patch does.

gdb/ChangeLog:

	* dwarf2/read.c (try_open_dwop_file): Add path for the binary to
	the search paths used resolve relative location of .dwo file.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/fission-relative-dwo.c: New file.
	* gdb.dwarf2/fission-relative-dwo.exp: New file.
---
 gdb/ChangeLog                                 |   5 +
 gdb/dwarf2/read.c                             |   7 +
 gdb/testsuite/ChangeLog                       |   5 +
 .../gdb.dwarf2/fission-relative-dwo.c         |  28 ++++
 .../gdb.dwarf2/fission-relative-dwo.exp       | 130 ++++++++++++++++++
 5 files changed, 175 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
 create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ee6f3f7f7e1..2b208f69970 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12721,6 +12721,13 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
   else
     search_path = debug_file_directory;
 
+  /* Add the path for the executable binary to the list of search paths.  */
+  std::string objfile_dir = ldirname (objfile_name (per_objfile->objfile));
+  search_path_holder.reset (concat (objfile_dir.c_str (),
+				    dirname_separator_string,
+				    search_path, nullptr));
+  search_path = search_path_holder.get ();
+
   openp_flags flags = OPF_RETURN_REALPATH;
   if (is_dwp)
     flags |= OPF_SEARCH_IN_PATH;
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
new file mode 100644
index 00000000000..27f7f0dfb4b
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   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/>.  */
+
+/* Our fake object.  */
+int global_var[100];
+
+int
+main (int argc, char **argv)
+{
+  asm ("main_label: .globl main_label");
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
new file mode 100644
index 00000000000..66afa3f6a96
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
@@ -0,0 +1,130 @@
+# 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/>.
+
+# This test checks that GDB can find the dwo file when the path to the
+# dwo embedded in the executable is relative.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+standard_testfile .c -dw.S
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    global srcfile gdb_test_file_name
+
+    set debug_addr_base -1
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture the current index into .debug_addr so we can fill in
+	# DW_AT_GNU_addr_base later.
+	set debug_addr_base [debug_addr_index]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir .}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+        } {
+	    declare_labels int4_type struct_type
+
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      integer}
+	    }
+
+	    struct_type: DW_TAG_structure_type {
+		{DW_AT_name "foo_t"}
+		{DW_AT_byte_size 12 DW_FORM_sdata}
+	    } {
+		member {
+		    {name "aa"}
+		    {type :$int4_type}
+		    {data_member_location 0 data1}
+		}
+		member {
+		    {name "bb"}
+		    {type :$int4_type}
+		    {data_member_location 4 data1}
+		}
+		member {
+		    {name "cc"}
+		    {type :$int4_type}
+		    {data_member_location 8 data1}
+		}
+	    }
+
+	    DW_TAG_variable {
+		{DW_AT_name global_var}
+		{DW_AT_type :$struct_type}
+		{DW_AT_location {
+		    DW_OP_GNU_addr_index [gdb_target_symbol global_var]
+		} SPECIAL_expr}
+		{external 1 flag}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name main DW_FORM_string}
+		{MACRO_AT_func {main}}
+	    }
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${gdb_test_file_name}.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir .}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_base}
+        } {
+	    # Nothing.
+	}
+    }
+}
+
+# Compile both source files to create the executable.  As we compile
+# ASM_FILE we split out the debug information into the dwo file.
+set object_file [standard_output_file ${testfile}.o]
+if { [build_executable_and_dwo_files "${testfile}.exp" ${testfile} {nodebug} \
+	  [list $asm_file {nodebug split-dwo} ${object_file}] \
+	  [list $srcfile {nodebug}]] } {
+    perror "failed to compile ${gdb_test_file_name}"
+    return -1
+}
+
+# Now we can start GDB.
+clean_restart ${testfile}
+
+if ![runto_main] {
+    return -1
+}
+
+# Print the type of global_var.  This type information is entirely
+# fictional, it only exists in the DWARF.  If we don't have the DWARF
+# information then there's no way we can print this.
+gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
-- 
2.25.4


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler
  2021-03-26 17:54             ` [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler Andrew Burgess
@ 2021-03-29 16:30               ` Simon Marchi
  2021-03-30 11:07                 ` Andrew Burgess
  0 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2021-03-29 16:30 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2021-03-26 1:54 p.m., Andrew Burgess wrote:
> This commit fixes fission support in the Dwarf assembler.  The new
> test gdb.dwarf2/fission-absolute-dwo.exp which exercises this
> feature.
> 
> To better support compiling the assembler files produced by the Dwarf
> assembler I have added the new proc build_executable_and_dwo_files in
> lib/dwarf.exp, this replaces build_executable_from_fission_assembler,
> all the tests that used the old proc have been updated.  Where the old
> proc assumed a single .S source file which contained the entire test,
> the new proc allows for multiple source files.
> 
> The Dwarf assembler already had some fission support, however, this
> was not actually used in any tests, and when I tried using it there
> were a few issues.
> 
> The biggest change is that we now generate DW_FORM_GNU_addr_index
> instead of DW_FORM_addr for the low and high pc in
> _handle_macro_at_range, support for the DW_FORM_GNU_addr_index is new
> in this commit.

Is it possible to make tests that produce multiple CUs, and if so, is
the DW_AT_GNU_addr_base attribute correctly generated for both CUs?

> @@ -1050,6 +1197,14 @@ namespace eval Dwarf {
>  	}
>      }
>  
> +    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
> +    # of this function can be used for the value of
> +    # DW_AT_GNU_addr_base.
> +    proc debug_addr_index {} {
> +	variable _debug_addr_index
> +	return ${_debug_addr_index}
> +    }

In the comment: do you really mean DW_AT_GNU_addr_base?  You probably
meant attributes for form DW_FORM_GNU_addr_index, or operator
DW_OP_GNU_addr_index.

Simon

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler
  2021-03-29 16:30               ` Simon Marchi
@ 2021-03-30 11:07                 ` Andrew Burgess
  2021-04-01 16:41                   ` Tom Tromey
  0 siblings, 1 reply; 17+ messages in thread
From: Andrew Burgess @ 2021-03-30 11:07 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi <simon.marchi@polymtl.ca> [2021-03-29 12:30:04 -0400]:

> On 2021-03-26 1:54 p.m., Andrew Burgess wrote:
> > This commit fixes fission support in the Dwarf assembler.  The new
> > test gdb.dwarf2/fission-absolute-dwo.exp which exercises this
> > feature.
> > 
> > To better support compiling the assembler files produced by the Dwarf
> > assembler I have added the new proc build_executable_and_dwo_files in
> > lib/dwarf.exp, this replaces build_executable_from_fission_assembler,
> > all the tests that used the old proc have been updated.  Where the old
> > proc assumed a single .S source file which contained the entire test,
> > the new proc allows for multiple source files.
> > 
> > The Dwarf assembler already had some fission support, however, this
> > was not actually used in any tests, and when I tried using it there
> > were a few issues.
> > 
> > The biggest change is that we now generate DW_FORM_GNU_addr_index
> > instead of DW_FORM_addr for the low and high pc in
> > _handle_macro_at_range, support for the DW_FORM_GNU_addr_index is new
> > in this commit.
> 
> Is it possible to make tests that produce multiple CUs, and if so, is
> the DW_AT_GNU_addr_base attribute correctly generated for both CUs?

I had thought it was, but, I hadn't really thought it through
properly, so it wouldn't have worked. I've now fixed this so that it
should work.

What we can't do is create multiple CUs in a single .S file, I just
can't see how that would work given that it's the CU that links to the
.dwo file.

But we can create multiple .S files, each is then compiled to a .o
from which we create a .dwo file.  Then all the .o files are linked
together to create one executable that references multiple .dwo
files.

The test gdb.dwarf2/fission-multi-cu.exp used to use a pre-generated
x86-64 assembler file.  As part of this patch I have rewritten this
test to generate the DWARF using the Dwarf assembler, this is now an
example of what I describe above.  I've kept the new test
gdb.dwarf2/fission-absolute-dwo.exp as this is a simpler example and
might be an easier starting point for anyone looking for something to
copy.

> 
> > @@ -1050,6 +1197,14 @@ namespace eval Dwarf {
> >  	}
> >      }
> >  
> > +    # Return the current value of _DEBUG_ADDR_INDEX.  The return value
> > +    # of this function can be used for the value of
> > +    # DW_AT_GNU_addr_base.
> > +    proc debug_addr_index {} {
> > +	variable _debug_addr_index
> > +	return ${_debug_addr_index}
> > +    }
> 
> In the comment: do you really mean DW_AT_GNU_addr_base?  You probably
> meant attributes for form DW_FORM_GNU_addr_index, or operator
> DW_OP_GNU_addr_index.

This is the proc I changed to fix the above issue, it's now called
debug_addr_label, and returns a label into the .debug_addr section.

I've updated the comment, but it mostly says the same as it did
before.

The point here is that the user will have code that looks like this:

  Dwarf::assemble $asm_file {
      cu {fission 1} {
        ...
      }
      cu {} {
        ...
     }
  }

This creates a single assembler file containing the dwo sections AND
the non-dwo sections.  Addresses in the dwo section are placed into
the .debug_addr section.  The non-fission CU will include a link to
the start of the .debug_addr section within its contained compilation
unit.

So, within 'cu {fission 1} { .... }' before we start adding things into
.debug_addr, we capture a label for the current start of .debug_addr.
Then in 'cu {} { ... }' we can use this label, like this:

  Dwarf::assemble $asm_file {
      cu {fission 1} {
  	set debug_addr_base [debug_addr_label]
          ...
      }
      cu {} {
  	compile_unit {
              ...
  	    {DW_AT_GNU_addr_base $debug_addr_base}
          }
     }
  }

I don't know if that actually answers your question, or maybe I've not
understood what you're asking me?

Anyway, revised patch below, let me know what you think.

[ NOTE: Patch #2 requires a minor change to call debug_addr_label
  instead of debug_addr_index.  I've not reposted patch #2 you would
  need to make that change manually if you're testing it. ]

Thanks,
Andrew

----

commit 081199e14bd799b3adc82f4758e2d2906e05d6f7
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Fri Mar 26 12:06:37 2021 +0000

    gdb/testsuite: fix fission support in the Dwarf assembler
    
    This commit fixes fission support in the Dwarf assembler. I added the
    new test gdb.dwarf2/fission-absolute-dwo.exp which is a simple example
    of using the fission support.  I also rewrote the existing test
    gdb.dwarf2/fission-multi-cu.exp to use the new functionality (instead
    of using an x86-64 only assembler file).
    
    To better support compiling the assembler files produced by the Dwarf
    assembler I have added the new proc build_executable_and_dwo_files in
    lib/dwarf.exp, this replaces build_executable_from_fission_assembler,
    all the tests that used the old proc have been updated.  Where the old
    proc assumed a single .S source file which contained the entire test,
    the new proc allows for multiple source files.
    
    The Dwarf assembler already had some fission support, however, this
    was not actually used in any tests, and when I tried using it there
    were a few issues.
    
    The biggest change is that we now generate DW_FORM_GNU_addr_index
    instead of DW_FORM_addr for the low and high pc in
    _handle_macro_at_range, support for the DW_FORM_GNU_addr_index is new
    in this commit.
    
    gdb/testsuite/ChangeLog:
    
            * gdb.dwarf2/fission-absolute-dwo.c: New file.
            * gdb.dwarf2/fission-absolute-dwo.exp: New file.
            * gdb.dwarf2/fission-base.exp: Use build_executable_and_dwo_files
            instead of build_executable_from_fission_assembler.
            * gdb.dwarf2/fission-loclists-pie.exp: Likewise.
            * gdb.dwarf2/fission-loclists.exp: Likewise.

diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu2.c b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
similarity index 71%
rename from gdb/testsuite/gdb.dwarf2/fission-multi-cu2.c
rename to gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
index 6f0ed1f5ae9..27f7f0dfb4b 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu2.c
+++ b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
@@ -1,6 +1,6 @@
 /* This testcase is part of GDB, the GNU debugger.
 
-   Copyright 2012-2021 Free Software Foundation, Inc.
+   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
@@ -13,12 +13,16 @@
    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/>.  */
+   along with this program.  If not, see
+   <http://www.gnu.org/licenses/>.  */
 
-void func ();
+/* Our fake object.  */
+int global_var[100];
 
 int
-main ()
+main (int argc, char **argv)
 {
-  func (-1);
+  asm ("main_label: .globl main_label");
+
+  return 0;
 }
diff --git a/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
new file mode 100644
index 00000000000..2483349bf78
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
@@ -0,0 +1,133 @@
+# 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/>.
+
+# This is a basic first test for using the testsuite's Dwarf assembler to
+# create split debug information.  There's not unique feature of GDB being
+# tested here, this exists only as a basic test for the testsuite
+# infrastructure.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if {![dwarf2_support]} {
+    return 0
+}
+
+standard_testfile .c -dw.S
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+    return -1
+}
+
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+    global srcfile binfile objdir
+
+    set debug_addr_lbl ".unknown!!"
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture a label to the current start of the .debug_addr
+	# section.  This will be passed to DW_AT_GNU_addr_base in the
+	# non-split CU later.
+	set debug_addr_lbl [debug_addr_label]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+        } {
+	    declare_labels int4_type struct_type
+
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      integer}
+	    }
+
+	    struct_type: DW_TAG_structure_type {
+		{DW_AT_name "foo_t"}
+		{DW_AT_byte_size 12 DW_FORM_sdata}
+	    } {
+		member {
+		    {name "aa"}
+		    {type :$int4_type}
+		    {data_member_location 0 data1}
+		}
+		member {
+		    {name "bb"}
+		    {type :$int4_type}
+		    {data_member_location 4 data1}
+		}
+		member {
+		    {name "cc"}
+		    {type :$int4_type}
+		    {data_member_location 8 data1}
+		}
+	    }
+
+	    DW_TAG_variable {
+		{DW_AT_name global_var}
+		{DW_AT_type :$struct_type}
+		{DW_AT_location {
+		    DW_OP_GNU_addr_index [gdb_target_symbol global_var]
+		} SPECIAL_expr}
+		{external 1 flag}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name main DW_FORM_string}
+		{MACRO_AT_func {main}}
+	    }
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${binfile}.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_lbl}
+        } {
+	    # Nothing.
+	}
+    }
+}
+
+# Compile both source files to create the executable.  As we compile
+# ASM_FILE we split out the debug information into the dwo file.
+set object_file [standard_output_file ${testfile}.o]
+if { [build_executable_and_dwo_files "${testfile}.exp" ${binfile} {nodebug} \
+	  [list $asm_file {nodebug split-dwo} ${object_file}] \
+	  [list $srcfile {nodebug}]] } {
+    perror "failed to compile ${gdb_test_file_name}"
+    return -1
+}
+
+# Now we can start GDB.
+clean_restart ${testfile}
+
+if ![runto_main] {
+    return -1
+}
+
+# Print the type of global_var.  This type information is entirely
+# fictional, it only exists in the DWARF.  If we don't have the DWARF
+# information then there's no way we can print this.
+gdb_test "p global_var" " = \\{aa = 0, bb = 0, cc = 0\\}"
diff --git a/gdb/testsuite/gdb.dwarf2/fission-base.exp b/gdb/testsuite/gdb.dwarf2/fission-base.exp
index 40a7e2a4e3c..00eb7fec1b0 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-base.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-base.exp
@@ -32,11 +32,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-base.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $srcfile \
+	     [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
index c0a7785985b..21098a24624 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists-pie.exp
@@ -37,11 +37,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-loclists-pie.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list "nodebug" "ldflags=-pie" additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" \
+	{nodebug ldflags=-pie} \
+	[list $srcfile [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
index 54eace0496c..c490763982e 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-loclists.exp
@@ -32,11 +32,12 @@ if {![istarget x86_64-*] || ![is_lp64_target]} {
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-loclists.dwo"]
-
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $srcfile \
+	     [list nodebug split-dwo additional_flags=-DDWO=$dwo] \
+	     $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.S b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.S
deleted file mode 100644
index df83613831e..00000000000
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.S
+++ /dev/null
@@ -1,364 +0,0 @@
-/* This testcase is part of GDB, the GNU debugger.
-
-   Copyright 2012-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/>.
-
-   This file was created by doing:
-
-   clang fission-multi-cu*.c -g -fno-split-dwarf-inlining -emit-llvm -S -c
-   llvm-link fission-multi-cu*.ll -S -o fission-multi-cu.ll
-   clang-tot fission-multi-cu.ll -gsplit-dwarf -S
-
-   and then massaging the output.
-*/
-
-#define XSTR(s) STR(s)
-#define STR(s) #s
-
-	.text
-	.file	"llvm-link"
-	.globl	func
-	.p2align	4, 0x90
-	.type	func,@function
-func:                                   # @func
-.Lfunc_begin0:
-	.file	1 "fission-multi-cu1.c"
-	.loc	1 20 0                  # fission-multi-cu1.c:20:0
-	.cfi_startproc
-# BB#0:                                 # %entry
-	pushq	%rbp
-	.cfi_def_cfa_offset 16
-	.cfi_offset %rbp, -16
-	movq	%rsp, %rbp
-	.cfi_def_cfa_register %rbp
-	movl	%edi, -4(%rbp)
-	.loc	1 21 10 prologue_end    # fission-multi-cu1.c:21:10
-	movl	-4(%rbp), %edi
-	.loc	1 21 14 is_stmt 0       # fission-multi-cu1.c:21:14
-	addl	$1, %edi
-	.loc	1 21 3                  # fission-multi-cu1.c:21:3
-	movl	%edi, %eax
-	popq	%rbp
-	retq
-.Lfunc_end0:
-	.size	func, .Lfunc_end0-func
-	.cfi_endproc
-
-	.globl	main
-	.p2align	4, 0x90
-	.type	main,@function
-main:                                   # @main
-.Lfunc_begin1:
-	.file	2 "fission-multi-cu2.c"
-	.loc	2 23 0 is_stmt 1        # fission-multi-cu2.c:23:0
-	.cfi_startproc
-# BB#0:                                 # %entry
-	pushq	%rbp
-	.cfi_def_cfa_offset 16
-	.cfi_offset %rbp, -16
-	movq	%rsp, %rbp
-	.cfi_def_cfa_register %rbp
-	movl	$4294967295, %edi       # imm = 0xFFFFFFFF
-	.loc	2 24 3 prologue_end     # fission-multi-cu2.c:24:3
-	movb	$0, %al
-	callq	func
-	xorl	%eax, %eax
-	.loc	2 25 1                  # fission-multi-cu2.c:25:1
-	popq	%rbp
-	retq
-.Lfunc_end1:
-	.size	main, .Lfunc_end1-main
-	.cfi_endproc
-
-	.section	.debug_str,"MS",@progbits,1
-.Lskel_string0:
-	.asciz	XSTR(DWO)  # string offset=0
-.Lskel_string1:
-	.asciz	"/tmp/src/gdb/testsuite" # string offset=21
-	.section	.debug_loc.dwo,"",@progbits
-	.section	.debug_abbrev,"",@progbits
-	.byte	1                       # Abbreviation Code
-	.byte	17                      # DW_TAG_compile_unit
-	.byte	0                       # DW_CHILDREN_no
-	.byte	16                      # DW_AT_stmt_list
-	.byte	23                      # DW_FORM_sec_offset
-	.ascii	"\260B"                 # DW_AT_GNU_dwo_name
-	.byte	14                      # DW_FORM_strp
-	.byte	27                      # DW_AT_comp_dir
-	.byte	14                      # DW_FORM_strp
-	.ascii	"\261B"                 # DW_AT_GNU_dwo_id
-	.byte	7                       # DW_FORM_data8
-	.ascii	"\263B"                 # DW_AT_GNU_addr_base
-	.byte	23                      # DW_FORM_sec_offset
-	.byte	17                      # DW_AT_low_pc
-	.byte	1                       # DW_FORM_addr
-	.byte	18                      # DW_AT_high_pc
-	.byte	6                       # DW_FORM_data4
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	0                       # EOM(3)
-	.section	.debug_info,"",@progbits
-.Lcu_begin0:
-	.long	44                      # Length of Unit
-	.short	4                       # DWARF version number
-	.long	.debug_abbrev           # Offset Into Abbrev. Section
-	.byte	8                       # Address Size (in bytes)
-	.byte	1                       # Abbrev [1] 0xb:0x25 DW_TAG_compile_unit
-	.long	.Lline_table_start0     # DW_AT_stmt_list
-	.long	.Lskel_string0          # DW_AT_GNU_dwo_name
-	.long	.Lskel_string1          # DW_AT_comp_dir
-	.quad	7615852067747431413     # DW_AT_GNU_dwo_id
-	.long	.debug_addr             # DW_AT_GNU_addr_base
-	.quad	.Lfunc_begin0           # DW_AT_low_pc
-	.long	.Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
-.Lcu_begin1:
-	.long	44                      # Length of Unit
-	.short	4                       # DWARF version number
-	.long	.debug_abbrev           # Offset Into Abbrev. Section
-	.byte	8                       # Address Size (in bytes)
-	.byte	1                       # Abbrev [1] 0xb:0x25 DW_TAG_compile_unit
-	.long	.Lline_table_start0     # DW_AT_stmt_list
-	.long	.Lskel_string0          # DW_AT_GNU_dwo_name
-	.long	.Lskel_string1          # DW_AT_comp_dir
-	.quad	2037650261599692324     # DW_AT_GNU_dwo_id
-	.long	.debug_addr             # DW_AT_GNU_addr_base
-	.quad	.Lfunc_begin1           # DW_AT_low_pc
-	.long	.Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
-	.section	.debug_ranges,"",@progbits
-	.section	.debug_macinfo,"",@progbits
-.Lcu_macro_begin1:
-.Lcu_macro_begin3:
-	.byte	0                       # End Of Macro List Mark
-	.section	.debug_str.dwo,"MS",@progbits,1
-.Linfo_string0:
-	.asciz	"fission-multi-cu.dwo"  # string offset=0
-.Linfo_string1:
-	.asciz	"clang version 5.0.0 (trunk 302855) (llvm/trunk 302853)" # string offset=21
-.Linfo_string2:
-	.asciz	"fission-multi-cu1.c" # string offset=76
-.Linfo_string3:
-	.asciz	"fission-multi-cu2.c" # string offset=96
-.Linfo_string4:
-	.asciz	"func"                  # string offset=116
-.Linfo_string5:
-	.asciz	"int"                   # string offset=121
-.Linfo_string6:
-	.asciz	"main"                  # string offset=125
-.Linfo_string7:
-	.asciz	"arg"                   # string offset=130
-	.section	.debug_str_offsets.dwo,"",@progbits
-	.long	0
-	.long	21
-	.long	76
-	.long	96
-	.long	116
-	.long	121
-	.long	125
-	.long	130
-	.section	.debug_info.dwo,"",@progbits
-	.long	53                      # Length of Unit
-	.short	4                       # DWARF version number
-	.long	0                       # Offset Into Abbrev. Section
-	.byte	8                       # Address Size (in bytes)
-	.byte	1                       # Abbrev [1] 0xb:0x2e DW_TAG_compile_unit
-	.byte	0                       # DW_AT_GNU_dwo_name
-	.byte	1                       # DW_AT_producer
-	.short	12                      # DW_AT_language
-	.byte	2                       # DW_AT_name
-	.quad	7615852067747431413     # DW_AT_GNU_dwo_id
-	.byte	2                       # Abbrev [2] 0x19:0x1b DW_TAG_subprogram
-	.byte	0                       # DW_AT_low_pc
-	.long	.Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
-	.byte	1                       # DW_AT_frame_base
-	.byte	86
-	.byte	4                       # DW_AT_name
-	.byte	1                       # DW_AT_decl_file
-	.byte	19                      # DW_AT_decl_line
-                                        # DW_AT_prototyped
-	.long	52                      # DW_AT_type
-                                        # DW_AT_external
-	.byte	3                       # Abbrev [3] 0x28:0xb DW_TAG_formal_parameter
-	.byte	2                       # DW_AT_location
-	.byte	145
-	.byte	124
-	.byte	7                       # DW_AT_name
-	.byte	1                       # DW_AT_decl_file
-	.byte	19                      # DW_AT_decl_line
-	.long	52                      # DW_AT_type
-	.byte	0                       # End Of Children Mark
-	.byte	4                       # Abbrev [4] 0x34:0x4 DW_TAG_base_type
-	.byte	5                       # DW_AT_name
-	.byte	5                       # DW_AT_encoding
-	.byte	4                       # DW_AT_byte_size
-	.byte	0                       # End Of Children Mark
-	.long	41                      # Length of Unit
-	.short	4                       # DWARF version number
-	.long	0                       # Offset Into Abbrev. Section
-	.byte	8                       # Address Size (in bytes)
-	.byte	1                       # Abbrev [1] 0xb:0x22 DW_TAG_compile_unit
-	.byte	0                       # DW_AT_GNU_dwo_name
-	.byte	1                       # DW_AT_producer
-	.short	12                      # DW_AT_language
-	.byte	3                       # DW_AT_name
-	.quad	2037650261599692324     # DW_AT_GNU_dwo_id
-	.byte	5                       # Abbrev [5] 0x19:0xf DW_TAG_subprogram
-	.byte	1                       # DW_AT_low_pc
-	.long	.Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
-	.byte	1                       # DW_AT_frame_base
-	.byte	86
-	.byte	6                       # DW_AT_name
-	.byte	2                       # DW_AT_decl_file
-	.byte	22                      # DW_AT_decl_line
-	.long	40                      # DW_AT_type
-                                        # DW_AT_external
-	.byte	4                       # Abbrev [4] 0x28:0x4 DW_TAG_base_type
-	.byte	5                       # DW_AT_name
-	.byte	5                       # DW_AT_encoding
-	.byte	4                       # DW_AT_byte_size
-	.byte	0                       # End Of Children Mark
-	.section	.debug_abbrev.dwo,"",@progbits
-	.byte	1                       # Abbreviation Code
-	.byte	17                      # DW_TAG_compile_unit
-	.byte	1                       # DW_CHILDREN_yes
-	.ascii	"\260B"                 # DW_AT_GNU_dwo_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	37                      # DW_AT_producer
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	19                      # DW_AT_language
-	.byte	5                       # DW_FORM_data2
-	.byte	3                       # DW_AT_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.ascii	"\261B"                 # DW_AT_GNU_dwo_id
-	.byte	7                       # DW_FORM_data8
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	2                       # Abbreviation Code
-	.byte	46                      # DW_TAG_subprogram
-	.byte	1                       # DW_CHILDREN_yes
-	.byte	17                      # DW_AT_low_pc
-	.ascii	"\201>"                 # DW_FORM_GNU_addr_index
-	.byte	18                      # DW_AT_high_pc
-	.byte	6                       # DW_FORM_data4
-	.byte	64                      # DW_AT_frame_base
-	.byte	24                      # DW_FORM_exprloc
-	.byte	3                       # DW_AT_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	58                      # DW_AT_decl_file
-	.byte	11                      # DW_FORM_data1
-	.byte	59                      # DW_AT_decl_line
-	.byte	11                      # DW_FORM_data1
-	.byte	39                      # DW_AT_prototyped
-	.byte	25                      # DW_FORM_flag_present
-	.byte	73                      # DW_AT_type
-	.byte	19                      # DW_FORM_ref4
-	.byte	63                      # DW_AT_external
-	.byte	25                      # DW_FORM_flag_present
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	3                       # Abbreviation Code
-	.byte	5                       # DW_TAG_formal_parameter
-	.byte	0                       # DW_CHILDREN_no
-	.byte	2                       # DW_AT_location
-	.byte	24                      # DW_FORM_exprloc
-	.byte	3                       # DW_AT_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	58                      # DW_AT_decl_file
-	.byte	11                      # DW_FORM_data1
-	.byte	59                      # DW_AT_decl_line
-	.byte	11                      # DW_FORM_data1
-	.byte	73                      # DW_AT_type
-	.byte	19                      # DW_FORM_ref4
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	4                       # Abbreviation Code
-	.byte	36                      # DW_TAG_base_type
-	.byte	0                       # DW_CHILDREN_no
-	.byte	3                       # DW_AT_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	62                      # DW_AT_encoding
-	.byte	11                      # DW_FORM_data1
-	.byte	11                      # DW_AT_byte_size
-	.byte	11                      # DW_FORM_data1
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	5                       # Abbreviation Code
-	.byte	46                      # DW_TAG_subprogram
-	.byte	0                       # DW_CHILDREN_no
-	.byte	17                      # DW_AT_low_pc
-	.ascii	"\201>"                 # DW_FORM_GNU_addr_index
-	.byte	18                      # DW_AT_high_pc
-	.byte	6                       # DW_FORM_data4
-	.byte	64                      # DW_AT_frame_base
-	.byte	24                      # DW_FORM_exprloc
-	.byte	3                       # DW_AT_name
-	.ascii	"\202>"                 # DW_FORM_GNU_str_index
-	.byte	58                      # DW_AT_decl_file
-	.byte	11                      # DW_FORM_data1
-	.byte	59                      # DW_AT_decl_line
-	.byte	11                      # DW_FORM_data1
-	.byte	73                      # DW_AT_type
-	.byte	19                      # DW_FORM_ref4
-	.byte	63                      # DW_AT_external
-	.byte	25                      # DW_FORM_flag_present
-	.byte	0                       # EOM(1)
-	.byte	0                       # EOM(2)
-	.byte	0                       # EOM(3)
-	.section	.debug_addr,"",@progbits
-	.quad	.Lfunc_begin0
-	.quad	.Lfunc_begin1
-	.section	.debug_pubnames,"",@progbits
-	.long	.LpubNames_end0-.LpubNames_begin0 # Length of Public Names Info
-.LpubNames_begin0:
-	.short	2                       # DWARF Version
-	.long	.Lcu_begin0             # Offset of Compilation Unit Info
-	.long	48                      # Compilation Unit Length
-	.long	25                      # DIE offset
-	.asciz	"func"                  # External Name
-	.long	0                       # End Mark
-.LpubNames_end0:
-	.long	.LpubNames_end1-.LpubNames_begin1 # Length of Public Names Info
-.LpubNames_begin1:
-	.short	2                       # DWARF Version
-	.long	.Lcu_begin1             # Offset of Compilation Unit Info
-	.long	48                      # Compilation Unit Length
-	.long	25                      # DIE offset
-	.asciz	"main"                  # External Name
-	.long	0                       # End Mark
-.LpubNames_end1:
-	.section	.debug_pubtypes,"",@progbits
-	.long	.LpubTypes_end0-.LpubTypes_begin0 # Length of Public Types Info
-.LpubTypes_begin0:
-	.short	2                       # DWARF Version
-	.long	.Lcu_begin0             # Offset of Compilation Unit Info
-	.long	48                      # Compilation Unit Length
-	.long	52                      # DIE offset
-	.asciz	"int"                   # External Name
-	.long	0                       # End Mark
-.LpubTypes_end0:
-	.long	.LpubTypes_end1-.LpubTypes_begin1 # Length of Public Types Info
-.LpubTypes_begin1:
-	.short	2                       # DWARF Version
-	.long	.Lcu_begin1             # Offset of Compilation Unit Info
-	.long	48                      # Compilation Unit Length
-	.long	40                      # DIE offset
-	.asciz	"int"                   # External Name
-	.long	0                       # End Mark
-.LpubTypes_end1:
-
-	.ident	"clang version 5.0.0 (trunk 302855) (llvm/trunk 302853)"
-	.ident	"clang version 5.0.0 (trunk 302855) (llvm/trunk 302853)"
-	.section	".note.GNU-stack","",@progbits
-	.section	.debug_line,"",@progbits
-.Lline_table_start0:
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu1.c b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.c
similarity index 72%
rename from gdb/testsuite/gdb.dwarf2/fission-multi-cu1.c
rename to gdb/testsuite/gdb.dwarf2/fission-multi-cu.c
index 08674a9b4a9..6a177ad4e61 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu1.c
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.c
@@ -15,8 +15,27 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#define LL(N) asm ("line_label_" #N ": .globl line_label_" #N)
+
+/* Fake parameter location.  */
+int global_param = 0;
+
 int
 func (int arg)
 {
+  asm ("func_label: .globl func_label");
+  LL(4);
   return arg + 1;
 }
+
+int
+main ()
+{
+  asm ("main_label: .globl main_label");
+  LL(1);
+  global_param = -1;
+  LL(2);
+  func (-1);
+  LL(3);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
index dec754798b6..0f7f796a541 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp
@@ -13,6 +13,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+# This test checks that GDB can load DWARF information from two
+# separate split .DWO files.
+
 load_lib dwarf.exp
 
 # We run objcopy locally to split out the .dwo file.
@@ -25,18 +28,186 @@ if ![dwarf2_support] {
     return 0
 }
 
-# This test can only be run on x86-64 targets.
-if {![istarget x86_64-*] || ![is_lp64_target]} {
-    return 0
+# We place the entire source code for the test into a single .c file,
+# but we generate the DWARF in two separate .S files.  Each .S is
+# compiled to a .o, then the DWARF is split into a .dwo file.  Finally
+# the all three .o files are merged into a single executable that will
+# reference the two .dwo files.
+standard_testfile .c -1-dw.S -2-cw.S
+
+# Generate the first .S file.
+set asm_file_1 [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file_1 {
+    global srcfile binfile objdir srcdir subdir
+
+    get_func_info func
+
+    declare_labels int4_type lines_table
+
+    set debug_addr_lbl ".unknown!!"
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture a label to the current start of the .debug_addr
+	# section.  This will be passed to DW_AT_GNU_addr_base in the
+	# non-split CU later.
+	set debug_addr_lbl [debug_addr_label]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+        } {
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      int}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name func DW_FORM_string}
+		{MACRO_AT_func {func}}
+		{DW_AT_type :$int4_type}
+	    } {
+		DW_TAG_formal_parameter {
+		    {DW_AT_name arg}
+		    {DW_AT_type :$int4_type}
+		    {DW_AT_location {
+			DW_OP_GNU_addr_index [gdb_target_symbol global_param]
+		    } SPECIAL_expr}
+		}
+	    }
+	}
+    }
+
+    lines {version 2} lines_table {
+	include_dir "${srcdir}/${subdir}"
+	file_name "$srcfile" 1
+
+	program {
+	    {DW_LNE_set_address $func_start}
+	    {DW_LNS_advance_line 24}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address line_label_4}
+	    {DW_LNS_advance_line 3}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address $func_end}
+	    {DW_LNS_advance_line 1}
+	    {DW_LNS_copy}
+	    {DW_LNE_end_sequence}
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${binfile}-1-dw.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x1234 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_lbl}
+	    {stmt_list $lines_table DW_FORM_sec_offset}
+        } {
+	    # Nothing.
+	}
+    }
 }
 
-standard_testfile .S
-
-set dwo [standard_output_file "fission-multi-cu.dwo"]
+# Generate the second .S file.
+set asm_file_2 [standard_output_file $srcfile3]
+Dwarf::assemble $asm_file_2 {
+    global srcfile binfile objdir srcdir subdir
+
+    set debug_addr_lbl ".unknown!!"
+
+    declare_labels int4_type lines_table
+
+    get_func_info main
+
+    # The information that will be split out into the .dwo file.
+    cu {fission 1} {
+
+	# Capture a label to the current start of the .debug_addr
+	# section.  This will be passed to DW_AT_GNU_addr_base in the
+	# non-split CU later.
+	set debug_addr_lbl [debug_addr_label]
+
+	compile_unit {
+            {language @DW_LANG_C}
+            {name ${srcfile}}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x4567 DW_FORM_data8}
+        } {
+	    int4_type: DW_TAG_base_type {
+		{DW_AT_byte_size 4 DW_FORM_sdata}
+		{DW_AT_encoding  @DW_ATE_signed}
+		{DW_AT_name      int}
+	    }
+
+	    subprogram {
+		{external 1 flag}
+		{DW_AT_name main DW_FORM_string}
+		{MACRO_AT_func {main}}
+		{DW_AT_type :$int4_type}
+		{DW_AT_decl_file 1 data1}
+		{DW_AT_decl_line 29 data1}
+	    }
+	}
+    }
+
+    lines {version 2} lines_table {
+	include_dir "${srcdir}/${subdir}"
+	file_name "$srcfile" 1
+
+	program {
+	    {DW_LNE_set_address $main_start}
+	    {DW_LNS_advance_line 32}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address line_label_1}
+	    {DW_LNS_advance_line 3}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address line_label_2}
+	    {DW_LNS_advance_line 2}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address line_label_3}
+	    {DW_LNS_advance_line 2}
+	    {DW_LNS_copy}
+
+	    {DW_LNE_set_address $main_end}
+	    {DW_LNS_advance_line 2}
+	    {DW_LNS_copy}
+	    {DW_LNE_end_sequence}
+	}
+    }
+
+    # The information that will remain in the .o file.
+    cu {} {
+	compile_unit {
+            {DW_AT_GNU_dwo_name ${binfile}-2-dw.dwo DW_FORM_strp}
+	    {DW_AT_comp_dir ${objdir}}
+	    {DW_AT_GNU_dwo_id 0x4567 DW_FORM_data8}
+	    {DW_AT_GNU_addr_base $debug_addr_lbl}
+	    {stmt_list $lines_table DW_FORM_sec_offset}
+        } {
+	    # Nothing.
+	}
+    }
+}
 
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" \
-	[list nodebug additional_flags=-DDWO=$dwo]] {
+# Compile all of the input files, split the DWARF into the .dwo files.
+set obj1 [standard_output_file "${testfile}-1-dw.o"]
+set obj2 [standard_output_file "${testfile}-2-dw.o"]
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" {nodebug} \
+	[list $asm_file_1 [list nodebug split-dwo] $obj1] \
+	[list $asm_file_2 [list nodebug split-dwo] $obj2] \
+	[list $srcfile  [list nodebug]]] {
     return -1
 }
 
@@ -51,13 +222,13 @@ if ![runto_main] {
 gdb_test "ptype main" "type = int \\(\\)"
 gdb_test "ptype func" "type = int \\(int\\)"
 
-gdb_test "frame" "#0 *main \\(\\) at ${testfile}2\\.c:$decimal.*" \
+gdb_test "frame" "#0 *main \\(\\) at \[^\r\n\]+${srcfile}:$decimal.*" \
     "frame in main"
 
-gdb_test "break func" "Breakpoint.*at.* file .*${testfile}1\\.c, line .*"
+gdb_test "break func" "Breakpoint.*at.* file .*${srcfile}, line .*"
 
 gdb_test "continue" "Breakpoint.* func \\(arg=-1\\).*" \
     "continue to func"
 
-gdb_test "frame" "#0 *func \\(arg=-1\\) at ${testfile}1\\.c:$decimal.*" \
+gdb_test "frame" "#0 *func \\(arg=-1\\) at \[^\r\n\]+${srcfile}:$decimal.*" \
     "frame in func"
diff --git a/gdb/testsuite/gdb.dwarf2/fission-reread.exp b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
index 58132794ee7..16a139eb0cd 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-reread.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-reread.exp
@@ -30,17 +30,20 @@ set additional_flags [gdb_target_symbol_prefix_flags_asm]
 
 standard_testfile .S
 
-set dwo [standard_output_file "fission-reread.dwo"]
+set obj [standard_output_file "${testfile}.o"]
+set dwo [standard_output_file "${testfile}.dwo"]
 
-set options [list]
-lappend options nodebug
+set options [list nodebug]
 if { $additional_flags != "" } {
     lappend options $additional_flags
 }
-lappend options additional_flags=-DDWO=$dwo
 
-if [build_executable_from_fission_assembler \
-	"$testfile.exp" "$binfile" "$srcfile" $options] {
+set dwo_options $options
+lappend dwo_options split-dwo
+lappend dwo_options additional_flags=-DDWO=$dwo
+
+if [build_executable_and_dwo_files "$testfile.exp" "${binfile}" $options \
+	[list $srcfile $dwo_options $obj]] {
     return -1
 }
 
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 4cd5e16c604..558d0fd0139 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -28,39 +28,12 @@ proc dwarf2_support {} {
     return 0
 }
 
-# Build an executable from a fission-based .S file.
-# This handles the extra work of splitting the .o into non-dwo and dwo
-# pieces, making sure the .dwo is available if we're using cc-with-tweaks.sh
-# to build a .dwp file.
-# The arguments and results are the same as for build_executable.
+# Use 'objcopy --extract-dwo to extract DWO information from
+# OBJECT_FILE and place it into DWO_FILE.
 #
-# Current restrictions:
-# - only supports one source file
-# - cannot be run on remote hosts
-
-proc build_executable_from_fission_assembler { testname executable sources options } {
-    verbose -log "build_executable_from_fission_assembler $testname $executable $sources $options"
-    if { [llength $sources] != 1 } {
-	error "Only one source file supported."
-    }
-    if [is_remote host] {
-	error "Remote hosts are not supported."
-    }
-
-    global srcdir subdir
-    set source_file ${srcdir}/${subdir}/${sources}
-    set root_name [file rootname [file tail $source_file]]
-    set output_base [standard_output_file $root_name]
-    set object_file ${output_base}.o
-    set dwo_file ${output_base}.dwo
-    set object_options "object $options"
+# Return 0 on success, otherwise, return -1.
+proc extract_dwo_information { object_file dwo_file } {
     set objcopy [gdb_find_objcopy]
-
-    set result [gdb_compile $source_file $object_file object $options]
-    if { "$result" != "" } {
-	return -1
-    }
-
     set command "$objcopy --extract-dwo $object_file $dwo_file"
     verbose -log "Executing $command"
     set result [catch "exec $command" output]
@@ -68,19 +41,157 @@ proc build_executable_from_fission_assembler { testname executable sources optio
     if { $result == 1 } {
 	return -1
     }
+    return 0
+}
 
-    set command "$objcopy --strip-dwo $object_file"
+# Use 'objcopy --strip-dwo to remove DWO information from
+# FILENAME.
+#
+# Return 0 on success, otherwise, return -1.
+proc strip_dwo_information { filename } {
+    set objcopy [gdb_find_objcopy]
+    set command "$objcopy --strip-dwo $filename"
     verbose -log "Executing $command"
     set result [catch "exec $command" output]
     verbose -log "objcopy --strip-dwo output: $output"
     if { $result == 1 } {
 	return -1
     }
+    return 0
+}
 
-    set result [gdb_compile $object_file $executable executable $options]
-    if { "$result" != "" } {
+# Build an executable, with the debug information split out into a
+# separate .dwo file.
+#
+# This function is based on build_executable_from_specs in
+# lib/gdb.exp, but with threading support, and rust support removed.
+#
+# TESTNAME is the name of the test; this is passed to 'untested' if
+# something fails.
+#
+# EXECUTABLE is the executable to create, this can be an absolute
+# path, or a relative path, in which case the EXECUTABLE will be
+# created in the standard output directory.
+#
+# OPTIONS is passed to the final link, using gdb_compile.  If OPTIONS
+# contains any option that indicates threads is required, of if the
+# option rust is included, then this function will return failure.
+#
+# ARGS is a series of lists.  Each list is a spec for one source file
+# that will be compiled to make EXECUTABLE.  Each spec in ARGS has the
+# form:
+#	[ SOURCE OPTIONS ]
+# or:
+#       [ SOURCE OPTIONS OBJFILE ]
+#
+# Where SOURCE is the path to the source file to compile.  This can be
+# absolute, or relative to the standard global ${subdir}/${srcdir}/
+# path.
+#
+# OPTIONS are the options to use when compiling SOURCE into an object
+# file.
+#
+# OBJFILE is optional, if present this is the name of the object file
+# to create for SOURCE.  If this is not provided then a suitable name
+# will be auto-generated.
+#
+# If OPTIONS contains the option 'split-dwo' then the debug
+# information is extracted from the object file created by compiling
+# SOURCE and placed into a file with a dwo extension.  The name of
+# this file is generated based on the name of the object file that was
+# created (with the .o replaced with .dwo).
+proc build_executable_and_dwo_files { testname executable options args } {
+    global subdir
+    global srcdir
+
+    if { ! [regexp "^/" "$executable"] } then {
+	set binfile [standard_output_file $executable]
+    } else {
+	set binfile $executable
+    }
+
+    set info_options ""
+    if { [lsearch -exact $options "c++"] >= 0 } {
+	set info_options "c++"
+    }
+    if [get_compiler_info ${info_options}] {
+        return -1
+    }
+
+    set func gdb_compile
+    if {[lsearch -regexp $options \
+	     {^(pthreads|shlib|shlib_pthreads|openmp)$}] != -1} {
+	# Currently don't support compiling thread based tests here.
+	# If this is required then look to build_executable_from_specs
+	# for inspiration.
 	return -1
     }
+    if {[lsearch -exact $options rust] != -1} {
+	# Currently don't support compiling rust tests here.  If this
+	# is required then look to build_executable_from_specs for
+	# inspiration.
+	return -1
+    }
+
+    # Must be run on local host due to use of objcopy.
+    if [is_remote host] {
+	return -1
+    }
+
+    set objects {}
+    set i 0
+    foreach spec $args {
+	if {[llength $spec] < 2} {
+	    error "invalid spec length"
+	    return -1
+	}
+
+	verbose -log "APB: SPEC: $spec"
+
+	set s [lindex $spec 0]
+	set local_options [lindex $spec 1]
+
+	if { ! [regexp "^/" "$s"] } then {
+	    set s "$srcdir/$subdir/$s"
+	}
+
+	if {[llength $spec] > 2} {
+	    set objfile [lindex $spec 2]
+	} else {
+	    set objfile "${binfile}${i}.o"
+	    incr i
+	}
+
+	if  { [$func "${s}" "${objfile}" object $local_options] != "" } {
+	    untested $testname
+	    return -1
+	}
+
+	lappend objects "$objfile"
+
+	if {[lsearch -exact $local_options "split-dwo"] >= 0} {
+	    # Split out the DWO file.
+	    set dwo_file "[file rootname ${objfile}].dwo"
+
+	    if { [extract_dwo_information $objfile $dwo_file] == -1 } {
+		untested $testname
+		return -1
+	    }
+
+	    if { [strip_dwo_information $objfile] == -1 } {
+		untested $testname
+		return -1
+	    }
+	}
+    }
+
+    verbose -log "APB: OBJECTS = $objects"
+
+    set ret [$func $objects "${binfile}" executable $options]
+    if  { $ret != "" } {
+        untested $testname
+        return -1
+    }
 
     return 0
 }
@@ -329,6 +440,14 @@ namespace eval Dwarf {
     # The address size for debug ranges section.
     variable _debug_ranges_64_bit
 
+    # The index into the .debug_addr section (used for fission
+    # generation).
+    variable _debug_addr_index
+
+    # Flag, true if the current CU is contains fission information,
+    # otherwise false.
+    variable _cu_is_fission
+
     proc _process_one_constant {name value} {
 	variable _constants
 	variable _AT
@@ -486,6 +605,18 @@ namespace eval Dwarf {
 		_op .${_cu_addr_size}byte $value
 	    }
 
+	    DW_FORM_GNU_addr_index {
+		variable _debug_addr_index
+		variable _cu_addr_size
+
+		_op .uleb128 ${_debug_addr_index}
+		incr _debug_addr_index
+
+		_defer_output .debug_addr {
+		    _op .${_cu_addr_size}byte $value
+		}
+	    }
+
 	    DW_FORM_data2 -
 	    DW_FORM_ref2 {
 		_op .2byte $value
@@ -553,7 +684,6 @@ namespace eval Dwarf {
 	    DW_FORM_strx3 -
 	    DW_FORM_strx4 -
 
-	    DW_FORM_GNU_addr_index -
 	    DW_FORM_GNU_str_index -
 
 	    default {
@@ -609,6 +739,9 @@ namespace eval Dwarf {
 	    DW_AT_name {
 		return DW_FORM_string
 	    }
+	    DW_AT_GNU_addr_base {
+		return DW_FORM_sec_offset
+	    }
 	}
 	return ""
     }
@@ -649,6 +782,8 @@ namespace eval Dwarf {
     # Handle macro attribute MACRO_AT_range.
 
     proc _handle_macro_at_range { attr_value } {
+	variable _cu_is_fission
+
 	if {[llength $attr_value] != 1} {
 	    error "usage: MACRO_AT_range { func }"
 	}
@@ -658,10 +793,14 @@ namespace eval Dwarf {
 	set src ${srcdir}/${subdir}/${srcfile}
 	set result [function_range $func $src]
 
-	_handle_attribute DW_AT_low_pc [lindex $result 0] \
-	    DW_FORM_addr
+	set form DW_FORM_addr
+	if { $_cu_is_fission } {
+	    set form DW_FORM_GNU_addr_index
+	}
+
+	_handle_attribute DW_AT_low_pc [lindex $result 0] $form
 	_handle_attribute DW_AT_high_pc \
-	    "[lindex $result 0] + [lindex $result 1]" DW_FORM_addr
+	    "[lindex $result 0] + [lindex $result 1]" $form
     }
 
     # Handle macro attribute MACRO_AT_func.
@@ -929,6 +1068,18 @@ namespace eval Dwarf {
 		    _op .${addr_size}byte [lindex $line 1]
 		}
 
+		DW_OP_GNU_addr_index {
+		    variable _debug_addr_index
+		    variable _cu_addr_size
+
+		    _op .uleb128 ${_debug_addr_index}
+		    incr _debug_addr_index
+
+		    _defer_output .debug_addr {
+			_op .${_cu_addr_size}byte [lindex $line 1]
+		    }
+		}
+
 		DW_OP_regx {
 		    _op .uleb128 [lindex $line 1]
 		}
@@ -1050,6 +1201,23 @@ namespace eval Dwarf {
 	}
     }
 
+    # Return a label that references the current position in the
+    # .debug_addr table.  When a user is creating split DWARF they
+    # will define two CUs, the first will be the split DWARF content,
+    # and the second will be the non-split stub CU.  The split DWARF
+    # CU fills in the .debug_addr section, but the non-split CU
+    # includes a reference to the start of the section.  The label
+    # returned by this proc provides that reference.
+    proc debug_addr_label {} {
+	variable _debug_addr_index
+
+	set lbl [new_label "debug_addr_idx_${_debug_addr_index}_"]
+	_defer_output .debug_addr {
+	    define_label $lbl
+	}
+	return $lbl
+    }
+
     # Emit a DWARF CU.
     # OPTIONS is a list with an even number of elements containing
     # option-name and option-value pairs.
@@ -1073,12 +1241,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_info"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1088,7 +1257,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1100,7 +1269,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_info.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -1180,12 +1349,13 @@ namespace eval Dwarf {
 	variable _cu_version
 	variable _cu_addr_size
 	variable _cu_offset_size
+	variable _cu_is_fission
 
 	# Establish the defaults.
 	set is_64 0
 	set _cu_version 4
 	set _cu_addr_size default
-	set fission 0
+	set _cu_is_fission 0
 	set section ".debug_types"
 	set _abbrev_section ".debug_abbrev"
 
@@ -1194,7 +1364,7 @@ namespace eval Dwarf {
 		is_64 { set is_64 $value }
 		version { set _cu_version $value }
 		addr_size { set _cu_addr_size $value }
-		fission { set fission $value }
+		fission { set _cu_is_fission $value }
 		default { error "unknown option $name" }
 	    }
 	}
@@ -1206,7 +1376,7 @@ namespace eval Dwarf {
 	    }
 	}
 	set _cu_offset_size [expr { $is_64 ? 8 : 4 }]
-	if { $fission } {
+	if { $_cu_is_fission } {
 	    set section ".debug_types.dwo"
 	    set _abbrev_section ".debug_abbrev.dwo"
 	}
@@ -2056,6 +2226,7 @@ namespace eval Dwarf {
 	variable _line_saw_program
 	variable _line_header_end_label
 	variable _debug_ranges_64_bit
+	variable _debug_addr_index
 
 	if {!$_initialized} {
 	    _read_constants
@@ -2074,6 +2245,8 @@ namespace eval Dwarf {
 	set _line_saw_program 0
 	set _debug_ranges_64_bit [is_64_target]
 
+	set _debug_addr_index 0
+
 	# Not "uplevel" here, because we want to evaluate in this
 	# namespace.  This is somewhat bad because it means we can't
 	# readily refer to outer variables.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-26 17:54           ` [PATCHv3 0/2] " Andrew Burgess
  2021-03-26 17:54             ` [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler Andrew Burgess
  2021-03-26 17:54             ` [PATCHv3 2/2] gdb: handle relative paths to DWO files Andrew Burgess
@ 2021-03-31 15:57             ` Caroline Tice
  2021-03-31 20:04               ` Andrew Burgess
  2 siblings, 1 reply; 17+ messages in thread
From: Caroline Tice @ 2021-03-31 15:57 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Caroline Tice via Gdb-patches

Hi Andrew,

Just checking:  When do you expect to push this?

-- Caroline
cmtice@google.com


On Fri, Mar 26, 2021 at 10:54 AM Andrew Burgess <andrew.burgess@embecosm.com>
wrote:

> Caroline,
>
> I split the testsuite changes out into a separate patch (#1), this
> makes the patch containing your change (#2) much smaller, and more
> focused.
>
> If there's no feedback I'll push this early next week.
>
> Thanks,
> Andrew
>
> ---
>
> Andrew Burgess (2):
>   gdb/testsuite: fix fission support in the Dwarf assembler
>   gdb: handle relative paths to DWO files
>
>  gdb/ChangeLog                                 |   5 +
>  gdb/dwarf2/read.c                             |   7 +
>  gdb/testsuite/ChangeLog                       |  31 +++
>  .../gdb.dwarf2/fission-absolute-dwo.c         |  28 ++
>  .../gdb.dwarf2/fission-absolute-dwo.exp       | 132 ++++++++++
>  gdb/testsuite/gdb.dwarf2/fission-base.exp     |  11 +-
>  .../gdb.dwarf2/fission-loclists-pie.exp       |  11 +-
>  gdb/testsuite/gdb.dwarf2/fission-loclists.exp |  11 +-
>  gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp |  11 +-
>  .../gdb.dwarf2/fission-relative-dwo.c         |  28 ++
>  .../gdb.dwarf2/fission-relative-dwo.exp       | 130 +++++++++
>  gdb/testsuite/gdb.dwarf2/fission-reread.exp   |  15 +-
>  gdb/testsuite/lib/dwarf.exp                   | 248 ++++++++++++++----
>  13 files changed, 598 insertions(+), 70 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
>  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
>
> --
> 2.25.4
>
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files.
  2021-03-31 15:57             ` [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files Caroline Tice
@ 2021-03-31 20:04               ` Andrew Burgess
  0 siblings, 0 replies; 17+ messages in thread
From: Andrew Burgess @ 2021-03-31 20:04 UTC (permalink / raw)
  To: Caroline Tice; +Cc: Caroline Tice via Gdb-patches

* Caroline Tice <cmtice@google.com> [2021-03-31 08:57:02 -0700]:

> Hi Andrew,
> 
> Just checking:  When do you expect to push this?

Caroline,

If you've been following the thread you'll see that Simon gave some
feedback here:

  https://sourceware.org/pipermail/gdb-patches/2021-March/177342.html

And I replied here:

  https://sourceware.org/pipermail/gdb-patches/2021-March/177360.html

Which was yesterday.  I think we should probably allow a little more
time before we start chasing things.

I would probably be chasing this up in a week or so if there's been no
further follow up, then if there's no more feedback after that I'd be
happy to merge this.

Are you in a rush to get this patch merged?  Or just worried it will
get forgotten?

Thanks,
Andrew

> 
> -- Caroline
> cmtice@google.com
> 
> 
> On Fri, Mar 26, 2021 at 10:54 AM Andrew Burgess <andrew.burgess@embecosm.com>
> wrote:
> 
> > Caroline,
> >
> > I split the testsuite changes out into a separate patch (#1), this
> > makes the patch containing your change (#2) much smaller, and more
> > focused.
> >
> > If there's no feedback I'll push this early next week.
> >
> > Thanks,
> > Andrew
> >
> > ---
> >
> > Andrew Burgess (2):
> >   gdb/testsuite: fix fission support in the Dwarf assembler
> >   gdb: handle relative paths to DWO files
> >
> >  gdb/ChangeLog                                 |   5 +
> >  gdb/dwarf2/read.c                             |   7 +
> >  gdb/testsuite/ChangeLog                       |  31 +++
> >  .../gdb.dwarf2/fission-absolute-dwo.c         |  28 ++
> >  .../gdb.dwarf2/fission-absolute-dwo.exp       | 132 ++++++++++
> >  gdb/testsuite/gdb.dwarf2/fission-base.exp     |  11 +-
> >  .../gdb.dwarf2/fission-loclists-pie.exp       |  11 +-
> >  gdb/testsuite/gdb.dwarf2/fission-loclists.exp |  11 +-
> >  gdb/testsuite/gdb.dwarf2/fission-multi-cu.exp |  11 +-
> >  .../gdb.dwarf2/fission-relative-dwo.c         |  28 ++
> >  .../gdb.dwarf2/fission-relative-dwo.exp       | 130 +++++++++
> >  gdb/testsuite/gdb.dwarf2/fission-reread.exp   |  15 +-
> >  gdb/testsuite/lib/dwarf.exp                   | 248 ++++++++++++++----
> >  13 files changed, 598 insertions(+), 70 deletions(-)
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.c
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-absolute-dwo.exp
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.c
> >  create mode 100644 gdb/testsuite/gdb.dwarf2/fission-relative-dwo.exp
> >
> > --
> > 2.25.4
> >
> >

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler
  2021-03-30 11:07                 ` Andrew Burgess
@ 2021-04-01 16:41                   ` Tom Tromey
  0 siblings, 0 replies; 17+ messages in thread
From: Tom Tromey @ 2021-04-01 16:41 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Simon Marchi, gdb-patches

Andrew> commit 081199e14bd799b3adc82f4758e2d2906e05d6f7
Andrew> Author: Andrew Burgess <andrew.burgess@embecosm.com>
Andrew> Date:   Fri Mar 26 12:06:37 2021 +0000

Andrew>     gdb/testsuite: fix fission support in the Dwarf assembler
    
FWIW this looks reasonable to me.
Thank you for doing this.

Tom

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCHv3 2/2] gdb: handle relative paths to DWO files
  2021-03-26 17:54             ` [PATCHv3 2/2] gdb: handle relative paths to DWO files Andrew Burgess
@ 2021-04-01 16:42               ` Tom Tromey
  0 siblings, 0 replies; 17+ messages in thread
From: Tom Tromey @ 2021-04-01 16:42 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* dwarf2/read.c (try_open_dwop_file): Add path for the binary to
Andrew> 	the search paths used resolve relative location of .dwo file.

Andrew> gdb/testsuite/ChangeLog:

Andrew> 	* gdb.dwarf2/fission-relative-dwo.c: New file.
Andrew> 	* gdb.dwarf2/fission-relative-dwo.exp: New file.

This looks good to me.  Thanks.

Tom

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-04-01 16:42 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  0:42 [PATCH] Add directory containing executable to relative search paths for .dwo files Caroline Tice
2021-03-03  9:53 ` Andrew Burgess
2021-03-04 15:48   ` [PATCH, v2] " Caroline Tice
2021-03-11 15:33     ` Caroline Tice
2021-03-18  0:26     ` Andrew Burgess
     [not found]       ` <CABtf2+RmUPwpmsx+1i+a-QynhZKEpAib=EcFR4jDbr6PgH9t3g@mail.gmail.com>
2021-03-21  2:33         ` Caroline Tice
2021-03-25 15:09       ` Caroline Tice
2021-03-25 17:46         ` Andrew Burgess
2021-03-26 17:54           ` [PATCHv3 0/2] " Andrew Burgess
2021-03-26 17:54             ` [PATCHv3 1/2] gdb/testsuite: fix fission support in the Dwarf assembler Andrew Burgess
2021-03-29 16:30               ` Simon Marchi
2021-03-30 11:07                 ` Andrew Burgess
2021-04-01 16:41                   ` Tom Tromey
2021-03-26 17:54             ` [PATCHv3 2/2] gdb: handle relative paths to DWO files Andrew Burgess
2021-04-01 16:42               ` Tom Tromey
2021-03-31 15:57             ` [PATCHv3 0/2] Add directory containing executable to relative search paths for .dwo files Caroline Tice
2021-03-31 20:04               ` Andrew Burgess

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).