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

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