From patchwork Fri Nov 3 16:58:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24073 Received: (qmail 92773 invoked by alias); 3 Nov 2017 16:58:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92763 invoked by uid 89); 3 Nov 2017 16:58:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=strcat X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.101) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 16:58:12 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 723CF83A5 for ; Fri, 3 Nov 2017 11:58:11 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AfIJeqQIlrWstAfIJeZdxf; Fri, 03 Nov 2017 11:58:11 -0500 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:35556 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eAfIJ-000t89-5W; Fri, 03 Nov 2017 11:58:11 -0500 From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA 06/13] Replace start_rbreak_breakpoints and end_rbreak_breakpoints References: <20171102223612.3642-1-tom@tromey.com> <20171102223612.3642-7-tom@tromey.com> <368bfe6be1612beb89c174c35e0cc73a@polymtl.ca> Date: Fri, 03 Nov 2017 10:58:10 -0600 In-Reply-To: <368bfe6be1612beb89c174c35e0cc73a@polymtl.ca> (Simon Marchi's message of "Thu, 02 Nov 2017 21:20:55 -0400") Message-ID: <87efpfuwnx.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eAfIJ-000t89-5W X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya) [71.218.90.63]:35556 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes >>>>> "Simon" == Simon Marchi writes: Simon> Your patch LGTM. But how is the "string" string freed in Simon> rbreak_command? It is leaked, which apparently is a regression introduced by an earlier patch of mine. Sorry about that! I've updated the patch as appended to fix this problem. Tom commit 391e4d7aa45fc4947632aa06a7aa462eeef3377c Author: Tom Tromey Date: Wed Nov 1 09:00:09 2017 -0600 Replace start_rbreak_breakpoints and end_rbreak_breakpoints This replaces start_rbreak_breakpoints and end_rbreak_breakpoints with a new scoped class. This allows the removal of a cleanup. This also fixes an earlier memory leak regression, by changing "string" to be a std::string. gdb/ChangeLog 2017-11-03 Tom Tromey * breakpoint.c (scoped_rbreak_breakpoints::scoped_rbreak_breakpoints): Rename from start_rbreak_breakpoints. (scoped_rbreak_breakpoints): Rename from end_rbreak_breakpoints. * breakpoint.h (class scoped_rbreak_breakpoints): New. (start_rbreak_breakpoints, end_rbreak_breakpoints): Remove. * symtab.c (do_end_rbreak_breakpoints): Remove. (rbreak_command): Use scoped_rbreak_breakpoints, std::string. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ce6c8db631..56b7e903bc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2017-11-03 Tom Tromey + + * breakpoint.c + (scoped_rbreak_breakpoints::scoped_rbreak_breakpoints): Rename + from start_rbreak_breakpoints. + (scoped_rbreak_breakpoints): Rename from end_rbreak_breakpoints. + * breakpoint.h (class scoped_rbreak_breakpoints): New. + (start_rbreak_breakpoints, end_rbreak_breakpoints): Remove. + * symtab.c (do_end_rbreak_breakpoints): Remove. + (rbreak_command): Use scoped_rbreak_breakpoints, std::string. + 2017-11-02 Tom Tromey * cp-namespace.c (reset_directive_searched): Remove. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 0bf47d5f56..61e41283b1 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -644,8 +644,7 @@ static int rbreak_start_breakpoint_count; /* Called at the start an "rbreak" command to record the first breakpoint made. */ -void -start_rbreak_breakpoints (void) +scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () { rbreak_start_breakpoint_count = breakpoint_count; } @@ -653,8 +652,7 @@ start_rbreak_breakpoints (void) /* Called at the end of an "rbreak" command to record the last breakpoint made. */ -void -end_rbreak_breakpoints (void) +scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () { prev_breakpoint_count = rbreak_start_breakpoint_count; } diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 9a9433bd66..69b63ea932 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1601,10 +1601,18 @@ extern VEC(breakpoint_p) *static_tracepoints_here (CORE_ADDR addr); that each command is suitable for tracepoint command list. */ extern void check_tracepoint_command (char *line, void *closure); -/* Call at the start and end of an "rbreak" command to register - breakpoint numbers for a later "commands" command. */ -extern void start_rbreak_breakpoints (void); -extern void end_rbreak_breakpoints (void); +/* Create an instance of this to start registering breakpoint numbers + for a later "commands" command. */ + +class scoped_rbreak_breakpoints +{ +public: + + scoped_rbreak_breakpoints (); + ~scoped_rbreak_breakpoints (); + + DISABLE_COPY_AND_ASSIGN (scoped_rbreak_breakpoints); +}; /* Breakpoint iterator function. diff --git a/gdb/symtab.c b/gdb/symtab.c index 16a6b2eb6f..25b3de0dfb 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4506,20 +4506,10 @@ rbreak_command_wrapper (char *regexp, int from_tty) rbreak_command (regexp, from_tty); } -/* A cleanup function that calls end_rbreak_breakpoints. */ - -static void -do_end_rbreak_breakpoints (void *ignore) -{ - end_rbreak_breakpoints (); -} - static void rbreak_command (char *regexp, int from_tty) { - struct cleanup *old_chain; - char *string = NULL; - int len = 0; + std::string string; const char **files = NULL; const char *file_name; int nfiles = 0; @@ -4550,8 +4540,7 @@ rbreak_command (char *regexp, int from_tty) FUNCTIONS_DOMAIN, nfiles, files); - start_rbreak_breakpoints (); - old_chain = make_cleanup (do_end_rbreak_breakpoints, NULL); + scoped_rbreak_breakpoints finalize; for (const symbol_search &p : symbols) { if (p.msymbol.minsym == NULL) @@ -4559,20 +4548,9 @@ rbreak_command (char *regexp, int from_tty) struct symtab *symtab = symbol_symtab (p.symbol); const char *fullname = symtab_to_fullname (symtab); - int newlen = (strlen (fullname) - + strlen (SYMBOL_LINKAGE_NAME (p.symbol)) - + 4); - - if (newlen > len) - { - string = (char *) xrealloc (string, newlen); - len = newlen; - } - strcpy (string, fullname); - strcat (string, ":'"); - strcat (string, SYMBOL_LINKAGE_NAME (p.symbol)); - strcat (string, "'"); - break_command (string, from_tty); + string = (std::string (fullname) + ":'" + + SYMBOL_LINKAGE_NAME (p.symbol) + "'"); + break_command (&string[0], from_tty); print_symbol_info (FUNCTIONS_DOMAIN, p.symbol, p.block, @@ -4580,24 +4558,14 @@ rbreak_command (char *regexp, int from_tty) } else { - int newlen = (strlen (MSYMBOL_LINKAGE_NAME (p.msymbol.minsym)) + 3); - - if (newlen > len) - { - string = (char *) xrealloc (string, newlen); - len = newlen; - } - strcpy (string, "'"); - strcat (string, MSYMBOL_LINKAGE_NAME (p.msymbol.minsym)); - strcat (string, "'"); + string = (std::string ("'") + + MSYMBOL_LINKAGE_NAME (p.msymbol.minsym) + "'"); - break_command (string, from_tty); + break_command (&string[0], from_tty); printf_filtered (" %s;\n", MSYMBOL_PRINT_NAME (p.msymbol.minsym)); } } - - do_cleanups (old_chain); }