old-cross-binutils/gdb/testsuite/lib
Pedro Alves 17b2616cba PR gdb/13860: don't lose '-interpreter-exec console EXECUTION_COMMAND''s output in async mode.
The other part of PR gdb/13860 is about console execution commands in
MI getting their output half lost.  E.g., take the finish command,
executed on a frontend's GDB console:

sync:

  finish
  &"finish\n"
  ~"Run till exit from #0  usleep (useconds=10) at ../sysdeps/unix/sysv/linux/usleep.c:27\n"
  ^running
  *running,thread-id="1"
  (gdb)
  ~"0x00000000004004d7 in foo () at stepinf.c:6\n"
  ~"6\t    usleep (10);\n"
  ~"Value returned is $1 = 0\n"
  *stopped,reason="function-finished",frame={addr="0x00000000004004d7",func="foo",args=[],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="6"},thread-id="1",stopped-threads="all",core="1"

async:

  finish
  &"finish\n"
  ~"Run till exit from #0  usleep (useconds=10) at ../sysdeps/unix/sysv/linux/usleep.c:27\n"
  ^running
  *running,thread-id="1"
  (gdb)
  *stopped,reason="function-finished",frame={addr="0x00000000004004d7",func="foo",args=[],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="6"},gdb-result-var="$1",return-value="0",thread-id="1",stopped-threads="all",core="0"

Note how all the "Value returned" etc. output is missing in async mode.

The same happens with e.g., catchpoints:

  =breakpoint-modified,bkpt={number="1",type="catchpoint",disp="keep",enabled="y",what="22016",times="1"}
  ~"\nCatchpoint "
  ~"1 (forked process 22016), 0x0000003791cbd8a6 in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/fork.c:131\n"
  ~"131\t  pid = ARCH_FORK ();\n"
  *stopped,reason="fork",disp="keep",bkptno="1",newpid="22016",frame={addr="0x0000003791cbd8a6",func="__libc_fork",args=[],file="../nptl/sysdeps/unix/sysv/linux/fork.c",fullname="/usr/src/debug/glibc-2.14-394-g8f3b1ff/nptl/sysdeps/unix/sysv/linux/fork.c",line="131"},thread-id="1",stopped-threads="all",core="0"

where all those ~ lines are missing in async mode, or just the "step"
current line indication:

  s
  &"s\n"
  ^running
  *running,thread-id="all"
  (gdb)
  ~"13\t  foo ();\n"
  *stopped,frame={addr="0x00000000004004ef",func="main",args=[{name="argc",value="1"},{name="argv",value="0x7fffffffdd78"}],file="stepinf.c",fullname="/home/pedro/gdb/tests/stepinf.c",line="13"},thread-id="1",stopped-threads="all",core="3"
  (gdb)

Or in the case of the PRs example, the "Stopped due to shared library
event" note:

  start
  &"start\n"
  ~"Temporary breakpoint 1 at 0x400608: file ../../../src/gdb/testsuite/gdb.mi/solib-main.c, line 21.\n"
  =breakpoint-created,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0000000000400608",func="main",file="../../../src/gdb/testsuite/gdb.mi/solib-main.c",fullname="/home/pedro/gdb/mygit/src/gdb/testsuite/gdb.mi/solib-main.c",line="21",times="0",original-location="main"}
  ~"Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.mi/solib-main \n"
  =thread-group-started,id="i1",pid="21990"
  =thread-created,id="1",group-id="i1"
  ^running
  *running,thread-id="all"
  (gdb)
  =library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
  ~"Stopped due to shared library event (no libraries added or removed)\n"
  *stopped,reason="solib-event",thread-id="1",stopped-threads="all",core="3"
  (gdb)

