public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb-patches@sourceware.org, Phil Muldoon <pmuldoon@redhat.com>
Subject: Re: [PATCH v3 8/9] compile: New compile printf
Date: Wed, 06 May 2015 10:22:00 -0000	[thread overview]
Message-ID: <5549EB71.1070101@redhat.com> (raw)
In-Reply-To: <20150503140605.GC18394@host1.jankratochvil.net>

On 05/03/2015 03:06 PM, Jan Kratochvil wrote:
> On Wed, 29 Apr 2015 17:52:09 +0200, Pedro Alves wrote:
>> The usefulness of "compile printf"
>> specifically isn't as immediately clear though.  I think the manual
>> should say something about why you want to use "compile printf" over
>> the alternatives.  (Edit: Ah, I see that's in the next patch.)
> 
> I do not know, I have never used the existing GDB printf command myself.
> GDB Manual could describe what the existing GDB printf command is good for.

It's useful for formatted output in user-defined commands, without
using extension languages.  But indeed it's not clear what
"compile printf" in its current form is really useful for.

> IMO in the cases where one needs the printf command one already has to use
> some extension language (such as Python) which can do that on its own.

(The printf command predates extensions languages.)

> This patch was created upon request by Phil.

I'm wondering / trying to understand why we're making
"compile printf" do the printf-ing in the inferior.  It seems we may
be making our lives harder for possibly no good reason.

Consider where we'll ideally be in the future:

 #0 - by default, the compiler outputs intermediate IR which is
      interpreted by gdb, instead of injecting and calling code
      in the inferior.

 #1 - all expression evaluation goes through the compiler.

 #2 - the user no longer needs to know to use "compile "
      prefixed commands.  Instead, "print" etc. just use the compiler
      when possible, or when the user asks for it with some option.

With these in mind, maybe a better direction is to make

  (gdb) compile printf "%s, %d", expr1, expr2

instead evaluate expr1 and expr2 using the "compile print"
mechanism to get the values of expr1 and expr2, and
then do the printf formatting all on the gdb side, just
like "(gdb) printf".  Basically, in the current
sequence for "printf":

  printf_command -> ui_printf -> parse_to_comma_and_eval

Make parse_to_comma_and_eval eval using the compiler.

This avoids all the complication related to calling printf
in the inferior, which would necessarily behave differently
with #0 above (gdb's printf vs inferior's printf).

> 
>> The main advantage is that after the next patch, the output always
>> appears in gdb's console, while "compile code printf" works just like
>>   (gdb) print printf (...)
>> meaning, in the "compile the output should go to the inferior's stdout.
>>
>> Or is there another advantage I missed, perhaps?
> 
> This patch is just to split it to two mails for review. 

I understand that.  But what I was asking is (after the series is wholly
pushed), what is the advantage of "(gdb) compile printf"
over "(gdb) compile print printf (...)" and "(gdb) call printf (...)".

> I do not think it
> makes sense on its own, it messes up debugging output with inferior output.
> 
> 
>> But can give an example of why you'd want to set "set compile-printf-args"
>> differently to "set compile-args" ?
> 
> I do not know exactly myself but currently there is already:
> 	+  compile_printf_args = xstrdup ("-Werror=format");
> 
> so one may need to modify that for whatever reason.  I do not think there
> should be non-overridable GCC options.

Agreed on the latter, but the question really is: why do we need
"set compile-printf-args" instead of using "set compile-args" for
all expression evaluation through the compiler?
Shouldn't "-Werror=format" be in "set compile-args" too?
The fewer knobs the user must learn the better, and I'd like to
avoid ending up with a bunch of "set compile-foo-args" knobs
if possible.

Thanks,
Pedro Alves

  reply	other threads:[~2015-05-06 10:22 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-11 19:43 [PATCH v3 0/9] compile: compile print&printf Jan Kratochvil
2015-04-11 19:43 ` [PATCH v3 2/9] compile: Distribute scope, add scope_data Jan Kratochvil
2015-04-29 15:44   ` Pedro Alves
2015-04-11 19:43 ` [PATCH v3 1/9] Code cleanup: Make parts of print_command_1 public Jan Kratochvil
2015-04-29 15:44   ` Pedro Alves
2015-04-30  0:24     ` Jan Kratochvil
2015-04-11 19:43 ` [PATCH v3 3/9] Code cleanup: compile: Constify some parameters Jan Kratochvil
2015-04-29 15:47   ` Pedro Alves
2015-05-06 18:58     ` [commit] " Jan Kratochvil
2015-04-11 19:44 ` [PATCH v3 7/9] compile: New 'compile print' Jan Kratochvil
2015-04-29 15:53   ` Pedro Alves
2015-05-03 14:06     ` Jan Kratochvil
2015-05-06 10:22       ` Pedro Alves
2015-05-06 12:23         ` Jan Kratochvil
2015-05-06 14:11           ` Pedro Alves
2015-05-06 19:18             ` Jan Kratochvil
2015-05-15 16:35               ` Pedro Alves
2015-04-11 19:44 ` [PATCH v3 9/9] compile: compile printf: gdbserver support Jan Kratochvil
2015-04-26  9:33   ` Jan Kratochvil
2015-04-29 18:19     ` Pedro Alves
2015-05-03 14:06       ` Jan Kratochvil
2015-05-06 10:22         ` Pedro Alves
2015-04-29 16:12   ` Pedro Alves
2015-04-11 19:44 ` [PATCH v3 8/9] compile: New compile printf Jan Kratochvil
2015-04-29 15:54   ` Pedro Alves
2015-05-03 14:06     ` Jan Kratochvil
2015-05-06 10:22       ` Pedro Alves [this message]
2015-05-06 11:30         ` Jan Kratochvil
2015-05-06 11:47           ` Pedro Alves
2015-04-11 19:44 ` [PATCH v3 5/9] compile: Use -Wall, not -w Jan Kratochvil
2015-04-29 15:49   ` Pedro Alves
2015-05-03 14:05     ` Jan Kratochvil
2015-05-06 10:21       ` Pedro Alves
2015-04-11 19:44 ` [PATCH v3 4/9] compile: Support relocation to GNU-IFUNCs Jan Kratochvil
2015-04-29 15:48   ` Pedro Alves
2015-05-06 19:00     ` [commit] " Jan Kratochvil
2015-04-11 19:44 ` [PATCH v3 6/9] Code cleanup: compile: func_addr -> func_sym Jan Kratochvil
2015-04-29 15:52   ` Pedro Alves

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=5549EB71.1070101@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=pmuldoon@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).