From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55099 invoked by alias); 9 Apr 2019 15:27:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 55086 invoked by uid 89); 9 Apr 2019 15:27:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: mail-wm1-f65.google.com Received: from mail-wm1-f65.google.com (HELO mail-wm1-f65.google.com) (209.85.128.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Apr 2019 15:27:25 +0000 Received: by mail-wm1-f65.google.com with SMTP id z24so3845401wmi.5 for ; Tue, 09 Apr 2019 08:27:25 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id b9sm22313281wmc.9.2019.04.09.08.27.22 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 08:27:23 -0700 (PDT) Subject: Re: [PATCH] Use -qualified flag when setting temporary breakpoint in start command To: Simon Marchi , gdb-patches@sourceware.org Cc: Simon Marchi References: <20190409025557.28846-1-simon.marchi@polymtl.ca> From: Pedro Alves Message-ID: Date: Tue, 09 Apr 2019 15:27:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190409025557.28846-1-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-04/txt/msg00144.txt.bz2 On 4/9/19 3:55 AM, Simon Marchi wrote: > From: Simon Marchi > > When using the "start" command, GDB puts a temporary breakpoint on the > "main" symbol (we literally invoke the tbreak command). However, since > it does wild matching by default, it also puts a breakpoint on any C++ > method or "main" function in a namespace. For example, when debugging > GDB, it creates a total of 24 locations: > > (gdb) start > Temporary breakpoint 1 at 0x198c1e9: main. (24 locations) > > as there are a bunch of methods called main in the selftests, such as > > selftests::string_view::capacity_1::main() > > If such method was called in the constructor of a global object, or a > function marked with the attribute "constructor", then we would stop at > the wrong place. Also, this causes a few extra symtabs (those that > contain the "wrong" mains) to be expanded for nothing. > > The dummiest, most straightforward solution is to add -qualified when > invoking tbreak. With this patch, "start" creates a single-location > breakpoint, as expected. > That seems fine. > I changed the start.exp test to use a C++ test file, which contains two > main functions. The test now verifies that the output of "start" is the > output we get when we set a single-location breakpoint. I'm mildly concerned that this drops testing with C, though. Given that "start" is a basic command, and that C++ symbol/name matching differs from C, and considering that some targets don't even support C++ (considering extended-remote too), I'd think it to be prudent to test both C and C++. I wouldn't say it's a big deal, but, the .exp file is small, so it shouldn't be much of a maintenance burden to copy & adjust it as a separate .exp file, IMHO. > > gdb/ChangeLog: > > * infcmd.c (run_command_1): Pass -qualified to tbreak when usind > the "start" command. > > gdb/testsuite/ChangeLog: > > * gdb.base/start.exp: Change test file to start.cpp. Enhance > regexp to match output of single-location breakpoint. > * gdb.base/start.cpp: New file. Nit: all other C++ source files in the testsuite use .cc extension. > +namespace foo > +{ > + > +int main () > +{ > + return 1; > +} > + > +} /* namespace foo */ > + > +int main() Watch out for GNU formatting. Thanks, Pedro Alves