From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24007 invoked by alias); 14 Aug 2011 15:10:13 -0000 Received: (qmail 23998 invoked by uid 22791); 14 Aug 2011 15:10:12 -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; Sun, 14 Aug 2011 15:09:58 +0000 Received: by fxg9 with SMTP id 9so3714305fxg.0 for ; Sun, 14 Aug 2011 08:09:57 -0700 (PDT) Received: by 10.223.10.15 with SMTP id n15mr4309479fan.95.1313334597125; Sun, 14 Aug 2011 08:09:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.115.11 with HTTP; Sun, 14 Aug 2011 08:09:17 -0700 (PDT) In-Reply-To: References: From: Hui Zhu Date: Sun, 14 Aug 2011 15:10: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/msg00287.txt.bz2 On Fri, Jul 22, 2011 at 04:38, Tom Tromey wrote: >>>>>> ">" =3D=3D Hui Zhu writes: > >>> So I make a patch to handle the error from value_as_address. =A0If >>> value_as_address get error and this is a internalvar, call >>> value_contents to get the address of the val. > > I don't think this is the best approach to solve this problem. > > It seems to me that if the value is already an array, the data might > already exist in gdb, and then you don't have to even try to coerce it > to memory. =A0(However, for a pointer or integer value, using > value_as_address is still the best thing.) > > I would suggest looking to see how valprint handles this situation, then > do the same thing here. > > Tom > Hi Tom, Thanks for your help. I make a new patch according to your mail. Best, Hui 2011-08-14 Hui Zhu * printcmd.c (ui_printf): Add a handler for internalvar and TYPE_CODE_ARRAY. --- printcmd.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) --- a/printcmd.c +++ b/printcmd.c @@ -2343,32 +2343,38 @@ 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 + && 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: {