This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3 9/9] compile: compile printf: gdbserver support


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]