From patchwork Mon Dec 24 16:26:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 30827 Received: (qmail 87806 invoked by alias); 24 Dec 2018 16:26:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 87797 invoked by uid 89); 24 Dec 2018 16:26:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=andrey, Andrey, quit, treated X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Dec 2018 16:26:08 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D6A0C1E059; Mon, 24 Dec 2018 11:26:05 -0500 (EST) Subject: Re: [PATCH] Fix search of debug files for remote debuggee To: John Baldwin , Andrey Utkin , gdb-patches@sourceware.org References: <20181109190940.22554-1-autkin@undo.io> <10046787-753c-f7e0-4386-2b50086ae530@FreeBSD.org> From: Simon Marchi Message-ID: <5c1211f6-0e75-d225-158a-0e6a310b68c7@simark.ca> Date: Mon, 24 Dec 2018 11:26:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: <10046787-753c-f7e0-4386-2b50086ae530@FreeBSD.org> On 2018-11-09 2:42 p.m., John Baldwin wrote: > On 11/9/18 11:09 AM, Andrey Utkin wrote: >> When using remote debugging server, and when debuggee filename is >> inferred via qXfer:exec-file:read request, or sysroot starts with >> "target:", this "target:" prefix of filepaths is not treated correctly >> during debug file search - it appears in the middle of the looked up >> paths. > > I only have a somewhat related comment. I have a similar-ish issue when > using sysroot and cross-debugging without a remote target. My use case is > that I'm on an x86 host but that I run QEMU instances of other architectures > (mips, arm, riscv, etc.) on my host. I tend to build base OS builds and > install them to some path (e.g. /ufs/riscv64/rootfs) and then use a tool > like makefs to generate a filesystem image to use with QEMU. I will then > scp a core dump out and debug it like so: > > gdb /path/to/binary > ... > (gdb) set sysroot /ufs/riscv64/rootfs > (gdb) core /path/to/core > > Now there are debug symbols for the various base OS libraries and binaries > installed in the sysroot at /ufs/riscv64/rootfs/usr/lib/debug. For example, > FreeBSD's libc is installed as /lib/libc.so.7 under the sysroot > (/ufs/riscv64/lib/libc.so.7) and the debug info is stored at /usr/lib/debug > under the sysroot (/ufs/riscv64/usr/lib/debug/lib/libc.so.7.debug). However, > GDB places the sysroot after the debug prefix and ends up looking for > /usr/lib/debug/ufs/riscv64/lib/libc.so.7 on the host instead. I usually > work around this by creating a symlink from /usr/lib/debug/ufs/riscv64 to > /ufs/riscv64/usr/lib/debug, but it seems like a bug to me that the we don't > look for debug files "under" the sysroot. > > I bring this up because I wonder if a more general solution of always putting > the sysroot before the debug prefix (e.g. "/usr/lib/debug") wouldn't fix > both your case and mine. It's not clear to me what the "correct" behavior > is for mixing sysroot with separate debug files. It may be that the current > behavior of // is intentional rather than > the // behavior that I would like (and that > I think your use case also wants). > Maybe I'm thinking in a bit too simplistic way, but I think it should always be //. I would have to actually try different scenarios in practice to convince myself. While trying to reproduce, I also noticed that build-id based separate debug files are not looked up using the sysroot... should they? If your debug files are in /usr/lib/debug/.build-id/..., I don't think they would be found at the moment. In the mean time, I think we can agree that the use case reported by Andrey is clearly broken, so I would be fine with merging the patch. I would like if we could come up with a test though. Andrey, I would make a few minor changes to your patch, if you agree: - Use "startswith" instead of strncmp - Use strlen instead of magical number 7 - Use ternary operator - Change variable name "remote" to "target_prefix". This would be the result: From 7999d879594a75c5e7e83fff8abb5b1f39197b71 Mon Sep 17 00:00:00 2001 From: Andrey Utkin Date: Fri, 9 Nov 2018 19:09:40 +0000 Subject: [PATCH] Fix search of debug files for remote debuggee When using remote debugging server, and when debuggee filename is inferred via qXfer:exec-file:read request, or sysroot starts with "target:", this "target:" prefix of filepaths is not treated correctly during debug file search - it appears in the middle of the looked up paths. In the following example, unpatched GDB can't find separate debug files for neither the executable, nor standard libraries: $ gdb -ex 'set debug separate-debug-file 1' -ex 'set sysroot target:/' -ex 'set debug-file-directory /usr/lib/debug:/home/j/hide' -ex 'target remote :3333' -ex 'break main' -ex 'continue' -ex 'bt' -ex 'info sharedlibrary' -ex 'set confirm off' -ex 'quit' GNU gdb (Gentoo 9999 vanilla) 8.2.50.20181109-git Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Remote debugging using :3333 Reading /home/j/test from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /home/j/test from remote target... Reading symbols from target:/home/j/test... Looking for separate debug info (debug link) for target:/home/j/test Trying target:/home/j/test.debug Reading /home/j/test.debug from remote target... Trying target:/home/j/.debug/test.debug Reading /home/j/.debug/test.debug from remote target... Trying /usr/lib/debug/target:/home/j/test.debug Trying /home/j/hide/target:/home/j/test.debug (No debugging symbols found in target:/home/j/test) Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading symbols from target:/lib64/ld-linux-x86-64.so.2... Looking for separate debug info (debug link) for target:/lib64/ld-linux-x86-64.so.2 Trying target:/lib64/ld-2.27.so.debug Reading /lib64/ld-2.27.so.debug from remote target... Trying target:/lib64/.debug/ld-2.27.so.debug Reading /lib64/.debug/ld-2.27.so.debug from remote target... Trying /usr/lib/debug/target:/lib64/ld-2.27.so.debug Trying /home/j/hide/target:/lib64/ld-2.27.so.debug (No debugging symbols found in target:/lib64/ld-linux-x86-64.so.2) Looking for separate debug info (build-id) for system-supplied DSO at 0x7ffff7ffa000 Trying /usr/lib/debug/.build-id/fd/03d584bc1a90ba28be457635a02662c9f9c1f2.debug Trying /home/j/hide/.build-id/fd/03d584bc1a90ba28be457635a02662c9f9c1f2.debug 0x00007ffff7dd7000 in ?? () from target:/lib64/ld-linux-x86-64.so.2 Breakpoint 1 at 0x4005eb Continuing. Reading /lib64/libpthread.so.0 from remote target... Reading /lib64/libc.so.6 from remote target... Looking for separate debug info (debug link) for target:/lib64/libpthread.so.0 Trying target:/lib64/libpthread-2.27.so.debug Reading /lib64/libpthread-2.27.so.debug from remote target... Trying target:/lib64/.debug/libpthread-2.27.so.debug Reading /lib64/.debug/libpthread-2.27.so.debug from remote target... Trying /usr/lib/debug/target:/lib64/libpthread-2.27.so.debug Trying /home/j/hide/target:/lib64/libpthread-2.27.so.debug Looking for separate debug info (debug link) for target:/lib64/libc.so.6 Trying target:/lib64/libc-2.27.so.debug Reading /lib64/libc-2.27.so.debug from remote target... Trying target:/lib64/.debug/libc-2.27.so.debug Reading /lib64/.debug/libc-2.27.so.debug from remote target... Trying /usr/lib/debug/target:/lib64/libc-2.27.so.debug Trying /home/j/hide/target:/lib64/libc-2.27.so.debug Breakpoint 1, 0x00000000004005eb in main () #0 0x00000000004005eb in main () From To Syms Read Shared Object Library 0x00007ffff7dd6e80 0x00007ffff7df4650 Yes (*) target:/lib64/ld-linux-x86-64.so.2 0x00007ffff7bbbb70 0x00007ffff7bcbfee Yes (*) target:/lib64/libpthread.so.0 0x00007ffff780f200 0x00007ffff7962d7c Yes (*) target:/lib64/libc.so.6 (*): Shared library is missing debugging information. With current fix, the paths used always have target: in the beginning and this helps to find all debug files: $ gdb -ex 'set debug separate-debug-file 1' -ex 'set sysroot target:/' -ex 'set debug-file-directory /usr/lib/debug:/home/j/hide' -ex 'target remote :3333' -ex 'break main' -ex 'continue' -ex 'bt' -ex 'info sharedlibrary' -ex 'set confirm off' -ex 'quit' GNU gdb (Gentoo 9999 vanilla) 8.2.50.20181109-git Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Remote debugging using :3333 Reading /home/j/test from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /home/j/test from remote target... Reading symbols from target:/home/j/test... Looking for separate debug info (debug link) for target:/home/j/test Trying target:/home/j/test.debug Reading /home/j/test.debug from remote target... Trying target:/home/j/.debug/test.debug Reading /home/j/.debug/test.debug from remote target... Trying target:/usr/lib/debug//home/j/test.debug Reading /usr/lib/debug//home/j/test.debug from remote target... Trying target:/home/j/hide//home/j/test.debug Reading /home/j/hide//home/j/test.debug from remote target... Reading /home/j/hide//home/j/test.debug from remote target... Reading symbols from target:/home/j/hide//home/j/test.debug... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading symbols from target:/lib64/ld-linux-x86-64.so.2... Looking for separate debug info (debug link) for target:/lib64/ld-linux-x86-64.so.2 Trying target:/lib64/ld-2.27.so.debug Reading /lib64/ld-2.27.so.debug from remote target... Trying target:/lib64/.debug/ld-2.27.so.debug Reading /lib64/.debug/ld-2.27.so.debug from remote target... Trying target:/usr/lib/debug//lib64/ld-2.27.so.debug Reading /usr/lib/debug//lib64/ld-2.27.so.debug from remote target... Reading /usr/lib/debug//lib64/ld-2.27.so.debug from remote target... Reading symbols from target:/usr/lib/debug//lib64/ld-2.27.so.debug... Looking for separate debug info (build-id) for system-supplied DSO at 0x7ffff7ffa000 Trying /usr/lib/debug/.build-id/fd/03d584bc1a90ba28be457635a02662c9f9c1f2.debug Trying /home/j/hide/.build-id/fd/03d584bc1a90ba28be457635a02662c9f9c1f2.debug 0x00007ffff7dd7000 in _start () from target:/lib64/ld-linux-x86-64.so.2 Breakpoint 1 at 0x4005ef: file test/test16.c, line 13. Continuing. Reading /lib64/libpthread.so.0 from remote target... Reading /lib64/libc.so.6 from remote target... Looking for separate debug info (debug link) for target:/lib64/libpthread.so.0 Trying target:/lib64/libpthread-2.27.so.debug Reading /lib64/libpthread-2.27.so.debug from remote target... Trying target:/lib64/.debug/libpthread-2.27.so.debug Reading /lib64/.debug/libpthread-2.27.so.debug from remote target... Trying target:/usr/lib/debug//lib64/libpthread-2.27.so.debug Reading /usr/lib/debug//lib64/libpthread-2.27.so.debug from remote target... Reading /usr/lib/debug//lib64/libpthread-2.27.so.debug from remote target... Looking for separate debug info (debug link) for target:/lib64/libc.so.6 Trying target:/lib64/libc-2.27.so.debug Reading /lib64/libc-2.27.so.debug from remote target... Trying target:/lib64/.debug/libc-2.27.so.debug Reading /lib64/.debug/libc-2.27.so.debug from remote target... Trying target:/usr/lib/debug//lib64/libc-2.27.so.debug Reading /usr/lib/debug//lib64/libc-2.27.so.debug from remote target... Reading /usr/lib/debug//lib64/libc-2.27.so.debug from remote target... Breakpoint 1, main () at test/test16.c:13 13 for ( i=0; i<10; ++i) #0 main () at test/test16.c:13 From To Syms Read Shared Object Library 0x00007ffff7dd6e80 0x00007ffff7df4650 Yes target:/lib64/ld-linux-x86-64.so.2 0x00007ffff7bbbb70 0x00007ffff7bcbfee Yes target:/lib64/libpthread.so.0 0x00007ffff780f200 0x00007ffff7962d7c Yes target:/lib64/libc.so.6 gdb/ChangeLog: 2018-11-09 Andrey Utkin * symfile.c (find_separate_debug_file): Fix search of debug files for remote debuggee. Signed-off-by: Andrey Utkin --- gdb/ChangeLog | 5 +++++ gdb/symfile.c | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fd5c612fa5c5..b4197c991bf1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-11-09 Andrey Utkin + + * symfile.c (find_separate_debug_file): Fix search of debug files for + remote debuggee. + 2018-12-23 Joel Brobecker GDB 8.2.1 released. diff --git a/gdb/symfile.c b/gdb/symfile.c index c5e2661415fd..bc72c7ba4830 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1425,14 +1425,17 @@ find_separate_debug_file (const char *dir, Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will cause "/..." lookups. */ + bool target_prefix = startswith (dir, "target:"); + const char *dir_notarget = target_prefix ? dir + strlen ("target:") : dir; std::vector> debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory); for (const gdb::unique_xmalloc_ptr &debugdir : debugdir_vec) { - debugfile = debugdir.get (); + debugfile = target_prefix ? "target:" : ""; + debugfile += debugdir.get (); debugfile += "/"; - debugfile += dir; + debugfile += dir_notarget; debugfile += debuglink; if (separate_debug_file_exists (debugfile, crc32, objfile)) @@ -1445,7 +1448,8 @@ find_separate_debug_file (const char *dir, strlen (gdb_sysroot)) == 0 && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)])) { - debugfile = debugdir.get (); + debugfile = target_prefix ? "target:" : ""; + debugfile += debugdir.get (); debugfile += (canon_dir + strlen (gdb_sysroot)); debugfile += "/"; debugfile += debuglink;