From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 572893857C44 for ; Thu, 6 May 2021 02:09:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 572893857C44 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 14629Ah7012699 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 5 May 2021 22:09:14 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 14629Ah7012699 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E17C91E813; Wed, 5 May 2021 22:09:09 -0400 (EDT) Subject: Re: [PATCH 2/2] gdb/guile: don't try to print location for watchpoints To: Andrew Burgess , gdb-patches@sourceware.org References: <751c2e78c06d9723343395ea616a30d4055e13f0.1620238156.git.andrew.burgess@embecosm.com> From: Simon Marchi Message-ID: <5b7817fc-5951-a532-d4ac-00bae7d3cb36@polymtl.ca> Date: Wed, 5 May 2021 22:09:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <751c2e78c06d9723343395ea616a30d4055e13f0.1620238156.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 6 May 2021 02:09:10 +0000 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 06 May 2021 02:09:17 -0000 On 2021-05-05 2:10 p.m., Andrew Burgess wrote: > Currently, using the guile API, if a user tries to print a breakpoint > object that represents a watchpoint, then GDB will crash. For > example: > > (gdb) guile (use-modules (gdb)) > (gdb) guile (define wp1 (make-breakpoint "some_variable" #:type BP_WATCHPOINT #:wp-class WP_WRITE)) > (gdb) guile (register-breakpoint! wp1) > (gdb) guile (display wp1) (newline) > Aborted (core dumped) > > This turns out to be because GDB calls event_location_to_string on the > breakpoints location, and watchpoint breakpoints don't have a > location. > > This commit resolves the crash by just skipping the printing of the > location if the breakpoint doesn't have one. > > Potentially, we could improve on this by printing details about what > the watchpoint is watching, however, I'm considering this a possible > future enhancement, this commit focuses just on having GDB not crash. > > gdb/ChangeLog: > > * guile/scm-breakpoint.c (bpscm_print_breakpoint_smob): Only print > breakpoint locations when the breakpoint actually has a location. > > gdb/testsuite/ChangeLog: > > * gdb.guile/scm-breakpoint.exp (test_watchpoints): Print the > watchpoint object before and after registering it with GDB. LGTM, I noted some nits below. > diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c > index 25b438b7210..791e3051f6d 100644 > --- a/gdb/guile/scm-breakpoint.c > +++ b/gdb/guile/scm-breakpoint.c > @@ -184,9 +184,12 @@ bpscm_print_breakpoint_smob (SCM self, SCM port, scm_print_state *pstate) > gdbscm_printf (port, " hit:%d", b->hit_count); > gdbscm_printf (port, " ignore:%d", b->ignore_count); > > - str = event_location_to_string (b->location.get ()); > - if (str != NULL) > - gdbscm_printf (port, " @%s", str); > + if (b->location.get () != nullptr) Nit 1: for the purpose of the comparison, you don't have to use `.get ()`. > + { > + str = event_location_to_string (b->location.get ()); Nit 2: declare `str` here. > + if (str != NULL) Nit 3: change NULL to nullptr. Simon