From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 3D7713858416 for ; Fri, 22 Oct 2021 17:34:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D7713858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42e.google.com with SMTP id k7so2697496wrd.13 for ; Fri, 22 Oct 2021 10:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/lRvf0omf/nB1+VJyXCGgLWAtUDB7YREKAssZM0fNlI=; b=HvQO671Uw+Mf33kdfgA6TtvpEn7qb9M2GprYjjSXWDg7K+K7tSrkYzUtaLpYR6+S6J LlTeS9IgdacNcsUZclL9KGWE9e+lGMVqjdqRl7t9Eeow8uXL2gRpYa073dGuSiYYOhWu PG58Y5Kq0mgOs61N7ilhbc+PS28sM9R9IjyPAGM34xZRZB2OA8kBtJ6G9EYXaE/Epn9t oHQDlEF2j2O951wFi6M1g6G82uxY+GtHYewvUUuHgzquXBAmJ5OMD1rt1x4xv1oTAS05 64y/vhg3i7Ji402i7Rhr5euZXX1PytTo+89a2VwmrdBdbP+lxX+0+kqDeqjKubUNJML/ oTMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/lRvf0omf/nB1+VJyXCGgLWAtUDB7YREKAssZM0fNlI=; b=pEHT7e39LqPMThumyp5YMh2DkffwoVm2/As7vdkuNmnFcPviFLudKil6MB4SXSitOz pJLrcQqa6urI0lauNIh2QQ6zXzlZDykZKKhONS26erQgneC8NypQZmd7utg0bB+2S7Jb elfSQxjNZkuMMLESWi5jO93POPenQQEd3yFBeMXjNWouiYVuKiIRVpyfp2B+vUD0r/Fn iLj0zCjLt5ZKReP5b4FWHW0SjqofC6NT0/DPCT60uPparvSqLRQc7J9xqdPSocChqt29 betETLw8uGrJCC3ZtPcVkkpuag+ac9uEIOnL00LHY/tBVXn/4jDOjRzaBpvsB7CJ2eDf E0iw== X-Gm-Message-State: AOAM53309veAvsvO/ZZGf9qLNROSrAGfiAfwRS60pt0kznStpM1F3yHs jHPfMjl+t6EKu4mAL/sfRMPBsG2Ra2QvCA== X-Google-Smtp-Source: ABdhPJw6HyubDxjnv7zS3Vp7zqRZcWrT4wDe221bBVJwUjXQaClM4PxpXsKLtP+AOleaC9gQrDBlKQ== X-Received: by 2002:a05:6000:1567:: with SMTP id 7mr1494530wrz.408.1634924047381; Fri, 22 Oct 2021 10:34:07 -0700 (PDT) Received: from localhost (host212-140-123-151.range212-140.btcentralplus.com. [212.140.123.151]) by smtp.gmail.com with ESMTPSA id z1sm8850541wre.21.2021.10.22.10.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 10:34:07 -0700 (PDT) Date: Fri, 22 Oct 2021 18:34:06 +0100 From: Andrew Burgess To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/5] gdb/python: new gdb.architecture_names function Message-ID: <20211022173406.GH19507@embecosm.com> References: <5cbb45ba-2184-3535-b7a0-67d7fab819b0@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5cbb45ba-2184-3535-b7a0-67d7fab819b0@polymtl.ca> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 18:12:36 up 1 day, 8:46, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2021 17:34:09 -0000 * Simon Marchi [2021-10-22 09:02:04 -0400]: > Hi Andrew, > > Sorry to reply only after you have merged this. I just have a question > about the API. Not a problem, better to get this sorted if something isn't right. > > On 2021-10-13 17:59, Andrew Burgess wrote: > > Add a new function to the Python API, gdb.architecture_names(). This > > function returns a list containing all of the supported architecture > > names within the current build of GDB. > > > > The values returned in this list are all of the possible values that > > can be returned from gdb.Architecture.name(). > > Did you consider having a `gdb.architectures()` function, that returns a > list of gdb.Architecture objects? And then, if you want the names, you > use gdb.Architecture.name: > > for arch in gdb.architectures(): > print(arch.name) Except I don't believe this would work. A gdb.Architecture goes 1:1 with a gdbarch object, and we can have multiple gdbarch objects for the same underlying bfd architecture. For example, if two targets have the same bfd-architecture, but different target descriptions, you'll get different gdbarch objects, and different gdb.Architecture objects. So, in your above code you have to at least filter for duplicates. Then, as I understand it, gdbarch objects are only created "on demand", so in a multi-arch GDB, if I pass an x86 ELF, I don't believe a risc-v gdb.Architecture is ever created. So, in your above code, you'll only see the names of architectures that the user has exposed to GDB. That doesn't mean a gdb.architectures() method wouldn't be useful in some other situation, I just don't think it did what I wanted - tell me all the architectures this GDB knows about. Maybe what I should do is add an architecture_created event, then I could do: def do_something(arch): print(arch.name) for arch in gdb.architectures(): do_something(arch) def handler(event): do_something(event.architecture) gdb.events.architecture_created.connect(handler) > > Being able to get the gdb.Architecture objects instead of just the name > sounds more flexible / future-proof to me. I don't think I'm worried that adding this API will be something we regret. gdb.Architecture already has a .name method, so being able to ask for the set of all possible names doesn't seem unreasonable. For that reason, I'd like to keep the existing method, even if you think that the above would be a better API... > Like, we have > `gdb.breakpoints()`, not `gdb.breakpoint_nums()`. But there is perhaps > a technical reason why this doesn't work or isn't a good idea. The only different I see is that the names can exist before the corresponding architectures, and we can have multiple architectures per name, it would be like if gdb.breakpoint_nums() only returned the numbers 1 -> 10 because we could only have that many breakpoints, but, then we could actually have multiple breakpoints for each number...... OK, this analogy got weird... I've added the above additional APIs to my todo list, and I'll try to get them implemented. Thanks, Andrew