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 075FB3858D3C for ; Fri, 2 Jun 2023 15:07:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 075FB3858D3C 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=1685718466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e7K+RJvG5Xd9FkManju2uX23u8QBiYaeTlaLrzrC2ac=; b=YM8mEc5NZ+q9CUwyg1dDQA8n+r9sTiGagm3cKuBv5283Hf7SKKeyV6jIKdz0/ReIsJAEo6 y1v8Ny7Aerw0swVLNqMOF7TpLiXH1QOBeJBK+uwbTCPmmBPUMETHMyN6022yvIMv32AeTp XW0nWuZRUvjlS0KG5+lyibyvta2IVmg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-DRoISVJ3M3mZElKrriRYAA-1; Fri, 02 Jun 2023 11:07:43 -0400 X-MC-Unique: DRoISVJ3M3mZElKrriRYAA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 51279101B043; Fri, 2 Jun 2023 15:07:43 +0000 (UTC) Received: from [10.22.17.181] (unknown [10.22.17.181]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13DAE492B0A; Fri, 2 Jun 2023 15:07:42 +0000 (UTC) Message-ID: Date: Fri, 2 Jun 2023 08:07:41 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH 1/1] gdb, python: fix python breakpoint with extra spec To: Christina Schimpe , gdb-patches@sourceware.org References: <20230602105946.3798356-1-christina.schimpe@intel.com> <20230602105946.3798356-2-christina.schimpe@intel.com> From: Keith Seitz In-Reply-To: <20230602105946.3798356-2-christina.schimpe@intel.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 List-Id: On 6/2/23 03:59, Christina Schimpe via Gdb-patches wrote: > For example this works as expected: > > (gdb) python bp1 = Breakpoint ("file:42") > > But here "thread 1000" is silently ignored: > > (gdb) python bp1 = Breakpoint ("file:42 thread 1000") This doesn't sound particularly idiomatic/python-y. Gdb already has getters/setters for thread, task, and other related properties. Are those insufficient in some way? The documentation for gdb.Breakpoint.__init__ says: "Create a new breakpoint according to spec, which is a string naming the location of a breakpoint." While it happens to work, "thread 1000" is not part of the location. That create_breakpoint() accepts this is simply a (messy) implementation detail that has been convenient for the CLI interpreter. If it is desired to be able to set breakpoint properties during construction, is expanding the ctor to accept a keyword not a viable, if not cleaner, option? Keith > This patch modifies `create_breakpoint` function call from the Python > implementation so that full spec string is processed. Unnecessary > string duplication for "spec" is removed as it is not used after the > call (tests still pass). > --- > gdb/python/py-breakpoint.c | 12 +++++------- > gdb/testsuite/gdb.python/py-breakpoint.exp | 4 +++- > 2 files changed, 8 insertions(+), 8 deletions(-) > > diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c > index d11fc64df20..3a2f8f5f2b8 100644 > --- a/gdb/python/py-breakpoint.c > +++ b/gdb/python/py-breakpoint.c > @@ -893,6 +893,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) > bppy_pending_object->number = -1; > bppy_pending_object->bp = NULL; > > + spec = skip_spaces (spec); > + > try > { > switch (type) > @@ -908,11 +910,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) > > if (spec != NULL) > { > - gdb::unique_xmalloc_ptr > - copy_holder (xstrdup (skip_spaces (spec))); > - const char *copy = copy_holder.get (); > - > - locspec = string_to_location_spec (©, > + locspec = string_to_location_spec (&spec, > current_language, > func_name_match_type); > } > @@ -941,8 +939,8 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) > = breakpoint_ops_for_location_spec (locspec.get (), false); > > create_breakpoint (gdbpy_enter::get_gdbarch (), > - locspec.get (), NULL, -1, NULL, false, > - 0, > + locspec.get (), NULL, -1, spec, false, > + 1, > temporary_bp, type, > 0, > AUTO_BOOLEAN_TRUE, > diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp > index 76094c95d10..3c747677fc7 100644 > --- a/gdb/testsuite/gdb.python/py-breakpoint.exp > +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp > @@ -170,8 +170,10 @@ proc_with_prefix test_bkpt_cond_and_cmds { } { > > # Test conditional setting. > set bp_location1 [gdb_get_line_number "Break at multiply."] > - gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \ > + gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1 thread 1\")" \ > "Set breakpoint" 0 > + gdb_test "python print (bp1.thread == 1)" "True" \ > + "Extra thread spec has been parsed" > gdb_continue_to_breakpoint "Break at multiply" \ > ".*Break at multiply.*" > gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \