From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31386 invoked by alias); 8 Mar 2008 20:24:33 -0000 Received: (qmail 31374 invoked by uid 22791); 8 Mar 2008 20:24:32 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 08 Mar 2008 20:24:15 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m28KODes013562 for ; Sat, 8 Mar 2008 15:24:13 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m28KODRd026209 for ; Sat, 8 Mar 2008 15:24:13 -0500 Received: from opsy.redhat.com (vpn-248-72.boston.redhat.com [10.13.248.72]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m28KOCwA019410; Sat, 8 Mar 2008 15:24:12 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id F3CD83782C6; Sat, 8 Mar 2008 12:31:52 -0700 (MST) To: gdb-patches@sources.redhat.com Subject: Re: RFC add "convenience functions" to gdb References: From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Sat, 08 Mar 2008 20:24:00 -0000 In-Reply-To: (Tom Tromey's message of "Fri\, 29 Feb 2008 21\:59\:46 -0700") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2008-03/txt/msg00069.txt.bz2 >>>>> "Tom" == Tom Tromey writes: Tom> So, this evening I spent some time adding a new "convenience Tom> function" facility to gdb. I added a new convenience function, "show". This lets you get at any gdb "set/show" value in an expression. Mostly, I think, this kind of thing is useful for conditions in commands. I've appended the new function, so folks can see it. I could prepare a new patch if anybody cares. After writing this I started thinking that it sure would be nice to have a host-side string type, plus a regex-matching operator. Then $(caller-matches ...) could be rewritten like: break func if $(caller-name) =~ $"callerfunction" I use $"..." to denote a host string. After this it would be pretty simple to start allowing scripting access to all kinds of interesting state: string-valued set/show variables, the exe name, the names of functions up and down the stack, types, syscalls (whatever happened to that "catch syscall" patch?) -- anything we can think of. So, I started implementing host strings... but I dunno. Is it worth doing? Maybe python will solve all the problems -- since what I really want is a nice, normal, complete programming language with access to gdb state. In fact maybe we only need *one* convenience function, $(python ...). Tom /* Return the value of a 'set/show' variable. Integer-ish variables are returned as integers, others as strings. */ static struct value * show_fn (char *arg) { struct cmd_list_element *alias, *prefix, *cmd; char *newarg; newarg = concat ("show ", arg, (char *) NULL); make_cleanup (free, newarg); if (! lookup_cmd_composition (newarg, &alias, &prefix, &cmd)) error ("could not find variable `%s'", arg); if (! cmd->var) error ("`%s' is not a variable", arg); switch (cmd->var_type) { case var_string: case var_string_noescape: case var_optional_filename: case var_filename: case var_enum: error ("gdb-internal string type not yet implemented"); case var_boolean: return value_from_longest (builtin_type_bool, * (int *) cmd->var); case var_auto_boolean: { enum auto_boolean ab = * (enum auto_boolean *) cmd->var; return value_from_longest (builtin_type_int, (ab == AUTO_BOOLEAN_TRUE ? 1 : (ab == AUTO_BOOLEAN_FALSE ? 0 : -1))); } case var_integer: case var_uinteger: case var_zinteger: return value_from_longest (builtin_type_int, * (int *) cmd->var); } error ("programmer error: unhandled type"); }