From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32058 invoked by alias); 8 Mar 2012 21:08:31 -0000 Received: (qmail 32049 invoked by uid 22791); 8 Mar 2012 21:08:30 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Mar 2012 21:08:13 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q28L8ASI020678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Mar 2012 16:08:10 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q28L89xW004364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 8 Mar 2012 16:08:09 -0500 From: Tom Tromey To: Stan Shebs Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] dynamic printf References: <4F4DCDD5.2040807@earthlink.net> Date: Thu, 08 Mar 2012 21:08:00 -0000 In-Reply-To: <4F4DCDD5.2040807@earthlink.net> (Stan Shebs's message of "Tue, 28 Feb 2012 23:03:49 -0800") Message-ID: <87ipien6me.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.94 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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 X-SW-Source: 2012-03/txt/msg00289.txt.bz2 >>>>> "Stan" == Stan Shebs writes: Stan> This patch implements a "dynamic printf", which is basically a Stan> breakpoint with a printf;continue as its command list - but with Stan> additional features that make it more interesting. Very nice. I implemented something like this in Python once, but without the cool remote agent features. Stan> dprintf ,,... Stan> where the location is as for breakpoints, while the format and args Stan> are as for the printf command. So you could have something like I think you have to have a comma after the location. That is the only reliable linespec terminator. Stan> The patch itself is somewhat of a hack-n-slash through the middle of Stan> GDB, and there is much to critique. :-) I have a few things, but nothing really major. Some of this is outside areas I know much about, but I did at least skim it all and I think it generally looks good. Stan> +/* Parse the given expression, compile it into an agent expression Stan> + that does a printf, and display the resulting expression. */ Stan> + Stan> +extern char *parse_format_string (char **arg); There must be a header that this could go in. Stan> +#if 0 :) Stan> +char * Stan> +parse_format_string (char **arg) Need intro comment. This looks like bits were copied from printcmd.c:ui_printf. Could the code be shared instead? Stan> +/* Temporary hack to smuggle remainder of command line through. */ Stan> +char *glob_extra_string = NULL; I'd much prefer something cleaner. There's been a lot of work in recent times to clean up breakpoints in various ways -- adding methods, refactorings, etc -- and there is more to come. This goes against the trend. Stan> + struct agent_expr *cmd_bytecode; Needs a comment. Perhaps subclassing bp_location is also doable? Stan> + case gdb_agent_op_printf: [...] Stan> + /* (should re-check format before calling?) */ Stan> + printf (format, Stan> + args[0], args[1], args[2], args[3], args[4], Stan> + args[5], args[6], args[7], args[8], args[9]); Yeah, this seems overly optimistic to me. gdb used to have bugs where bad printf commands would crash it (IIRC there are some closed PRs about this). Maybe common-izing some code from ui_printf is the right thing? Or some kind of format checking. Also this leaves you at the mercy of the host printf for the '"%s", 0' case. Tom