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 9DCA83858C41 for ; Tue, 7 Nov 2023 11:16:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DCA83858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9DCA83858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699355772; cv=none; b=sQYvJkJK14iWIuU70oaOTjdr9JrT0xpxf9NGXJXx1a17QZdmdDJ6GT/nFm63XROjrNWo0Pzx5AmIQGmk0EALU4SKKVzy905a7twmgM6tfN7o0FiwfCWF3m90PJJPcMJetK8mkGTkYSzFkY+/0C2w1OvSxPPjhZtpeUP+FfVwZSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699355772; c=relaxed/simple; bh=4XK8T7WfuVM6gTPeowpT5R/tASPp4u2isDwXC2GkIck=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uDRbIuQB6a3WL9pLX0Lbb1T9XSmN0keqzUtlfe7O7kRrIOx4cn6JEz8qrR9QER9zDYjBuJB0vJDL1vuT+9KZ4wm178bZJD+Ni+c8zx6cPIm9cnihj3AGU3oKpi7BktPp2xBViShB6zkd5h77az5M4IquAvD0wWmyJgck00i2RuE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699355770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QICP3z3YbIVGh+lyE/Ac+1uCuZz+JTYMnR1z5WaYvAw=; b=EIXZld1DMepyW6102+1cC0PLM+AigEZgcpSE45EFJIeqCzpMTD9yBADtAW4SzFGMn2FP9g EtnHap8UoyN9rrBQwjR1BnV21Z4NOL0s5rr8oRIAlKwI9QsDY4fxclgLH63VQHbyRBguaD y9UEENLrU9rksSmDyK8tRYfiMKZFYCg= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-FbtTtdxhMzOdc9rTZhsKdg-1; Tue, 07 Nov 2023 06:16:08 -0500 X-MC-Unique: FbtTtdxhMzOdc9rTZhsKdg-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-507d4583c4cso5911753e87.1 for ; Tue, 07 Nov 2023 03:16:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699355767; x=1699960567; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QICP3z3YbIVGh+lyE/Ac+1uCuZz+JTYMnR1z5WaYvAw=; b=hPxaEo4pZzQPZ5z1AmgUJd0MRKG5S1UNjcGq+86CLuQ/VGpqNwuHa06seVFPwM9SYZ cya/7YGoHXVu7WgCciDicTU7I3kN5S9A2/jZqNWHlFjyWbs4bTCHyJyUxLDv5Q7XZwV7 r2dInh4ZXsVdtbVJt/5HfMEwHXYqS431tUUmr1NiA+zZmqxBrUdvXk0ok5WrJn961v1p +hrP8OiRIrkKNYMb7dYv4KvFSvojyZKcSKmUD3PN+BnQ3lPatWThkgKT1v9SuLB2qI52 Kjhw+NuIbzSEQRwdkKuLNir1cNx6t9rJjK6Dl3S6GukVim0AVpbmEUyEUejH12f/BswI hgNQ== X-Gm-Message-State: AOJu0YxH3NQ6eBe94pXmg4hBunlig79fnlNVdEhw92r/tzUdemI/mhSI 11JnXH4cAlvk3cAsZV5+n6ZklozX0gwYyMxpD0QyIjzZ37h/8XXNjaCXAWGDWBb3JREqSD7ChqE noWdC+Gzwzdpp/LGXDA/c7FasXGNN/Q== X-Received: by 2002:a05:6512:3f0b:b0:507:c507:c9b6 with SMTP id y11-20020a0565123f0b00b00507c507c9b6mr30046489lfa.41.1699355767150; Tue, 07 Nov 2023 03:16:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUUAPg1n8uA+oNx+8OdFvyr9kWDHeapQkx4XvJtvTPcQu+tysMZK205bv/Z6zFmV5alZM9WQ== X-Received: by 2002:a05:6512:3f0b:b0:507:c507:c9b6 with SMTP id y11-20020a0565123f0b00b00507c507c9b6mr30046465lfa.41.1699355766728; Tue, 07 Nov 2023 03:16:06 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id j19-20020a05600c1c1300b004060f0a0fd5sm15438527wms.13.2023.11.07.03.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 03:16:06 -0800 (PST) From: Andrew Burgess To: Simon Marchi , Tom de Vries , gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] [gdb] Fix segfault in for_each_block, part 1 In-Reply-To: <3040273d-76d9-43a3-a9a6-5b7225276cc6@simark.ca> References: <20231104155757.16649-1-tdevries@suse.de> <20231104155757.16649-2-tdevries@suse.de> <3040273d-76d9-43a3-a9a6-5b7225276cc6@simark.ca> Date: Tue, 07 Nov 2023 11:16:04 +0000 Message-ID: <87fs1hu83v.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=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Simon Marchi writes: > On 11/4/23 11:57, Tom de Vries wrote: >> When running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise >> on s390x), I run into: >> ... >> (gdb) PASS: gdb.base/vfork-follow-parent.exp: \ >> exec_file=vfork-follow-parent-exit: target-non-stop=on: non-stop=off: \ >> resolution_method=schedule-multiple: print unblock_parent = 1 >> continue^M >> Continuing.^M >> Reading symbols from vfork-follow-parent-exit...^M >> ^M >> ^M >> Fatal signal: Segmentation fault^M >> ----- Backtrace -----^M >> 0x1027d3e7 gdb_internal_backtrace_1^M >> src/gdb/bt-utils.c:122^M >> 0x1027d54f _Z22gdb_internal_backtracev^M >> src/gdb/bt-utils.c:168^M >> 0x1057643f handle_fatal_signal^M >> src/gdb/event-top.c:889^M >> 0x10576677 handle_sigsegv^M >> src/gdb/event-top.c:962^M >> 0x3fffa7610477 ???^M >> 0x103f2144 for_each_block^M >> src/gdb/dcache.c:199^M >> 0x103f235b _Z17dcache_invalidateP13dcache_struct^M >> src/gdb/dcache.c:251^M >> 0x10bde8c7 _Z24target_dcache_invalidatev^M >> src/gdb/target-dcache.c:50^M >> ... >> or similar. >> >> The root cause for the segmentation fault is that linux_is_uclinux gives an >> incorrect result: it should always return false, given that we're running on a >> regular linux system, but instead it returns first true, then false. >> >> In more detail, the segmentation fault happens as follows: >> - a program space with an address space is created >> - a second program space is about to be created. maybe_new_address_space >> is called, and because linux_is_uclinux returns true, maybe_new_address_space >> returns false, and no new address space is created >> - a second program space with the same address space is created >> - a program space is deleted. Because linux_is_uclinux now returns false, >> gdbarch_has_shared_address_space (current_inferior ()->arch ()) returns >> false, and the address space is deleted >> - when gdb uses the address space of the remaining program space, we run into >> the segfault, because the address space is deleted. >> >> Hardcoding linux_is_uclinux to false makes the test-case pass. >> >> We leave addressing the root cause for the following commit in this series. >> >> For now, prevent the segmentation fault by making the address space a refcounted >> object. >> >> This was already suggested here [1]: >> ... >> A better solution might be to have the address spaces be reference counted >> ... > > That reminded me of a patch I started to work on a while ago to remove > program_space::aspace, which I have to get back to. The rationale is > that there might be a 1:N relation ship between one program space and > many address spaces (see diagram in progspace.h), so having this one > pointer does not represent well the relationship. An inferior is always > bound to a single address space, so my patch changes the code to use > inferior::aspace instead. I also started looking at this after our previous discussion on address_space pointer sharing :) > > I think that even with my patch, we would still have the problem of > knowing when to delete an address space. When you have many inferiors > sharing an address space, and you delete an inferior, how do you know if > you should delete the address space? Perhaps we can implement a method > like program_space::empty, but for address_space. > > However, I still think that using refcounting for address spaces (and > perhaps for program spaces too?) is a good solution. It would spare us > of having to deal with the logic of knowing when address space is no > longer used. Refcounting isn't always the right solution, but I don't > see any downsides in this case. Agreed. The biggest yuck for me was finding the address_space to assign to a new inferior when in the shared address_space case. Currently, the program_space serves as the authority that hands out the single shared address_space. With the address_space removed from the program_space, you now need to find a sibling inferior and take a reference to their address space. Not a show stopping issue by any means, I just never got around to finishing this part of the task. Thanks, Andrew > > Implementation question: is there any reason you didn't choose > std::shared_ptr? For objects that are new'ed / delete'd, that seems > like a good choice. > > Simon