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.129.124]) by sourceware.org (Postfix) with ESMTPS id 96B18385840A for ; Mon, 24 Oct 2022 10:46:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96B18385840A 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=1666608363; 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=3d92kssRNbfOwuJ4Mbwx3K1rujvRp2AoAjwLaQRvIbQ=; b=FU/Go991gHYYckhgBHkoJFTPVIpZeiLMAXsIfGUgmFBGz3erdUR8g/vrxIvBbWQZHkZwFl mRWDxaAOHKYV9Bp5tuil8rLRoXHTZ4ue9qZATrObaxjh/WkI7yY1AOsixnyXymFhzSqZY9 0eIeWpGdvg7UnvTK+FV+6XIwCNxWwE4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-479-YTV5DwvVNpKJDBruplsimA-1; Mon, 24 Oct 2022 06:46:02 -0400 X-MC-Unique: YTV5DwvVNpKJDBruplsimA-1 Received: by mail-qv1-f70.google.com with SMTP id mo15-20020a056214330f00b004b96d712bccso5029231qvb.22 for ; Mon, 24 Oct 2022 03:46:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3d92kssRNbfOwuJ4Mbwx3K1rujvRp2AoAjwLaQRvIbQ=; b=8LG+8Hi/AjzVEE84VOE7CjWJBUQd1gK/hWVDZMYdM+I7pJsu1LH+OBNm+gSzlQdMsn bobsY0hkulmWCv96FgF3Fx+q+gEq6J6lcUgcMBTHZCDeQUCQjBz2JAWhz9KafzXGVWBQ 7ZMmrF4s32b0h2wSZ88VkCedq6hr9FSU/5MD8Lydi34IdH5slN6zmV1V5vkrJtXStVho ENSgOpAbubBVvkrNyXGuLk0eSpV3omDM0N6bWVNrOXs2gdAme0rAB5KpkFunDi80B8a4 kC/NlWJnTakvnY9uIMAUyO8CIMJpQg4PHhq42iO+rGJNsdkTYmkTY283vnXYzv8K4Gq6 MzMQ== X-Gm-Message-State: ACrzQf1CWrvymD7fonFuilm3yIsTc/TR3R6q/A3ndNghHOBCPv84jSzl c2kWVhBbZxs3hMR7cA+AFad89WZJM6WITIc0YADJB3RZp6H8JVkooe6HLKaJa3pd9VpmPqH5jFp 20eIeaGrA7DIaediSEJk/kLTKiFwrKZVAL3vpEQj/7WGYMsgHsLBBSIzG5b7vCKL/iAn3QdIy2g == X-Received: by 2002:a05:622a:178d:b0:39c:c64e:292 with SMTP id s13-20020a05622a178d00b0039cc64e0292mr27336422qtk.231.1666608361435; Mon, 24 Oct 2022 03:46:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM65AkCuXlpUFZp9E1M6TZxmtSUuClNKQyEXXGJyxajNeNh9IlhsF8gyEmpkebF0Pk/oO2RDYQ== X-Received: by 2002:a05:622a:178d:b0:39c:c64e:292 with SMTP id s13-20020a05622a178d00b0039cc64e0292mr27336271qtk.231.1666608358417; Mon, 24 Oct 2022 03:45:58 -0700 (PDT) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id t14-20020a05620a450e00b006ce580c2663sm14968672qkp.35.2022.10.24.03.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 03:45:58 -0700 (PDT) From: Andrew Burgess To: Asaf Fisher via Gdb-patches , gdb-patches@sourceware.org Cc: Asaf Fisher Subject: Re: [PATCH v3 1/2] Add test to check GDB handles dlopen of /proc/self/fd/[num] correctly In-Reply-To: <20221021174205.5389-1-asaffisher.dev@gmail.com> References: <20221021174205.5389-1-asaffisher.dev@gmail.com> Date: Mon, 24 Oct 2022 11:45:56 +0100 Message-ID: <87bkq1a49n.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.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: Asaf Fisher via Gdb-patches writes: > --- > gdb/testsuite/gdb.base/solib-proc-self.cc | 72 ++++++++++++++++++ > gdb/testsuite/gdb.base/solib-proc-self.exp | 86 ++++++++++++++++++++++ > 2 files changed, 158 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/solib-proc-self.cc > create mode 100644 gdb/testsuite/gdb.base/solib-proc-self.exp Hi! Thanks for working on this fix. If you have not contributed to GDB before then you might want to check out: https://sourceware.org/gdb/wiki/ContributionChecklist I think, given the size of these patches, you would need to complete a copyright assigment before these patches could be merged. Details of the copyright assignment can be found here: https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment The best choice for copyright assignment would be this starting point: http://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future which would assign copyright for past and future contributions to GDB over to the FSF. Thanks, Andrew > > diff --git a/gdb/testsuite/gdb.base/solib-proc-self.cc b/gdb/testsuite/gdb.base/solib-proc-self.cc > new file mode 100644 > index 00000000000..dc0b446d53c > --- /dev/null > +++ b/gdb/testsuite/gdb.base/solib-proc-self.cc > @@ -0,0 +1,72 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2007-2022 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 . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#ifdef __WIN32__ > +#include > +#define dlopen(name, mode) LoadLibrary (name) > +#define dlclose(handle) FreeLibrary (handle) > +#define dlerror() "an error occurred" > +#else > +#include > +#endif > + > +int main() > +{ > + void *handle; > + /* Read the so's content to a buffer */ > + std::ifstream read_so_file = std::ifstream(SHLIB_NAME); > + read_so_file.seekg(0, std::ios::end); > + std::streamsize size = read_so_file.tellg(); > + read_so_file.seekg(0, std::ios::beg); > + std::vector buffer(size); > + if (!read_so_file.read(buffer.data(), size)) > + { > + fprintf (stderr, "Failed to load solib\n"); > + exit(1); > + } > + > + int mem_fd = memfd_create("test", 0); > + > + /* Write the so's data to the memory mapped file. */ > + write(mem_fd, buffer.data(), buffer.size()); > + > + /* Generate the /proc/self/fd/[num] path */ > + std::string prof_self_fd_path; /* break-here */ > + std::stringstream prof_self_fd_path_stream = std::stringstream(prof_self_fd_path); > + prof_self_fd_path_stream << "/proc/self/fd/" << mem_fd; > + > + /* Call dlopen on it */ > + handle = dlopen (prof_self_fd_path_stream.str().c_str(), RTLD_LAZY); > + if (!handle) > + { > + fprintf (stderr, "%s\n", dlerror ()); > + exit (1); > + } > + /* YAY it worked */ > + dlclose (handle); > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/solib-proc-self.exp b/gdb/testsuite/gdb.base/solib-proc-self.exp > new file mode 100644 > index 00000000000..b59ba357492 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/solib-proc-self.exp > @@ -0,0 +1,86 @@ > +# Copyright 2007-2022 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 . */ > + > +# Test connecting and disconnecting at shared library events. > + > +if {[skip_shlib_tests]} { > + untested "could not run to main" > + return 0 > +} > + > +standard_testfile .cc > + > +# Chose random lib > +set libfile so-disc-shr > +set libsrc "${srcdir}/${subdir}/${libfile}.c" > +set libname "${libfile}.so" > +set libobj [standard_output_file ${libname}] > + > +# Compile the shared lib > +if { [gdb_compile_shlib $libsrc $libobj {debug}] != ""} { > + return -1 > +} > + > +# Compile test > +if [ prepare_for_testing "failed to prepare" $testfile $srcfile "list shlib_load debug c++ additional_flags=-DSHLIB_NAME=\"${libobj}\"" ] { > + return -1 > +} > + > +gdb_exit > +gdb_start > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load ${binfile} > +gdb_load_shlib $libobj > + > +if ![runto_main] then { > + return 0 > +} > + > +# Get inferior's PID for later > +set inferior_pid -1 > +gdb_test_multiple "info inferior 1" "get inferior pid" { > + -re "process (\[0-9\]*).*$gdb_prompt $" { > + set inferior_pid $expect_out(1,string) > + pass $gdb_test_name > + } > +} > + > +# Turn on the solib-events so we can see that gdb resolves everything correctly > +gdb_test_no_output "set stop-on-solib-events 1" > + > +# I use this breakpoint to get the memory mapped fd. > +gdb_breakpoint [gdb_get_line_number "break-here"] > +gdb_continue_to_breakpoint "break-here" ".* break-here .*" > + > +set msg "Getting MEMFD" > +set memfd "" > +gdb_test_multiple "p mem_fd" $msg { > + -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { > + set memfd $expect_out(1,string) > + pass $msg > + } > +} > + > +gdb_test "continue" "Stopped due to shared library event.*" "continue to load" > + > +# Check if inferior resolved the /proc/self/fd/[num] to /proc/[pid]/fd/[num] > +set msg "Inferior's /proc/self resolving $inferior_pid $memfd" > +set inferior_proc_self_path "" > +gdb_test_multiple "continue" $msg { > + -re "Attempting to replace `self` with inferior's PID. -> (\/proc\/$inferior_pid\/fd\/$memfd\[^\r\n\]*)\r\n.*$gdb_prompt $" { > + set inferior_proc_self_path $expect_out(1,string) > + pass $msg > + } > +} > -- > 2.38.0