From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mc1aDy8z2WpICQkAWB0awg (envelope-from ) for ; Wed, 21 Oct 2026 17:48:31 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GlZc2PCP; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1BC191E04D; Wed, 21 Oct 2026 17:48:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id EC91E1E04D for ; Wed, 21 Oct 2026 17:48:29 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D16C34BA23E1 for ; Wed, 21 Oct 2026 21:48:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D16C34BA23E1 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GlZc2PCP Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 15F634BA2E2C for ; Wed, 21 Oct 2026 21:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15F634BA2E2C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 15F634BA2E2C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792619282; cv=none; b=O3IdWmhFlPNlMkDxc59r2w77apVCnknbd5H1hNP1078K+d/egHHtb6Z/ojxra5paK2LjA4c/AO3DFaHUBAjb9pBwVKqWN7VAw885XfWouuNR8ZM3CD330XCqXco9Vv2VprV9H45MWMzwY0iqlqyp06m8U1lxiineH9lqQbhOo2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792619282; c=relaxed/simple; bh=w0y1Kqsz+BPBioqfQf0rsTr2uKUGwA5Rut1ESALMl1A=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FfRT8dF9+PMC791w6Qmd1eM8Sn5G8Z0NBAHpMArEvndSySu31B9fAUXff0nwsaZI6bDRJhsEW6OU07qkSrCTSaROx9Qb2oQyXkZYfU1Jw3SzsadBkYFjlXzqDnNHZgb3Fz8XWEqmHkdh5hFprxFd2yd/NpnzkSd7Xp9dZMlCZnU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GlZc2PCP DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15F634BA2E2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792619281; 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: content-transfer-encoding:content-transfer-encoding; bh=0wjpgL4UgSfsfSYyyZ9TrfiWmUxyHTCM9tHiJkuzIiY=; b=GlZc2PCPTaTrTcQEKceCx8VPWzjKviskF2XamsN46haaWJYniuWd4cgXtcRRt1bkBvGekb AYrPBywQZFE4prZEewxXf/2MR11cdEnrOAhYA23la+EKfxMoAlm5fhRNwU6azWTSRk73yG vXBZaO4HjovTyMbZDdvWJCaB29qGwPY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-xLBgRDK7NRqRcIaHCQTMKQ-1; Wed, 21 Oct 2026 21:48:00 +0000 X-MC-Unique: xLBgRDK7NRqRcIaHCQTMKQ-1 X-Mimecast-MFC-AGG-ID: xLBgRDK7NRqRcIaHCQTMKQ_1792619279 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48b01a74792so798359f8f.0 for ; Wed, 21 Oct 2026 14:48:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792619279; x=1793224079; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0wjpgL4UgSfsfSYyyZ9TrfiWmUxyHTCM9tHiJkuzIiY=; b=MHd1xFGFWKuIBQfU74i9e9AytrBmzVzDeGEOS/hynf4JdoQcN6NRW+vRpeY3o9p/6M wV9gS7alLS6Bo2a6KeKB8806s2gljDL8evBWWeXBvtGZnq4ng8ARdbeeRWp8FRbRnw+v mhxS4WVZc35ve0xCfEHczl6gLz6BRfyEII2ljIgtzsPXvid3H9une67TUZtCnaz47kv6 njc93Qh341psmgCDF8TfmjlzDuQnRw54rq7Jrgc02cUXUQTTYliXrhbL0wgm9ZNOxLwn QWWCn9h2qv8rCkx0bRqn4+CDc9SylonoduDeb4318AJJ11kqUmGRqbxNe0NREAQiVt84 IMyg== X-Gm-Message-State: AFq9FYJZ9SlqO2L9e7jI7tZkcaBPc4RWtn9OgQ4uev8L2qDyvI7wPbB7 tq+2I0w90P1Oy8vFVVuCj4A1ifYv4e8lc3pdZOeDbU5GsLUW/GNqGJkUcWBEYvhbMREjsGmoWx/ Yfj3tabmftECGt8k2GtPoPdG5aIkXbtdeTbUQr68nM5/dBHccJ7khnraZcvgOa61DoBWI1rfBKF i7a3zhw6Vj5MkDrnlBc51VmIGtBzjtGPXuiqzn4OI2HYRJ/bk= X-Gm-Gg: AYBFou095XWO7o22taGN8t9xvdSxvMmhowADcOfw8jbYKkb69C+cwqUPpkPsHDj31dV dCgx7lGCTxUdYVdzQQWlYPvQf9oaBwHmmoPxx02UMfXG3uwZGDCD2eMCMN9vYJOJYdnOrmMkARf plYEtafYy0h3A67jSw+SDRG90oUbRyCYNnHUJjW16LhGcXJ/b9MLsedNvalGimaeCS+WWUaas+Z 7kocR8Y+bmAxQ5myETSI+dByaCBNIPdHxb8Szi+MEOM7X5xDrLl8qhyM6ZSkjwJC4f9Licpd3LW a7C2mivVLKm7DER9RwDBiWiSHfDolErHmrqtUVHkfCgHGYFc48CBpBT/c8M2TFx/5HOj X-Received: by 2002:a05:6000:1866:b0:48e:412:37f4 with SMTP id ffacd0b85a97d-48e2641de1amr8242195f8f.1.1792619279192; Wed, 21 Oct 2026 14:47:59 -0700 (PDT) X-Received: by 2002:a05:6000:1866:b0:48e:412:37f4 with SMTP id ffacd0b85a97d-48e2641de1amr8242165f8f.1.1792619278623; Wed, 21 Oct 2026 14:47:58 -0700 (PDT) Received: from localhost ([213.31.44.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e2581fa7fsm7535468f8f.17.2026.10.21.14.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2026 14:47:57 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb: add debug_file_directory changed observer Date: Wed, 21 Oct 2026 22:47:54 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: BVfWIqoBYdgN0Q00RI83TDfqTkpMrD4xkYtQOlOHS3U_1792619279 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Add a new observer gdb::observers::gdb_debugdir_changed, this is triggered whenever the debug_file_directory is updated. This new observer is analogous to the existing gdb_datadir_changed observer. I was motivated to add this when trying to understand some code in auto-load.c, in file_is_auto_load_safe we call filename_is_in_auto_load_safe_path_vec, and if this fails we call auto_load_safe_path_vec_update, then filename_is_in_auto_load_safe_path_vec again. This seemed weird to me, why would we need to update the safe path vector again at this point? I think there are two reasons why this might be needed (before this patch): 1. If the definition of $debugdir changes then the vector needs to be rebuilt based on the new value, and 2. If any symlinks on the filesystem change the gdb_realpath might return new directory or filenames, which would then cause different things to match. The first case here is similar to $datadir, but for $datadir we have an observer which triggers an update of the safe path vector as soon as the variable changes. I figure that it makes sense to add an observer for the $debugdir case too. This leaves just case (2) as being the motivation for rebuilding the vector in the auto-load code. I've also added a comment about this too the code. --- gdb/auto-load.c | 18 +++++++++++++++--- gdb/observable.c | 1 + gdb/observable.h | 4 ++++ gdb/symfile.c | 12 +++++++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/gdb/auto-load.c b/gdb/auto-load.c index ccbd091e1c2..6dff57ec38b 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -298,10 +298,11 @@ auto_load_safe_path_vec_update (void) } } -/* Variable gdb_datadir has been set. Update content depending on $datadir. */ +/* One of the variables gdb_datadir or debug_file_directory might have + changed. Update content depending on $datadir and $debugdir. */ static void -auto_load_gdb_datadir_changed (void) +auto_load_gdb_vars_changed () { auto_load_safe_path_vec_update (); } @@ -503,6 +504,15 @@ file_is_auto_load_safe (const char *filename) if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real)) return true; + /* The reason for rebuilding the vector, and retrying the match at + this point is in case the user has updated some symlinks on their + file system. Rebuilding the safe path vector calls gdb_realpath + on each entry and adds the result to the vector. As a result, if + any symlinks change then this update will change the set of paths + we consider safe. + + This does mean that a stale entry might trigger a match in the + above check, for now though we just accept this risk. */ auto_load_safe_path_vec_update (); if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real)) return true; @@ -1677,7 +1687,9 @@ This option has security implications for untrusted inferiors."), show_auto_load_safe_path, auto_load_set_cmdlist_get (), auto_load_show_cmdlist_get ()); - gdb::observers::gdb_datadir_changed.attach (auto_load_gdb_datadir_changed, + gdb::observers::gdb_datadir_changed.attach (auto_load_gdb_vars_changed, + "auto-load"); + gdb::observers::gdb_debugdir_changed.attach (auto_load_gdb_vars_changed, "auto-load"); cmd = add_cmd ("add-auto-load-safe-path", class_support, diff --git a/gdb/observable.c b/gdb/observable.c index 151014590a8..6a658303ee9 100644 --- a/gdb/observable.c +++ b/gdb/observable.c @@ -63,6 +63,7 @@ DEFINE_OBSERVABLE (inferior_cloned); DEFINE_OBSERVABLE (memory_changed); DEFINE_OBSERVABLE (before_prompt); DEFINE_OBSERVABLE (gdb_datadir_changed); +DEFINE_OBSERVABLE (gdb_debugdir_changed); DEFINE_OBSERVABLE (inferior_call_pre); DEFINE_OBSERVABLE (inferior_call_post); DEFINE_OBSERVABLE (register_changed); diff --git a/gdb/observable.h b/gdb/observable.h index 979e9d1c3ac..9fe5cd44c4d 100644 --- a/gdb/observable.h +++ b/gdb/observable.h @@ -213,6 +213,10 @@ extern observable before_prompt; change. */ extern observable<> gdb_datadir_changed; +/* Variable debug_file_directory has been updated. The value may not + necessarily have changed. */ +extern observable<> gdb_debugdir_changed; + /* An inferior function at ADDRESS is about to be called in thread THREAD. */ extern observable diff --git a/gdb/symfile.c b/gdb/symfile.c index 017f7a49d8d..f8a7378120f 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1340,6 +1340,16 @@ show_debug_file_directory (struct ui_file *file, int from_tty, value); } +/* Implement 'set debug-file-directory' command. */ + +static void +set_debug_file_directory (const char *args, int from_tty, + struct cmd_list_element *e) +{ + /* The new value has already been installed by this point. */ + gdb::observers::gdb_debugdir_changed.notify (); +} + #if ! defined (DEBUG_SUBDIRECTORY) #define DEBUG_SUBDIRECTORY ".debug" #endif @@ -3885,7 +3895,7 @@ Separate debug symbols are first searched for in the same\n\ directory as the binary, then in the `" DEBUG_SUBDIRECTORY "' subdirectory,\n\ and lastly at the path of the directory of the binary with\n\ each global debug-file-directory component prepended."), - NULL, + set_debug_file_directory, show_debug_file_directory, &setlist, &showlist); base-commit: 13db356ae83f72de0828e11826a256a4a28d17b1 -- 2.25.4