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 5A89B385624C for ; Wed, 27 Sep 2023 10:51:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A89B385624C 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=1695811915; 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=OzvbODeVsTrxqHnXdP1fvqL1FRSgGY/pEkNs5IbtLEc=; b=UKCUkwnfFH4mlqczbCCt7/e//a6YMHcGRulMw2aPeGd2cDgPV30DNfwZSt4kuBrOpkfDp3 jfJAdOrwjocNOMiJmiUCZ/jgoP2NafTQ/aCtc16Zv6ZoNnndVlhC6k7gsQkakbdoCh9+Ww 3x/UX3y6vOljm3tftFLwY8bQmRomNuI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-244-sNYfhTc3M0OTwu3TxeFL1A-1; Wed, 27 Sep 2023 06:51:53 -0400 X-MC-Unique: sNYfhTc3M0OTwu3TxeFL1A-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4180b3a5119so140561381cf.1 for ; Wed, 27 Sep 2023 03:51:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695811913; x=1696416713; 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=OzvbODeVsTrxqHnXdP1fvqL1FRSgGY/pEkNs5IbtLEc=; b=kokhWEPsRQxLJZXmVyhZ0UTXVx2Y+r9v+EXHZkTpZpeic7B1eBhLPp/y4Z23OIFSl8 1t9KFEa+B5s64XMFuMg4g8iUaD4VmgnezDNGhsVde1YLinOERsv4s/H2BChbixAQ59Qk 9CWg5UzrDQ8BQve+qqTegKWfOu2K90TZWX/0SkcXd8a/hkxscgAwWEltixcyw/rPFe3W lsVRXY14mDbmTYBVqZ5sPFV+c0Y4J0YtQgANNv7I1I/2htZ64ym0ciSVimvAT6aQvn2r 4NeKv6LHHd5sXXJRq5TGzNxveDMYXBPIgwH/PSW2UjI8qXx7IsJwFcDn/l51rZFuRY9c lriw== X-Gm-Message-State: AOJu0Yxzr7zJsYcQ5yuE3sKYU0RZIERUSOeoDgDfGVid8sPoCfXJdThc CPqafjYSJzPDMxsoAbP80JcfoCKHVoc/wYIS/duW1IgiZ3cOC4hDrbjQ8ulVDUF5u/QjTuuKW8v Ry+ekxpT3yDVBYvngk8PcdxbJiAQ4yg== X-Received: by 2002:a05:622a:1496:b0:40e:6f1:3d38 with SMTP id t22-20020a05622a149600b0040e06f13d38mr1941521qtx.8.1695811913256; Wed, 27 Sep 2023 03:51:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeTdmRw2U05Daq3i2pbLW+2mQ3wY5gd2P2QDoscQF791+qdy4Nt88KyAe0VSsSwRmg0Mqa5A== X-Received: by 2002:a05:622a:1496:b0:40e:6f1:3d38 with SMTP id t22-20020a05622a149600b0040e06f13d38mr1941513qtx.8.1695811913016; Wed, 27 Sep 2023 03:51:53 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id w22-20020a05622a191600b0041514d1da65sm5296383qtc.20.2023.09.27.03.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:51:52 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , Andrew Burgess via Gdb-patches Subject: Re: [PATCH] gdb: add Python events for program space addition and removal In-Reply-To: <87cyyb72pj.fsf@tromey.com> References: <634d50951c6a4d50b0aa8dc91758c025738e8c68.1695300249.git.aburgess@redhat.com> <87cyyb72pj.fsf@tromey.com> Date: Wed, 27 Sep 2023 11:51:51 +0100 Message-ID: <87r0mjx514.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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Tom Tromey writes: >>>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: > > Andrew> Initially I just wanted a Python event for when GDB removes a program > Andrew> space, I'm writing a Python extension that caches information for each > Andrew> program space, and need to know when I should discard entries for a > Andrew> particular program space. > > Andrew> But, it seemed easy enough to also add an event for when GDB adds a > Andrew> new program space, so I went ahead and added both new events. > > This approach seems totally fine to me, but it's worth noting that you > could attach data directly to a Progspace if the tp_hash field were > filled in. Some other Python classes in gdb do this. This makes caches > easier because the cleanup is automatic. I'm not sure I understand how tp_hash helps here? gdb.Progspace does have a __dict__ attribute, so things like: progspace.my_random_var = .... works just fine, and I did consider this. But I wasn't sure if this was "good practice". My concern was mostly that this might lead to clashes between different extensions if good names are not chosen for 'my_random_var', or even clashes between extensions and future GDB enhancements -- my understanding is that if we later added 'my_random_var' as a builtin attribute this would take precedence over the user defined attribute, breaking their extension. > > Andrew> +No @code{NewProgspaceEvent} is emitted for the very first program > Andrew> +space, which is assigned to the first inferior. This first program > Andrew> +space is created within @value{GDBN} before and Python scripts are > > Typo, "before any" Fixed, thanks. > > Other than that it looks good. I'll likely merge this anyway, this doesn't stop folk making use of the __dict__ approach if they prefer -- as you point out, it does have a significant benefit in that it automates the cleanup. > > Approved-By: Tom Tromey Thanks, Andrew