From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28142 invoked by alias); 14 Nov 2005 16:34:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 28106 invoked by uid 22791); 14 Nov 2005 16:34:07 -0000 Received: from fra-del-01.spheriq.net (HELO fra-del-01.spheriq.net) (195.46.51.97) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 14 Nov 2005 16:34:07 +0000 Received: from fra-out-02.spheriq.net (fra-out-02.spheriq.net [195.46.51.130]) by fra-del-01.spheriq.net with ESMTP id jAEGY5Rp014255 for ; Mon, 14 Nov 2005 16:34:05 GMT Received: from fra-cus-01.spheriq.net (fra-cus-01.spheriq.net [195.46.51.37]) by fra-out-02.spheriq.net with ESMTP id jAEGXOSZ008227 for ; Mon, 14 Nov 2005 16:33:49 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-01.spheriq.net with ESMTP id jAEGXKdI021479 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Mon, 14 Nov 2005 16:33:23 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1C4E7DA7F; Mon, 14 Nov 2005 16:30:46 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id EA6E7474F4; Mon, 14 Nov 2005 16:33:43 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 71BDD75969; Mon, 14 Nov 2005 16:33:43 +0000 (UTC) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DBA4B475DC; Mon, 14 Nov 2005 16:33:39 +0000 (GMT) Received: from [164.129.15.13] (terrorhawk.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CGZ21178 (AUTH "andrew stubbs"); Mon, 14 Nov 2005 16:30:39 GMT Message-ID: <4378BB1A.9070606@st.com> Date: Mon, 14 Nov 2005 22:12:00 -0000 From: Andrew STUBBS User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: Daniel Jacobowitz Cc: Eli Zaretskii , gdb-patches@sources.redhat.com Subject: Re: $argc variable References: <436A0BD2.5080505@st.com> <20051107001800.GF19200@nevyn.them.org> <436F35E9.4070808@st.com> <20051107133538.GA2331@nevyn.them.org> <43709E94.4070004@st.com> <4371D9A6.40109@st.com> <43731C16.2040203@st.com> <20051113173524.GC1945@nevyn.them.org> In-Reply-To: <20051113173524.GC1945@nevyn.them.org> Content-Type: multipart/mixed; boundary="------------090907070505070707080505" X-O-Spoofed: Not Scanned X-O-General-Status: No X-O-Spam1-Status: Not Scanned X-O-Spam2-Status: Not Scanned X-O-URL-Status: Not Scanned X-O-Virus1-Status: No X-O-Virus2-Status: Not Scanned X-O-Virus3-Status: No X-O-Virus4-Status: No X-O-Virus5-Status: Not Scanned X-O-Image-Status: Not Scanned X-O-Attach-Status: Not Scanned X-SpheriQ-Ver: 4.1.07 X-SW-Source: 2005-11/txt/msg00192.txt.bz2 This is a multi-part message in MIME format. --------------090907070505070707080505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 676 Daniel Jacobowitz wrote: > It looks OK to me. Could you post the revised documentation (to > gdb-patches, please) so that we can make sure that Eli and you did > converge? I couldn't quite follow your earlier conversation. Here is the full patch including both code and docs. In the end I have dropped the index altogether. Eli didn't like the kindex and the cindex would be so close to the cindex for the section, and so similar in content, that it would be pointless. I still think there is an argument for a kindex entry for both $argc and $arg0...$arg1 in case people don't know they are looking for 'user-defined', but I'm not really that bothered. OK? Andrew --------------090907070505070707080505 Content-Type: text/plain; name="argc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="argc.patch" Content-length: 4178 2005-11-14 Andrew Stubbs * cli/cli-script.c: Include gdb_assert.h. (locate_arg): Detect $argc. (insert_args): Substitute $argc. * Makefile.in (cli-script.o): Add dependency on gdb_assert.h. doc/ * gdb.texinfo (User-defined commands): Add $argc. Add missing 'end'. Change @var{$arg0 to @code{$arg0. Index: src/gdb/cli/cli-script.c =================================================================== --- src.orig/gdb/cli/cli-script.c 2005-11-14 14:49:30.000000000 +0000 +++ src/gdb/cli/cli-script.c 2005-11-14 15:01:14.000000000 +0000 @@ -33,6 +33,7 @@ #include "cli/cli-cmds.h" #include "cli/cli-decode.h" #include "cli/cli-script.h" +#include "gdb_assert.h" /* Prototypes for local functions */ @@ -572,7 +573,8 @@ locate_arg (char *p) { while ((p = strchr (p, '$'))) { - if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4])) + if (strncmp (p, "$arg", 4) == 0 + && (isdigit (p[4]) || p[4] == 'c')) return p; p++; } @@ -596,12 +598,20 @@ insert_args (char *line) len += p - line; i = p[4] - '0'; - if (i >= user_args->count) + if (p[4] == 'c') + { + /* $argc. Number will be <=10. */ + len += user_args->count == 10 ? 2 : 1; + } + else if (i >= user_args->count) { error (_("Missing argument %d in user function."), i); return NULL; } - len += user_args->a[i].len; + else + { + len += user_args->a[i].len; + } line = p + 5; } @@ -625,13 +635,27 @@ insert_args (char *line) memcpy (new_line, line, p - line); new_line += p - line; - i = p[4] - '0'; - len = user_args->a[i].len; - if (len) + if (p[4] == 'c') + { + gdb_assert (user_args->count >= 0 && user_args->count <= 10); + if (user_args->count == 10) + { + *(new_line++) = '1'; + *(new_line++) = '0'; + } + else + *(new_line++) = user_args->count + '0'; + } + else { - memcpy (new_line, user_args->a[i].arg, len); - new_line += len; + i = p[4] - '0'; + len = user_args->a[i].len; + if (len) + { + memcpy (new_line, user_args->a[i].arg, len); + new_line += len; + } } line = p + 5; } Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2005-11-14 14:50:18.000000000 +0000 +++ src/gdb/doc/gdb.texinfo 2005-11-14 15:28:00.000000000 +0000 @@ -15708,11 +15708,12 @@ A @dfn{user-defined command} is a sequen which you assign a new name as a command. This is done with the @code{define} command. User commands may accept up to 10 arguments separated by whitespace. Arguments are accessed within the user command -via @var{$arg0@dots{}$arg9}. A trivial example: +via @code{$arg0@dots{}$arg9}. A trivial example: @smallexample define adder print $arg0 + $arg1 + $arg2 +end @end smallexample @noindent @@ -15728,6 +15729,20 @@ its three arguments. Note the arguments reference variables, use complex expressions, or even perform inferior functions calls. +In addition, @code{$argc} may be used to find out how many arguments have +been passed. This expands to a number in the range 0@dots{}10. + +@smallexample +define adder + if $argc == 2 + print $arg0 + $arg1 + end + if $argc == 3 + print $arg0 + $arg1 + $arg2 + end +end +@end smallexample + @table @code @kindex define Index: src/gdb/Makefile.in =================================================================== --- src.orig/gdb/Makefile.in 2005-11-14 14:49:30.000000000 +0000 +++ src/gdb/Makefile.in 2005-11-14 15:01:14.000000000 +0000 @@ -2807,7 +2807,7 @@ cli-logging.o: $(srcdir)/cli/cli-logging $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-logging.c cli-script.o: $(srcdir)/cli/cli-script.c $(defs_h) $(value_h) $(language_h) \ $(ui_out_h) $(gdb_string_h) $(exceptions_h) $(top_h) $(cli_cmds_h) \ - $(cli_decode_h) $(cli_script_h) + $(cli_decode_h) $(cli_script_h) $(gdb_assert_h) $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/cli/cli-script.c cli-setshow.o: $(srcdir)/cli/cli-setshow.c $(defs_h) $(readline_tilde_h) \ $(value_h) $(gdb_string_h) $(ui_out_h) $(cli_decode_h) $(cli_cmds_h) \ --------------090907070505070707080505--