Re: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory

Hui Zhu
2011-09-06T08:22:50Z

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]

On Fri, Aug 19, 2011 at 22:14, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>
> Tom> This test seems odd to me.  Why does the lvalue-ness of the value
> Tom> matter?
>
>>> I don't understand your means, could you do some explain?
>
> I just don't understand why a check of the VALUE_LVAL is necessary.
> Does something go wrong in the other cases?  It doesn't seem to me that
> it should.
>
> Tom
>

Got it.

I make a new patch remove the line:
>> + if ((VALUE_LVAL (val_args[i]) == lval_internalvar
>> + || VALUE_LVAL (val_args[i]) == not_lval)

Please help me review it.

Thanks,
Hui

2011-09-06 Hui Zhu <teawater@gmail.com>

* printcmd.c (ui_printf): Add a handler for TYPE_CODE_ARRAY.

[-- Attachment #2: fix-v-string.txt --]
[-- Type: text/plain, Size: 1731 bytes --]

---
printcmd.c | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)

--- a/printcmd.c
+++ b/printcmd.c
@@ -2343,32 +2343,37 @@ ui_printf (char *arg, struct ui_file *st
switch (argclass[i])
{
case string_arg:
- {
- gdb_byte *str;
- CORE_ADDR tem;
- int j;
+ if (TYPE_CODE (check_typedef (value_type (val_args[i])))
+ == TYPE_CODE_ARRAY)
+ fprintf_filtered (stream, current_substring,
+ (char *) value_contents (val_args[i]));
+ else
+ {
+ gdb_byte *str;
+ CORE_ADDR tem;
+ int j;

- tem = value_as_address (val_args[i]);
+ tem = value_as_address (val_args[i]);

- /* This is a %s argument. Find the length of the string. */
- for (j = 0;; j++)
- {
- gdb_byte c;
+ /* This is a %s argument. Find the length of the string. */
+ for (j = 0;; j++)
+ {
+ gdb_byte c;

- QUIT;
- read_memory (tem + j, &c, 1);
- if (c == 0)
- break;
- }
+ QUIT;
+ read_memory (tem + j, &c, 1);
+ if (c == 0)
+ break;
+ }

- /* 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;
+ /* 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);
- }
+ fprintf_filtered (stream, current_substring, (char *) str);
+ }
break;
case wide_string_arg:
{