Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: PING: Re: [PATCH] printcmd.c (ui_printf): make internalvar string can be printf and eval when inferior cannot alloc memory
Date: Wed, 17 Aug 2011 13:39:00 -0000	[thread overview]
Message-ID: <CANFwon3pQVYxPi7g=pSkLk5y-E=SphHQEKRb=-aSw+oD=Xuc_Q@mail.gmail.com> (raw)

Thanks,
Hui

On Tue, Aug 16, 2011 at 12:57, Hui Zhu <teawater@gmail.com> wrote:
> Hi Tom,
>
> Thanks for your help.
>
> On Tue, Aug 16, 2011 at 03:06, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> ">" == Hui Zhu <teawater@gmail.com> writes:
>>
>>>> Thanks for your help.
>>>> I make a new patch according to your mail.
>>
>>>> 2011-08-14  Hui Zhu  <teawater@gmail.com>
>>>>        * 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:
>>
>>    printf "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  <teawater@gmail.com>
>
>        * 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]) == lval_internalvar
> +                || VALUE_LVAL (val_args[i]) == not_lval)
> +               && 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:
>            {
>


             reply	other threads:[~2011-08-17 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-17 13:39 Hui Zhu [this message]
2011-08-17 14:35 ` Tom Tromey

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='CANFwon3pQVYxPi7g=pSkLk5y-E=SphHQEKRb=-aSw+oD=Xuc_Q@mail.gmail.com' \
    --to=teawater@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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