From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15127 invoked by alias); 20 Jul 2011 06:10:02 -0000 Received: (qmail 15098 invoked by uid 22791); 20 Jul 2011 06:10:00 -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-f54.google.com (HELO mail-fx0-f54.google.com) (209.85.161.54) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jul 2011 06:09:44 +0000 Received: by fxe4 with SMTP id 4so1061065fxe.13 for ; Tue, 19 Jul 2011 23:09:43 -0700 (PDT) Received: by 10.223.16.136 with SMTP id o8mr6345565faa.21.1311142183083; Tue, 19 Jul 2011 23:09:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.37.200 with HTTP; Tue, 19 Jul 2011 23:09:03 -0700 (PDT) From: Hui Zhu Date: Wed, 20 Jul 2011 10:37:00 -0000 Message-ID: Subject: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory To: gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 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-07/txt/msg00512.txt.bz2 Hi, printf and eval commands call ui_printf to get the format string. But I found that: gdb (gdb) p $a="pwd" $1 = "pwd" (gdb) p $a $2 = "pwd" (gdb) printf "%s\n", $a evaluation of this expression requires the target program to be active (gdb) eval "%s", $a evaluation of this expression requires the target program to be active This error is because we can alloc memory from inferior now. But ui_printf will call allocate_space_in_inferior to alloc inferior memory. This issue can reproduce in the inferior that cannot alloc memory such as KGTP. So I make a patch to handle the error from value_as_address. If value_as_address get error and this is a internalvar, call value_contents to get the address of the val. After this patch, gdb can always success with this commands. Please help review the patch, it for the trunk and 7.3. Thanks, Hui 2011-07-20 Hui Zhu * printcmd.c (ui_printf): Add error handler for value_as_address. --- printcmd.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) --- a/printcmd.c +++ b/printcmd.c @@ -2330,27 +2330,42 @@ ui_printf (char *arg, struct ui_file *st gdb_byte *str; CORE_ADDR tem; int j; + volatile struct gdb_exception ex; - tem = value_as_address (val_args[i]); - - /* This is a %s argument. Find the length of the string. */ - for (j = 0;; j++) + TRY_CATCH (ex, RETURN_MASK_ERROR) { - gdb_byte c; - - QUIT; - read_memory (tem + j, &c, 1); - if (c == 0) - break; + tem = value_as_address (val_args[i]); } + if (ex.reason >= 0) + { + /* This is a %s argument. Find the length of the string. */ + for (j = 0;; j++) + { + gdb_byte c; - /* Copy the string contents into a string inside GDB. */ - str = (gdb_byte *) alloca (j + 1); - if (j != 0) - read_memory (tem, str, j); - str[j] = 0; + QUIT; + read_memory (tem + j, &c, 1); + if (c == 0) + break; + } - fprintf_filtered (stream, current_substring, (char *) str); + /* Copy the string contents into a string inside GDB. */ + str = (gdb_byte *) alloca (j + 1); + if (j != 0) + read_memory (tem, str, j); + str[j] = 0; + + fprintf_filtered (stream, current_substring, (char *) str); + } + else + { + if (VALUE_LVAL (val_args[i]) == lval_internalvar) + fprintf_filtered (stream, + current_substring, + (char *) value_contents (val_args[i])); + else + error (_("%s"), ex.message); + } } break; case wide_string_arg: