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 27852384B0CA for ; Mon, 30 May 2022 09:29:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 27852384B0CA Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-304-ikx8XwGgNBiDTniHP3b7XQ-1; Mon, 30 May 2022 05:29:25 -0400 X-MC-Unique: ikx8XwGgNBiDTniHP3b7XQ-1 Received: by mail-qk1-f199.google.com with SMTP id j12-20020a37c24c000000b006a375a433bbso8342144qkm.8 for ; Mon, 30 May 2022 02:29:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=cJMQdyR3r6jNmcfrk97dJgbwwSo3O8IbGX6K/njvYb4=; b=gZ+1S8jcWhgE+wgMMENFfVfo24V2TkFeBBnQ69epds01iQQo74T9UGLUywJC6CDHLL GauKOYdDPm6DrYdUq71uwpOdfurUjAooRRFjMtX1sAT1sNY6jq4XwH8nUotacjnlcn7Q Lg8Tt7K47fzD+7dEXBu1KPjfXGbe5I3xO0PhxEAmyOM11OJiet2W2aRIr8UpKh9WdMAU 8qzq3wopDJdRIuA3yQVulEEL/dHWfo5avq7WxH/bPcbx3pRCbeAKXlK5Eclodok1vcbc 3KFoTAEMJiTCrGAUMqeNTIjCYIl6fi5h+WD6HaVw3+s/yksf9EihjZEkQZ8LGU2hXuq/ ssQg== X-Gm-Message-State: AOAM531clwWzgkaYiXhdEEa4WAMOxfToyZ8zgPJdxgRfqYPl/bKfJWJ/ e0BHxikcXfgpHAlJbc2bzPLpc6sZnTwLOzGMcDcuzVy6ttnt1ygzoiiL0r/7evW2iE/I34SjjOV OZD9lVU/TXx6ZZwDm7jcENWaCRqMHy+rZYUTL4X+gIfqt0wxi/SbVu2jKxbyrcZ7XKo2o0rHepA == X-Received: by 2002:ac8:58ce:0:b0:304:b4e1:a892 with SMTP id u14-20020ac858ce000000b00304b4e1a892mr1216882qta.507.1653902964627; Mon, 30 May 2022 02:29:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1RIgK2SwLwHdGuAHxSaQvm1a++fOePrJSW0DZ57IzuJeh9qBnF3EmYcqFs62ZBVMoPKQ8jA== X-Received: by 2002:ac8:58ce:0:b0:304:b4e1:a892 with SMTP id u14-20020ac858ce000000b00304b4e1a892mr1216866qta.507.1653902964247; Mon, 30 May 2022 02:29:24 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id v11-20020a05622a014b00b002f918680d80sm7494103qtw.78.2022.05.30.02.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 02:29:23 -0700 (PDT) From: Andrew Burgess To: Tom Tromey via Gdb-patches , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Add gdb.current_language function In-Reply-To: <20220527173642.1180218-1-tromey@adacore.com> References: <20220527173642.1180218-1-tromey@adacore.com> Date: Mon, 30 May 2022 10:29:21 +0100 Message-ID: <871qwbfjwu.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=-9.6 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 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: Mon, 30 May 2022 09:29:29 -0000 Tom Tromey via Gdb-patches writes: > This adds the gdb.current_language function, which can be used to find > the current language without (1) ever having the value "auto" or (2) > having to parse the output of "show language". I think you should also add Frame.current_lanaguage, and the docs for gdb.current_lanaguage should make it clear that the Frame method should be used in preference where a Frame is available. I understand that there the current language does change GDB's behaviour in places where there is no inferior and therefore no frame, so I guess we probably do want both methods, which is a bit of a shame, but can't be helped. Having a Frame method means users don't need to switch frames just to figure out the lanague of a specific frame. Adding the method now means users wont be tempted to write code that relies on the global method, which could lead to the wrong result in some cases. Thanks, Andrew > --- > gdb/NEWS | 4 ++++ > gdb/doc/python.texi | 6 ++++++ > gdb/python/python.c | 12 ++++++++++++ > gdb/testsuite/gdb.python/py-parameter.exp | 13 +++++++++++++ > 4 files changed, 35 insertions(+) > > diff --git a/gdb/NEWS b/gdb/NEWS > index 52ffdc4c83a..2e87f8d56f3 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -51,6 +51,10 @@ maintenance info line-table > This is the same format that GDB uses when printing address, symbol, > and offset information from the disassembler. > > + ** New function gdb.current_language() that returns the name of the > + current language. Unlike gdb.parameter('language'), this will > + never return 'auto'. > + > *** Changes in GDB 12 > > * DBX mode is deprecated, and will be removed in GDB 13 > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index cb5283e03c0..0767e157e4a 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -667,6 +667,12 @@ Here are some examples of the possible string formats: > @end smallexample > @end defun > > +@defun gdb.current_language () > +Return the name of the current language as a string. Note that, > +unlike @code{gdb.parameter(language')}, this function will never > +return @samp{auto}. > +@end defun > + > @node Exception Handling > @subsubsection Exception Handling > @cindex python exceptions > diff --git a/gdb/python/python.c b/gdb/python/python.c > index 11aaa7ae778..9bef2252e88 100644 > --- a/gdb/python/python.c > +++ b/gdb/python/python.c > @@ -1571,6 +1571,14 @@ gdbpy_progspaces (PyObject *unused1, PyObject *unused2) > return list.release (); > } > > +/* Return the name of the current language. */ > + > +static PyObject * > +gdbpy_current_language (PyObject *unused1, PyObject *unused2) > +{ > + return host_string_to_python_string (current_language->name ()).release (); > +} > + > > > /* The "current" objfile. This is set when gdb detects that a new > @@ -2534,6 +2542,10 @@ Format ADDRESS, an address within PROG_SPACE, a gdb.Progspace, using\n\ > ARCH, a gdb.Architecture to determine the address size. The format of\n\ > the returned string is 'ADDRESS ' without the quotes." }, > > + { "current_language", gdbpy_current_language, METH_NOARGS, > + "current_language () -> string\n\ > +Return the name of the currently selected language." }, > + > {NULL, NULL, 0, NULL} > }; > > diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp > index 199d3bc16ec..fcafa7ee717 100644 > --- a/gdb/testsuite/gdb.python/py-parameter.exp > +++ b/gdb/testsuite/gdb.python/py-parameter.exp > @@ -370,6 +370,19 @@ proc_with_prefix test_throwing_parameter { } { > "gdb.GdbError does not show Python stack" > } > > +proc_with_prefix test_language {} { > + gdb_test "python print(gdb.parameter('language'))" "auto" \ > + "print language parameter" > + gdb_test "python print(gdb.current_language())" "c" \ > + "print current language" > + gdb_test_no_output "set lang rust" > + gdb_test "python print(gdb.parameter('language'))" "rust" \ > + "print language parameter for rust" > + gdb_test "python print(gdb.current_language())" "rust" \ > + "print current language for rust" > + gdb_test_no_output "set lang auto" > +} > + > test_directories > test_data_directory > test_boolean_parameter > -- > 2.34.1