From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30054 invoked by alias); 16 Aug 2011 04:58:15 -0000 Received: (qmail 30045 invoked by uid 22791); 16 Aug 2011 04:58:13 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-fx0-f41.google.com (HELO mail-fx0-f41.google.com) (209.85.161.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Aug 2011 04:57:56 +0000 Received: by fxg9 with SMTP id 9so4655832fxg.0 for ; Mon, 15 Aug 2011 21:57:55 -0700 (PDT) Received: by 10.223.10.15 with SMTP id n15mr6804713fan.95.1313470675056; Mon, 15 Aug 2011 21:57:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.115.11 with HTTP; Mon, 15 Aug 2011 21:57:15 -0700 (PDT) In-Reply-To: References: From: Hui Zhu Date: Tue, 16 Aug 2011 04:58:00 -0000 Message-ID: Subject: Re: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory To: Tom Tromey Cc: gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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: 2011-08/txt/msg00320.txt.bz2 Hi Tom, Thanks for your help. On Tue, Aug 16, 2011 at 03:06, Tom Tromey wrote: >>>>>> ">" =3D=3D Hui Zhu writes: > >>> Thanks for your help. >>> I make a new patch according to your mail. > >>> 2011-08-14 =A0Hui Zhu =A0 >>> =A0 =A0 =A0 =A0* printcmd.c (ui_printf): Add a handler for internalvar = and >>> TYPE_CODE_ARRAY. > > I still don't think this is correct. > > This special-cases lval_internalvar, but IIUC this will still fail for > something like: > > =A0 =A0printf "hi %s\n", "bob" > > In this code I don't think you need to call value_as_address for an > array; likewise reading from memory. I make a new patch according to it. Please help me review it. > > The patch also doesn't address the wide-string case, which it should. I don't know howto input a wide-string to GDB command line. Could you help me with that and let me write a separate patch special for wide-string case? > > Tom > Best, Hui 2011-08-16 Hui Zhu * printcmd.c (ui_printf): Add a handler for internalvar or not_lval and TYPE_CODE_ARRAY. --- printcmd.c | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) --- a/printcmd.c +++ b/printcmd.c @@ -2343,32 +2343,39 @@ ui_printf (char *arg, struct ui_file *st switch (argclass[i]) { case string_arg: - { - gdb_byte *str; - CORE_ADDR tem; - int j; + if ((VALUE_LVAL (val_args[i]) =3D=3D lval_internalvar + || VALUE_LVAL (val_args[i]) =3D=3D not_lval) + && TYPE_CODE (check_typedef (value_type (val_args[i]))) + =3D=3D TYPE_CODE_ARRAY) + fprintf_filtered (stream, current_substring, + (char *) value_contents (val_args[i])); + else + { + gdb_byte *str; + CORE_ADDR tem; + int j; - tem =3D value_as_address (val_args[i]); + tem =3D value_as_address (val_args[i]); - /* This is a %s argument. Find the length of the string. */ - for (j =3D 0;; j++) - { - gdb_byte c; + /* This is a %s argument. Find the length of the string. */ + for (j =3D 0;; j++) + { + gdb_byte c; - QUIT; - read_memory (tem + j, &c, 1); - if (c =3D=3D 0) - break; - } + QUIT; + read_memory (tem + j, &c, 1); + if (c =3D=3D 0) + break; + } - /* Copy the string contents into a string inside GDB. */ - str =3D (gdb_byte *) alloca (j + 1); - if (j !=3D 0) - read_memory (tem, str, j); - str[j] =3D 0; + /* Copy the string contents into a string inside GDB. */ + str =3D (gdb_byte *) alloca (j + 1); + if (j !=3D 0) + read_memory (tem, str, j); + str[j] =3D 0; - fprintf_filtered (stream, current_substring, (char *) str); - } + fprintf_filtered (stream, current_substring, (char *) str); + } break; case wide_string_arg: {