From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 68DCC385800A for ; Wed, 24 May 2023 09:01:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68DCC385800A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684918880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+hyj7eq+muckmIpP/uXzXqJANTpxVoQh5Eo6z2ZY+jI=; b=YVXqM+MBP7LyE8zXKSOCXCdt+TSwdxiTcqorgQ4RpN4HHSgBXyJ9I1KWeRwXmoc4XDp9gZ PgLCQ5+x05fYNeqGIi/+5uihXiMvPfypcQ+ZxTI5Y3tWDqS94FU+Op0i0jNQcN+WfkgSeb krfNLn0LQRP6YB3Z1v8MfNnm8YoPS28= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-yuFfIFY3OUKNznjQ690opA-1; Wed, 24 May 2023 05:01:18 -0400 X-MC-Unique: yuFfIFY3OUKNznjQ690opA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-2f2981b8364so323439f8f.1 for ; Wed, 24 May 2023 02:01:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684918877; x=1687510877; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+hyj7eq+muckmIpP/uXzXqJANTpxVoQh5Eo6z2ZY+jI=; b=VhTNt73wu9PZfKQkys+ORgBoZ2kLCzMNGIuSs4GnxVMtAQ5jY4oIVTVB60KZCo5Gi7 p/q52xxAZzwtNx2HKWSMHt0lf2OGJnlz5JH3jQaRhX/OdcKM38dCP1aIr1BtsGhEZqTQ hZWzYsBKhMZ8Z3nqvAK5U2hhZkAyTNZwqJrpVIBlpDcikF6WTHf7OB5EC4RKXnrpSQ6X 5KEhUf+Bn4qhVkc7ZfZQJXV8YA7OyqhMzuvblD7HakSQ4alY9DRTkAl27x7uA6TW2gF8 +ZhC1AS/lt+amXW0mrgQBbWkyRHKVpM28pC+bv6ObbjvKJ5yI9ZySj40wDN9hnspm0M3 FoLQ== X-Gm-Message-State: AC+VfDzsapVDxjzFbrSBque40qXEnaFN0y6+9pRpOlWnPnetmtTWDu8l EoTLhiOFzBx/0u1P7zmRelliVo7FEyX0XWHMGo5RJuZDj7yt34f9MP0Ie+KsqWmSZA8mTrOlOd0 d9xFkoaH2ukEFad/3HSBODq0kJ82fQN7HI1LlL4OuN3Y9XLc+xv9wC0gSO04z1pEaKv/L9sI4bD XbL4P6EQ== X-Received: by 2002:a7b:cc8e:0:b0:3f6:89e:2716 with SMTP id p14-20020a7bcc8e000000b003f6089e2716mr5087091wma.33.1684918877380; Wed, 24 May 2023 02:01:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wMVYKBARRCHQUH5Gy4rYQrkdcLGRyjcB0DzH8W0lAV5lYShGOxQ0Cf1zpvHHsWBsez+guNw== X-Received: by 2002:a7b:cc8e:0:b0:3f6:89e:2716 with SMTP id p14-20020a7bcc8e000000b003f6089e2716mr5087057wma.33.1684918876840; Wed, 24 May 2023 02:01:16 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id p22-20020a7bcc96000000b003f1751016desm1590530wma.28.2023.05.24.02.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 02:01:16 -0700 (PDT) From: Andrew Burgess To: Aaron Merey via Gdb-patches , gdb-patches@sourceware.org Cc: Aaron Merey Subject: Re: [PATCH 1/7] gdb/debuginfod: Add debuginfod_section_query In-Reply-To: <20230227194212.348003-1-amerey@redhat.com> References: <20230227194212.348003-1-amerey@redhat.com> Date: Wed, 24 May 2023 10:01:13 +0100 Message-ID: <874jo285nq.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Aaron Merey via Gdb-patches writes: > Add new function debuginfod_section_query. This function queries > debuginfod servers for an individual ELF/DWARF section associated with > a given build-id. > > Also check for libdebuginfod version >= 0.188 at configure time. > debuginfod_section_query simply returns -ENOSYS if this condition > is not met. > --- > config/debuginfod.m4 | 27 +++++++++++ > gdb/config.in | 3 ++ > gdb/configure | 102 ++++++++++++++++++++++++++++++++++++++- > gdb/configure.ac | 2 +- > gdb/debuginfod-support.c | 55 +++++++++++++++++++++ > gdb/debuginfod-support.h | 24 +++++++++ > 6 files changed, 211 insertions(+), 2 deletions(-) > > diff --git a/config/debuginfod.m4 b/config/debuginfod.m4 > index 2c1bfbdb544..203a799719d 100644 > --- a/config/debuginfod.m4 > +++ b/config/debuginfod.m4 > @@ -26,3 +26,30 @@ else > AC_MSG_WARN([debuginfod support disabled; some features may be unavailable.]) > fi > ]) > + > +AC_DEFUN([AC_DEBUGINFOD_SECTION], > +[ > +# Handle optional debuginfod support as well as optional section downloading support Missing a '.' from the end of this sentence. I'd also like to see this comment explain what this define actually does. Like: # Handle optional debuginfod support as well as optional section # downloading support. # # Define HAVE_LIBDEBUGINFOD if .... # # Define HAVE_DEBUGINFOD_FIND_SECTION if ... > +AC_ARG_WITH([debuginfod], > + AC_HELP_STRING([--with-debuginfod], [Enable debuginfo lookups with debuginfod (auto/yes/no)]), > + [], [with_debuginfod=auto]) > +AC_MSG_CHECKING([whether to use debuginfod]) > +AC_MSG_RESULT([$with_debuginfod]) > + > +if test "x$with_debuginfod" != xno; then > + PKG_CHECK_MODULES([DEBUGINFOD], [libdebuginfod >= 0.188], > + [AC_DEFINE([HAVE_DEBUGINFOD_FIND_SECTION], [1], I think this should be HAVE_LIBDEBUGINFOD_FIND_SECTION in order to be consistent with the plain HAVE_LIBDEBUGINFOD. > + [Define to 1 if debuginfod section downloading is supported.])], > + [AC_MSG_WARN([libdebuginfod is missing or some features may be unavailable.])]) > + > + PKG_CHECK_MODULES([DEBUGINFOD], [libdebuginfod >= 0.179], > + [AC_DEFINE([HAVE_LIBDEBUGINFOD], [1], [Define to 1 if debuginfod is enabled.])], > + [if test "x$with_debuginfod" = xyes; then > + AC_MSG_ERROR(["--with-debuginfod was given, but libdebuginfod is missing or unusable."]) > + else > + AC_MSG_WARN([libdebuginfod is missing or unusable; some features may be unavailable.]) > + fi]) > +else > + AC_MSG_WARN([debuginfod support disabled; some features may be unavailable.]) > +fi > +]) > diff --git a/gdb/config.in b/gdb/config.in > index a7da88b92d7..157acd46c7c 100644 > --- a/gdb/config.in > +++ b/gdb/config.in > @@ -99,6 +99,9 @@ > /* define if the compiler supports basic C++11 syntax */ > #undef HAVE_CXX11 > > +/* Define to 1 if debuginfod section downloading is supported. */ > +#undef HAVE_DEBUGINFOD_FIND_SECTION > + > /* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if > you don't. */ > #undef HAVE_DECL_ADDR_NO_RANDOMIZE > diff --git a/gdb/configure b/gdb/configure > index 017ec05e4b7..338460c07bd 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -18349,7 +18349,7 @@ esac > > # Handle optional debuginfod support > > -# Handle optional debuginfod support > +# Handle optional debuginfod support as well as optional section downloading support > > # Check whether --with-debuginfod was given. > if test "${with_debuginfod+set}" = set; then : > @@ -18365,6 +18365,106 @@ $as_echo "$with_debuginfod" >&6; } > > if test "x$with_debuginfod" != xno; then > > +pkg_failed=no > +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libdebuginfod >= 0.188" >&5 > +$as_echo_n "checking for libdebuginfod >= 0.188... " >&6; } > + > +if test -n "$DEBUGINFOD_CFLAGS"; then > + pkg_cv_DEBUGINFOD_CFLAGS="$DEBUGINFOD_CFLAGS" > + elif test -n "$PKG_CONFIG"; then > + if test -n "$PKG_CONFIG" && \ > + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdebuginfod >= 0.188\""; } >&5 > + ($PKG_CONFIG --exists --print-errors "libdebuginfod >= 0.188") 2>&5 > + ac_status=$? > + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; }; then > + pkg_cv_DEBUGINFOD_CFLAGS=`$PKG_CONFIG --cflags "libdebuginfod >= 0.188" 2>/dev/null` > + test "x$?" != "x0" && pkg_failed=yes > +else > + pkg_failed=yes > +fi > + else > + pkg_failed=untried > +fi > +if test -n "$DEBUGINFOD_LIBS"; then > + pkg_cv_DEBUGINFOD_LIBS="$DEBUGINFOD_LIBS" > + elif test -n "$PKG_CONFIG"; then > + if test -n "$PKG_CONFIG" && \ > + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdebuginfod >= 0.188\""; } >&5 > + ($PKG_CONFIG --exists --print-errors "libdebuginfod >= 0.188") 2>&5 > + ac_status=$? > + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; }; then > + pkg_cv_DEBUGINFOD_LIBS=`$PKG_CONFIG --libs "libdebuginfod >= 0.188" 2>/dev/null` > + test "x$?" != "x0" && pkg_failed=yes > +else > + pkg_failed=yes > +fi > + else > + pkg_failed=untried > +fi > + > +if test $pkg_failed = no; then > + pkg_save_LDFLAGS="$LDFLAGS" > + LDFLAGS="$LDFLAGS $pkg_cv_DEBUGINFOD_LIBS" > + cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > + > +int > +main () > +{ > + > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_c_try_link "$LINENO"; then : > + > +else > + pkg_failed=yes > +fi > +rm -f core conftest.err conftest.$ac_objext \ > + conftest$ac_exeext conftest.$ac_ext > + LDFLAGS=$pkg_save_LDFLAGS > +fi > + > + > + > +if test $pkg_failed = yes; then > + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 > +$as_echo "no" >&6; } > + > +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then > + _pkg_short_errors_supported=yes > +else > + _pkg_short_errors_supported=no > +fi > + if test $_pkg_short_errors_supported = yes; then > + DEBUGINFOD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libdebuginfod >= 0.188" 2>&1` > + else > + DEBUGINFOD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libdebuginfod >= 0.188" 2>&1` > + fi > + # Put the nasty error message in config.log where it belongs > + echo "$DEBUGINFOD_PKG_ERRORS" >&5 > + > + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libdebuginfod is missing or some features may be unavailable." >&5 > +$as_echo "$as_me: WARNING: libdebuginfod is missing or some features may be unavailable." >&2;} > +elif test $pkg_failed = untried; then > + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 > +$as_echo "no" >&6; } > + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libdebuginfod is missing or some features may be unavailable." >&5 > +$as_echo "$as_me: WARNING: libdebuginfod is missing or some features may be unavailable." >&2;} > +else > + DEBUGINFOD_CFLAGS=$pkg_cv_DEBUGINFOD_CFLAGS > + DEBUGINFOD_LIBS=$pkg_cv_DEBUGINFOD_LIBS > + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 > +$as_echo "yes" >&6; } > + > +$as_echo "#define HAVE_DEBUGINFOD_FIND_SECTION 1" >>confdefs.h > + > +fi > + > + > pkg_failed=no > { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libdebuginfod >= 0.179" >&5 > $as_echo_n "checking for libdebuginfod >= 0.179... " >&6; } > diff --git a/gdb/configure.ac b/gdb/configure.ac > index fb43cd10d6c..499802bb4c9 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -342,7 +342,7 @@ case $host_os in > esac > > # Handle optional debuginfod support > -AC_DEBUGINFOD > +AC_DEBUGINFOD_SECTION > > # Libunwind support for ia64. > AC_ARG_WITH(libunwind-ia64, > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c > index 04d254a1601..f909742362f 100644 > --- a/gdb/debuginfod-support.c > +++ b/gdb/debuginfod-support.c > @@ -80,6 +80,15 @@ debuginfod_exec_query (const unsigned char *build_id, > return scoped_fd (-ENOSYS); > } > > +scoped_fd > +debuginfod_section_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + const char *section_name, > + gdb::unique_xmalloc_ptr *destname) > +{ > + return scoped_fd (-ENOSYS); > +} > #define NO_IMPL _("Support for debuginfod is not compiled into GDB.") > > #else > @@ -388,6 +397,52 @@ debuginfod_exec_query (const unsigned char *build_id, > > return fd; > } > + > +/* See debuginfod-support.h */ > + > +scoped_fd > +debuginfod_section_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + const char *section_name, > + gdb::unique_xmalloc_ptr *destname) > +{ > +#if !defined (HAVE_DEBUGINFOD_FIND_SECTION) > + return scoped_fd (-ENOSYS); > +#else > + > + if (!debuginfod_is_enabled ()) > + return scoped_fd (-ENOSYS); > + > + debuginfod_client *c = get_debuginfod_client (); > + > + if (c == nullptr) > + return scoped_fd (-ENOMEM); > + > + char *dname = nullptr; > + std::string desc = std::string ("section ") + section_name + " for"; > + user_data data (desc.c_str (), filename); > + > + debuginfod_set_user_data (c, &data); > + gdb::optional term_state; > + if (target_supports_terminal_ours ()) > + { > + term_state.emplace (); > + target_terminal::ours (); > + } > + > + scoped_fd fd (debuginfod_find_section (c, build_id, build_id_len, > + section_name, &dname)); > + debuginfod_set_user_data (c, nullptr); > + print_outcome (data, fd.get ()); > + > + if (fd.get () >= 0 && destname != nullptr) > + destname->reset (dname); Given all the uses of debuginfod_section_query pass a non-nullptr destname, and the comment in debuginfod-support.h doesn't indicate that destname is optional, I would suggest removing the 'destname != nullptr' check here, and replace it with an extra line: gdb_assert (destname != nullptr); Thanks, Andrew > + > + return fd; > +#endif /* HAVE_DEBUGINFOD_FIND_SECTION */ > +} > + > #endif > > /* Set callback for "set debuginfod enabled". */ > diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h > index 633600a79da..9701e3b4685 100644 > --- a/gdb/debuginfod-support.h > +++ b/gdb/debuginfod-support.h > @@ -81,4 +81,28 @@ extern scoped_fd debuginfod_exec_query (const unsigned char *build_id, > const char *filename, > gdb::unique_xmalloc_ptr > *destname); > + > +/* Query debuginfod servers for the binary contents of a ELF/DWARF section > + from a file matching BUILD_ID. BUILD_ID can be given as a binary blob > + or a null-terminated string. If given as a binary blob, BUILD_ID_LEN > + should be the number of bytes. If given as a null-terminated string, > + BUILD_ID_LEN should be 0. > + > + FILENAME should be the name or path associated with the file matching > + BUILD_ID. It is used for printing messages to the user. > + > + SECTION_NAME should be the name of an ELF/DWARF section. > + > + If the file is successfully retrieved, return a file descriptor and store > + the file's local path in DESTNAME. If unsuccessful, print an error message > + and return a negative errno. If GDB is not built with debuginfod or > + libdebuginfod does not support section queries, this function returns > + -ENOSYS. */ > + > +extern scoped_fd debuginfod_section_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + const char *section_name, > + gdb::unique_xmalloc_ptr > + *destname); > #endif /* DEBUGINFOD_SUPPORT_H */ > -- > 2.39.2