From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D8AED3858D33 for ; Tue, 7 Nov 2023 13:18:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8AED3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8AED3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699363117; cv=none; b=QHt9s3GYIazSnkmSRjWtuCCeI8akp2hJ1P8faVVEOhZUxHLBBl3PU8YH8klQNSxOadaVZ1WCkOYyagVcoingl+cV3tQfbX3ogIJCd+0d8yN1qYbF6w6Z6YWA9s9yuO3TLyWCSwKy82w85UBuQ97I1FIdV/j5tf/L2V4kKFy6zzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699363117; c=relaxed/simple; bh=vS9zvAFtOtyoH3JomVx0XuaSiTDFIFOR8v++vJtTGhA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=fwydRMTcrYs85tzgdu51QK0jgXnn2kbR9D+U+nB0o6e71AmYXHN+6p7oYsPKyFu0AJ6oKnA4URaFolvuSOvXPc6j/cq6/Y9KsAhzpLH2pmH1tosY4wTR5nhSjjcnnWdZJlEh/IDdYdNlVnN2o8iF0BUOAtn9/oYRWX0kyikgCDc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 136F42191A for ; Tue, 7 Nov 2023 13:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699363115; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZKPpF2kqOgmOcq8kKO0+d9GLL7EDFXCEXMWCWVWEPjk=; b=x2cARQlooLmdJhubQnvORu4wr9JccRSD6ek8QPfaUICHw6EEPODccDjuNnRV/I0BgxFH9m Zq5VlbJM9zhdbCqSSwjGKarHQQRP4h/ndk92V/ndXAnBYhN1wt1fnAvKes4znf+A8rL6Jz C73mwCvCH/P9cbQFTMMEgryqwruLemk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699363115; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZKPpF2kqOgmOcq8kKO0+d9GLL7EDFXCEXMWCWVWEPjk=; b=SP1g7Tm2Or+AhigmghfRiDm76j4fLsAkI8pWpfUffWFYFebKLxtoH22/Pw7JBd106KDJg5 cqCgtvTZjwHBTHAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F271313907 for ; Tue, 7 Nov 2023 13:18:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +LcNOio5SmUCXQAAMHmgww (envelope-from ) for ; Tue, 07 Nov 2023 13:18:34 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 0/2] [gdb] Fix segfault in for_each_block Date: Tue, 7 Nov 2023 14:19:48 +0100 Message-Id: <20231107131950.3083-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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: This patch series fixes PR gdb/30547, a segfault when running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x). There are two patches, each of them by themselves sufficient to no longer trigger the segfault. The root cause of the problem is that linux_is_uclinux, and consequently gdbarch_has_shared_address_space returns an incorrect value. The first patch makes gdb more robust against gdbarch_has_shared_address_space returning incorrect values, by eliminating a call to it. The second patch addresses the root cause. Tested on top of trunk on x86_64-linux and ppc64le-linux. Tested on top of gdb-14-branch on ppc64-linux. [ I used gdb-14-branch for ppc64-linux, because I can't build trunk anymore with system gcc 4.8.5 (CentOS-7), due to the recent c++17 requirement (and just before that, some gcc bug in atomic support), and that's all I have readily available on that machine. ] There is still scope to fix things further. When I started to investigate, I noticed that I only ran into the segfault on ppc64 and s390x, two big-endian architectures, so I sort of expected to find an endian-related problem. Instead, the problem was ppc_linux_target_wordsize returning 4 instead of 8, which causes gdb to interpret the 8-byte entry auxv vector using 4-byte words, causing an incorrect linux_is_uclinux == true. The same problem happens on ppc64le (ppc_linux_target_wordsize returns 4), it's just that the incorrect word size doesn't change the outcome of: - target_auxv_search (AT_NULL, &dummy) == 1, and - target_auxv_search (AT_PAGESZ, &dummy) == 1 so linux_is_uclinux returns false, as it should. This suggest a too forgiving parsing of the auxv vector, which should be made more strict. Finally, it should be fixed that ppc_linux_target_wordsize returns 4 in a process with wordsize == 8. I added an assert that PTRACE_PEEKUSER doesn't fail (errno != 0) and ran into it in test-case gdb.base/access-mem-running.exp, during trying to "set a breakpoint while the process is running". It's clear that it's quite common for this to happen, and it's surprising that this doesn't cause more problems. I'll eventually file PRs for these two issues, for now my interest is to backport at least one, possibly both patches from this series to fix this PR on the gdb 14 release branch (and the 13.2 based distro packages I maintain). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547 Tom de Vries (2): [gdb] Fix segfault in for_each_block, part 1 [gdb] Fix segfault in for_each_block, part 2 gdb/infrun.c | 12 +++++++++++- gdb/progspace.c | 37 +++++++++++++++++++++++++++---------- gdb/progspace.h | 11 ++++++++++- 3 files changed, 48 insertions(+), 12 deletions(-) -- 2.35.3 Tom de Vries (2): [gdb] Fix segfault in for_each_block, part 1 [gdb] Fix segfault in for_each_block, part 2 gdb/breakpoint.c | 29 ++++++++++++++++------------- gdb/inferior.c | 8 ++------ gdb/inferior.h | 2 +- gdb/infrun.c | 28 +++++++++++++++++++--------- gdb/linux-nat.c | 2 +- gdb/process-stratum-target.c | 2 +- gdb/progspace.c | 29 +++++++++++++++++------------ gdb/progspace.h | 5 +++-- gdb/record-btrace.c | 2 +- gdb/regcache.c | 2 +- gdb/target-dcache.c | 11 ++++++----- 11 files changed, 68 insertions(+), 52 deletions(-) base-commit: d1bd9787f9ad8c49fb463d8d53411aeb5f9c179b -- 2.35.3