This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v3 9/9] compile: compile printf: gdbserver support
- From: Pedro Alves <palves at redhat dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>, gdb-patches at sourceware dot org
- Cc: Phil Muldoon <pmuldoon at redhat dot com>
- Date: Wed, 29 Apr 2015 16:52:58 +0100
- Subject: Re: [PATCH v3 9/9] compile: compile printf: gdbserver support
- Authentication-results: sourceware.org; auth=none
- References: <20150411194322 dot 29128 dot 52477 dot stgit at host1 dot jankratochvil dot net> <20150411194437 dot 29128 dot 58569 dot stgit at host1 dot jankratochvil dot net>
On 04/11/2015 08:44 PM, Jan Kratochvil wrote:
> Hi,
>
> former patch injects plain:
> printf (...);
> This patch injects gdbserver-compatible:
> f = open_memstream (&s, ...);
> fprintf (f, ...);
> fclose (f);
> return s;
(A more expanded explanation would have helped here. The first time I
skimmed this, I didn't really understand what this meant.)
So the issue here is that calling "printf" in the inferior ends up
with output sent to the inferior's stdout. If gdbserver is running on a
separate terminal (or machine), then the output of "compile printf" without
this patch goes to the inferior's terminal, unlike using "(gdb) printf ...".
That's not just an issue for gdbserver, actually. Even with the native target,
using "compile printf" without this patch against an inferior that gdb attached
to, with "attach PID" (a process that was already running on a separate
terminal), or if you use the "set inferior-tty" option, you get the exact
same problem.
> @@ -233,10 +241,15 @@ add_code_footer (enum compile_i_scope_types type, struct ui_file *buf)
> {
> switch (type)
> {
> + case COMPILE_I_PRINTF_SCOPE:
> + fputs_unfiltered ("\tif (fclose (__gdb_outf) != 0)\n"
> + "\t\treturn NULL;\n"
> + "\treturn __gdb_retval;\n",
> + buf);
> + // FALLTHRU
Please use /* */ comments, here and elsewhere.
(replying to the other mail)
Thanks,
Pedro Alves