From: Hui Zhu <teawater@gmail.com>
To: gdb-patches ml <gdb-patches@sourceware.org>
Subject: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory
Date: Wed, 20 Jul 2011 10:37:00 -0000 [thread overview]
Message-ID: <CANFwon0RttecHT1BrVx886NC6yCsojHm-MWfr7ttS8=CjoNEzg@mail.gmail.com> (raw)
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 <teawater@gmail.com>
* 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:
next reply other threads:[~2011-07-20 6:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-20 10:37 Hui Zhu [this message]
2011-07-21 20:43 ` Tom Tromey
2011-08-14 15:10 ` Hui Zhu
2011-08-15 19:06 ` Tom Tromey
2011-08-16 4:58 ` Hui Zhu
2011-08-17 14:38 ` Tom Tromey
2011-08-18 2:54 ` Hui Zhu
2011-08-19 14:15 ` Tom Tromey
2011-09-06 8:50 ` Hui Zhu
2011-09-06 13:44 ` Jan Kratochvil
2011-09-07 9:27 ` Hui Zhu
2011-09-07 10:02 ` Jan Kratochvil
2011-09-09 7:59 ` Hui Zhu
2011-09-09 12:32 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANFwon0RttecHT1BrVx886NC6yCsojHm-MWfr7ttS8=CjoNEzg@mail.gmail.com' \
--to=teawater@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox