old-cross-binutils/gdb/testsuite/gdb.mi
Simon Marchi 6ef284bd18 PR mi/15806: Fix quoting of async events
Original patch:
https://sourceware.org/ml/gdb-patches/2014-04/msg00552.html

New in v2:
* In remote.c:escape_buffer, pass '\\' to fputstrn_unfiltered/printchar to
make sure backslashes are escaped in remote debug output.
* Updated function documentation for printchar.

See updated ChangeLog below.

--------------------

The quoting in whatever goes in the event_channel of MI is little bit broken.

Link for the lazy:
  https://sourceware.org/bugzilla/show_bug.cgi?id=15806

Here is an example of a =library-loaded event with an ill-named directory,
/tmp/how"are\you (the problem is present with every directory on Windows since
it uses backslashes as a path separator). The result will be the following:

=library-loaded,id="/tmp/how"are\\you/libexpat.so.1",...

The " between 'how' and 'are' should be escaped.

Another bad behavior is double escaping in =breakpoint-created, for example:

=breakpoint-created,bkpt={...,fullname="/tmp/how\\"are\\\\you/test.c",...}

The two backslashes before 'how' should be one and the four before 'you' should
be two.

The reason for this is that when sending something to an MI console, escaping
can take place at two different moments (the actual escaping work is always
done in the printchar function):

1. When generating the content, if ui_out_field_* functions are used. Here,
fields are automatically quoted with " and properly escaped. At least
mi_field_string does it, not sure about mi_field_fmt, I need to investigate
further.

2. When gdb_flush is called, to send the data in the buffer of the console to
the actual output (stdout). At this point, mi_console_raw_packet takes the
whole string in the buffer, quotes it, and escapes all occurences of the
quoting character and backslashes. The event_channel does not specify a quoting
character, so quotes are not escaped here, only backslashes.

The problem with =library-loaded is that it does use fprintf_unfiltered, which
doesn't do escaping (so, no #1). When gdb_flush is called, backslashes are
escaped (#2).

The problem with =breakpoint-created is that it first uses ui_out_field_*
functions to generate its output, so backslashes and quotes are escaped there
(#1). backslashes are escaped again in #2, leading to an overdose of
backslashes.

In retrospect, there is no way escaping can be done reliably in
mi_console_raw_packet for data that is already formatted, such as
event_channel. At this point, there is no way to differentiate quotes that
delimit field values from those that should be escaped. In the case of other MI
consoles, it is ok since mi_console_raw_packet receives one big string that
should be quoted and escaped as a whole.

So, first part of the fix: for the MI channels that specify no quoting
character, no escaping at all should be done in mi_console_raw_packet (that's
the change in printchar, thanks to Yuanhui Zhang for this). For those channels,
whoever generates the content is responsible for proper quoting and escaping.
This will fix the =breakpoint-created kind of problem.

Second part of the fix is to make =library-loaded generate content that is
properly escaped. For this, we use ui_out_field_* functions, instead of one big
fprintf_unfiltered. =library-unloaded suffered from the same problem so it is
modified as well. There might be other events that need fixing too, but that's
all I found with a quick scan. Those that use fprintf_unfiltered but whose sole
variable data is a %d are not critical, since it won't generate a " or a \.

Finally, a test has been fixed, as it was expecting an erroneous output.
Otherwise, all other tests that were previously passing still pass (x86-64
linux).

gdb/ChangeLog:

2014-06-02  Simon Marchi  <simon.marchi@ericsson.com>

	PR mi/15806
	* utils.c (printchar): Don't escape at all if quoter is NUL.
	Update function documentation to clarify effect of parameter
	QUOTER.
	* remote.c (escape_buffer): Pass '\\' as the quoter to
	fputstrn_unfiltered.
	* mi/mi-interp.c (mi_solib_loaded): Use ui_out_field_* functions to
	generate the output.
	(mi_solib_unloaded): Same.

gdb/testsuite/ChangeLog:

2014-06-02  Simon Marchi  <simon.marchi@ericsson.com>

	* gdb.mi/mi-breakpoint-changed.exp (test_insert_delete_modify): Fix
	erroneous dprintf expected input.
2014-06-05 17:59:46 -04:00
..
array.f Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
basics.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
ChangeLog-1999-2003
dw2-ref-missing-frame-func.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
dw2-ref-missing-frame-main.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
dw2-ref-missing-frame.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
dw2-ref-missing-frame.S Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb669.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb680.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb701.c
gdb701.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb792.cc
gdb792.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb2549.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Makefile.in
mi-async.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-basics.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-break.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-breakpoint-changed.exp PR mi/15806: Fix quoting of async events 2014-06-05 17:59:46 -04:00
mi-catch-load-so.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-catch-load.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-catch-load.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-cli.exp PR gdb/13860 - Make MI sync vs async output (closer to) the same. 2014-05-29 13:09:45 +01:00
mi-cmd-param-changed.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-condbreak-call-thr-state-mt.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state-st.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state.c PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-condbreak-call-thr-state.exp PR15693 - Fix spurious *running events, thread state, dprintf-style call 2014-05-29 12:27:01 +01:00
mi-console.c
mi-console.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-disassemble.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-dprintf.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-dprintf.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-eval.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-file-transfer.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-file.exp Fix mi-file.exp fails on remote host 2014-05-14 20:11:53 +08:00
mi-fill-memory.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-fullname-deleted.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-hack-cli.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-i-cmd.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-info-os.exp gdb.mi/mi-info-os.exp: Fix cross-debugger testing 2014-01-09 19:57:13 +00:00
mi-inheritance-syntax-error.cc
mi-inheritance-syntax-error.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-language.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-logging.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-memory-changed.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-nonstop-exit.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nonstop.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-ns-stale-regcache.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsintrall.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsmoribund.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-nsthrexec.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-pending.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-pending.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-pendshr.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-pthreads.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-read-memory.c
mi-read-memory.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-record-changed.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-reg-undefined.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-reg-undefined.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-reg-undefined.S Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-regs.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-return.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-reverse.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-simplerun.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-solib.exp PR gdb/13860: don't lose '-interpreter-exec console EXECUTION_COMMAND''s output in async mode. 2014-05-21 23:17:23 +01:00
mi-stack.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-stack.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-start.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-start.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-stepi.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-stepn.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-stepn.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-syn-frame.c
mi-syn-frame.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-undefined-cmd.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-until.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-block.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-child-f.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-child.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-child.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-cmd.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-cp.cc Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-cp.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-create-rtti.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-create-rtti.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-display.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-var-invalidate.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-rtti.cc Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-var-rtti.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-vla-c99.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi-watch-nonstop.exp enable target async by default; separate MI and target notions of async 2014-05-29 14:38:02 +01:00
mi-watch.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi2-amd64-entry-value.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi2-amd64-entry-value.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
mi2-amd64-entry-value.s Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi2-prompt.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi2-var-child.exp Introduce some new MI test suite cleanups for breakpoint and 2014-04-23 12:17:31 -07:00
non-stop-exit.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
non-stop.c Add return value for non-void function return statements to fix error in clang build. 2014-04-14 08:34:51 -07:00
ns-stale-regcache.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
nsintrall.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
nsmoribund.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
nsthrexec.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pending.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pendshr1.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pendshr2.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pr11022.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pr11022.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
pthreads.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
solib-lib.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
solib-main.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
testcmds
until.c
var-cmd.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
vla.c test: add mi vla test 2014-04-14 09:52:11 -07:00
watch-nonstop.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00