IMO, if you're typing execution commands in a frontend's console, you
expect to see their output.  Indeed it's what you get in sync mode.  I
think async mode should do the same.  Deciding what to mirror to the
console wrt to breakpoints and random stops gets messy real fast.
E.g., say "s" trips on a breakpoint.  We'd clearly want to mirror the
event to the console in this case.  But what about more complicated
cases like "s&; thread n; s&", and one of those steps spawning a new
thread, and that thread hitting a breakpoint?  It's impossible in
general to track whether the thread had any relation to the commands
that had been executed.  So I think we should just simplify and always
mirror breakpoints and random events to the console.

Notes:

  - mi->out is the same as gdb_stdout when MI is the current
    interpreter.  I think that referring to that directly is cleaner.
    An earlier revision of this patch made the changes that are now
    done in mi_on_normal_stop directly in infrun.c:normal_stop, and so
    not having an obvious place to put the new uiout by then, and not
    wanting to abuse CLI's uiout, I made a temporary uiout when
    necessary.

  - Hopefuly the rest of the patch is more or less obvious given the
    comments added.

Tested on x86_64 Fedora 20, no regressions.

2014-05-21  Pedro Alves  <palves@redhat.com>

	PR gdb/13860
	* gdbthread.h (struct thread_control_state): New field
	`command_interp'.
	* infrun.c (follow_fork): Copy the new thread control field to the
	child fork thread.
	(clear_proceed_status_thread): Clear the new thread control field.
	(proceed): Set the new thread control field.
	* interps.h (command_interp): Declare.
	* interps.c (command_interpreter): New global.
	(command_interp): New function.
	(interp_exec): Set `command_interpreter' while here.
	* cli-out.c (cli_uiout_dtor): New function.
	(cli_ui_out_impl): Install it.
	* mi/mi-interp.c: Include cli-out.h.
	(mi_cmd_interpreter_exec): Add comment.
	(restore_current_uiout_cleanup): New function.
	(ui_out_free_cleanup): New function.
	(mi_on_normal_stop): If finishing an execution command started by
	a CLI command, or any kind of breakpoint-like event triggered,
	print the stop event to the output (CLI) stream.
	* mi/mi-out.c (mi_ui_out_impl): Install NULL `dtor' handler.

2014-05-21  Pedro Alves  <palves@redhat.com>

	PR gdb/13860
	* gdb.mi/mi-cli.exp (line_callee4_next_step): New global.
	(top level): Test that output related to execution commands is
	sent to the console with CLI commands, but not with MI commands.
	Test that breakpoint events are always mirrored to the console.
	Also expect the new source line to be output after a "next" in
	async mode too.  Make it a pass/fail test.
	* gdb.mi/mi-solib.exp: Test that the CLI solib event note is
	output.
	* lib/mi-support.exp (mi_gdb_expect_cli_output): New procedure.
2014-05-21 23:17:23 +01:00
..
ada.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
append_gdb_boards_dir.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
cache.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
cell.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
cl_util.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
cl_util.h Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
compiler.c Add support to recognize clang. 2014-04-07 14:14:03 -07:00
compiler.cc Add support to recognize clang. 2014-04-07 14:14:03 -07:00
cp-support.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
d-support.exp Add gdb.dlang to the gdb testsuite for the purpose of creating D 2014-01-18 18:09:28 +00:00
dwarf.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
fortran.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
future.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb-guile.exp Add Guile as an extension language. 2014-02-09 19:40:01 -08:00
gdb-python.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
gdb.exp gdb/testsuite: Bump up `match_max' 2014-05-21 20:34:57 +01:00
gdbserver-support.exp Fix wrapper.exp testcase with stdio gdbserver. 2014-04-16 10:40:41 -07:00
go.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
java.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
mi-support.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
objc.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
opencl.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
opencl_hostapp.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
opencl_kernel.cl
pascal.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
perftest.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
prelink-support.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
prompt.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
range-stepping-support.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
selftest-support.exp Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
set_unbuffered_mode.c Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
trace-support.exp Check tracefile is generated by binary execution 2014-04-22 09:57:44 +08:00