Commit Graph

34880 Commits

Author SHA1 Message Date
Jan Kratochvil e6cf2ae8bb PR 17170 - testcase for GDB global --statistics regression - fix up.
Add missing file to previous entry.
2014-07-17 13:59:03 +02:00
Jan Kratochvil 17d0c5c8f0 PR 17170 - testcase for GDB global --statistics regression.
gdb/testsuite/
2014-07-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/17170
	* gdb.base/statistics.exp: New file.

Message-ID: <20140712174217.GA1478@host2.jankratochvil.net>
2014-07-17 13:56:24 +02:00
Doug Evans 74b49205e0 Add reference to PR 17170 to previous entry. 2014-07-17 02:42:55 -07:00
Doug Evans b8b8facf90 Fix 17170.
* maint.c (count_symtabs_and_blocks): Handle NULL
	current_program_space.
	(report_command_stats): Check global enabled flag in addition to
	recorded enabled flag.
	(make_command_stats_cleanup): Handle msg_type == 0, startup.

	testsuite/
	* gdb.base/maint.exp: Update testing of per-command stats.
2014-07-17 02:38:32 -07:00
Pedro Alves 69ff6be55c Linux: Use kill_lwp/tkill instead of kill when killing a process
Since we use tkill everywhere, using kill to try to kill each lwp
individually looks suspiciously odd.  We should really be using tgkill
everywhere, but at least while we don't get there this makes us
consistent.

gdb/gdbserver/
2014-07-16  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_kill_one_lwp): Use kill_lwp, not kill.

gdb/
2014-07-16  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (kill_callback): Use kill_lwp, not kill.
2014-07-16 20:06:55 +01:00
Pedro Alves 1b5d0ab34c gdb.trace/tfile.c: Remove Thumb bit in one more more, general cleanup
I noticed that the existing code casts a function's address to 'long',
but that doesn't work correctly on some ABIs, like Win64, where long
is 32-bit and while pointers are 64-bit:

  func_addr = (long) &write_basic_trace_file;

Fixing that showed there's actually another place in the file that
writes a function address to file, and therefore should clear the
Thumb bit.  This commit adds a macro+function pair to centralize the
Thumb bit handling, and uses it in both places.

The rest is just enough changes to make the file build without
warnings with "-Wall -Wextra" with x86_64-w64-mingw32-gcc and
i686-w64-mingw32-gcc cross compilers, and with -m32/-m64 on x86_64
GNU/Linux.  Currently with x86_64-w64-mingw32-gcc we get:

  $ x86_64-w64-mingw32-gcc tfile.c  -Wall -DTFILE_DIR=\"\"
  tfile.c: In function 'start_trace_file':
  tfile.c:51:23: error: 'S_IRGRP' undeclared (first use in this function)
	 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
			 ^
  tfile.c:51:23: note: each undeclared identifier is reported only once for each function it appears in
  tfile.c:51:31: error: 'S_IROTH' undeclared (first use in this function)
	 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
				 ^
  tfile.c: In function 'add_memory_block':
  tfile.c:79:10: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     ll_x = (unsigned long) addr;
	    ^
  tfile.c: In function 'write_basic_trace_file':
  tfile.c:113:15: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     func_addr = (long) &write_basic_trace_file;
		 ^
  tfile.c:137:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
     add_memory_block (&testglob, sizeof (testglob));
     ^
  tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
   add_memory_block (char *addr, int size)
   ^
  tfile.c:139:3: warning: passing argument 1 of 'add_memory_block' from incompatible pointer type [enabled by default]
     add_memory_block (&testglob2, 1);
     ^
  tfile.c:72:1: note: expected 'char *' but argument is of type 'int *'
   add_memory_block (char *addr, int size)
   ^
  tfile.c: In function 'write_error_trace_file':
  tfile.c:185:3: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
     char *hex = alloca (len * 2 + 1);
     ^
  tfile.c:185:15: warning: incompatible implicit declaration of built-in function 'alloca' [enabled by default]
     char *hex = alloca (len * 2 + 1);
		 ^
  tfile.c:211:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
	(long) &write_basic_trace_file);
      ^

Tested on x86_64 Fedora 20, -m64 and -m32.
Tested by Yao on arm targets.

gdb/testsuite/
2014-07-16  Pedro Alves  <palves@redhat.com>

	* gdb.trace/tfile.c: Include unistd.h and stdint.h.
	(start_trace_file): Guard S_IRGRP and S_IROTH uses behind #ifdef.
	(tfile_write_64, tfile_write_16, tfile_write_8, tfile_write_addr)
	(tfile_write_buf): New functions.
	(add_memory_block): Rewrite using the above.
	(adjust_function_address): New function.
	(FUNCTION_ADDRESS): New macro.
	(write_basic_trace_file): Remove short_x local, and use
	tfile_write_16. Change type of func_addr local to unsigned long
	long.  Use FUNCTION_ADDRESS instead of handling the Thumb bit
	here.  Cast argument of add_memory_block to char pointer.
	(write_error_trace_file): Avoid alloca.  Use FUNCTION_ADDRESS.
	(main): Remove parameters.
	* gdb.trace/tfile.exp: Remove nowarnings.
2014-07-16 19:25:41 +01:00
Simon Marchi 4d974e8854 Add test for string evaluation with "debug expression" on
As Joel pointed out in...
https://sourceware.org/ml/gdb-patches/2014-07/msg00391.html
...it would be nice to add a test for that.

Tested on Linux x86_64 (Ubuntu 14.10).

gdb/testsuite/ChangeLog

2014-07-15  Simon Marchi  <simon.marchi@ericsson.com>

	* gdb.base/debug-expr.exp: Test string evaluation with
	"debug expression" on.
2014-07-16 12:43:11 -04:00
Tom Tromey 252db1b5de reformat comment in target.h
A comment in target.h went past the column limit.  This patch
reformats it.  I'm pushing this as obvious.

2014-07-16  Tom Tromey  <tromey@redhat.com>

	* target.h (struct target_ops) <to_delete_record>: Reformat
	comment.
2014-07-16 08:09:27 -06:00
Tom Tromey a432721e61 rebuild target-delegates.c
target-delegates.c was out of date.  This patch rebuilds it.
Built and regtested on x86-64 Fedora 20.
Committed as obvious.

2014-07-16  Tom Tromey  <tromey@redhat.com>

	* target-delegates.c: Rebuild.
2014-07-16 08:05:03 -06:00
Pedro Alves 41e9956873 gdb.base/reread.exp: Really restart GDB
The other day I noticed that default_gdb_start reuses the GDB process
if it has been spawned already:

proc default_gdb_start { } {
...
    if [info exists gdb_spawn_id] {
	return 0
    }

I was a bit surprised, and so I hacked in an error to check whether
anything is relying on it:

 + if [info exists gdb_spawn_id] {
 +    error "GDB already spawned"
 + }

And lo, that tripped on a funny buglet (see below).  The comment in
reread.exp says "Restart GDB entirely", but in reality, due to the
above, that's not what is happening, as a gdb_exit call is missing.
The test is proceeding with the previous GDB process...

I don't really want to go hunt for whether there's an odd setup out
there that assumes this in its board file or something, so for now,
I'm taking the simple route of just making the test do what it says it
does.  I think this much makes it an obvious fix.

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 (gdb) PASS: gdb.base/reread.exp: run to foo() second time
 ERROR: tcl error sourcing ../src/gdb/testsuite/gdb.base/reread.exp.
 ERROR: GDB already spawned
     while executing
 "error "GDB already spawned""
     invoked from within
 "if [info exists gdb_spawn_id] {
	 error "GDB already spawned"
     }"
     (procedure "default_gdb_start" line 22)
     invoked from within
 "default_gdb_start"
     (procedure "gdb_start" line 2)
     invoked from within
 "gdb_start"
     invoked from within
 "if [is_remote target] {
     unsupported "second pass: GDB should check for changes before running"
 } else {

     # Put the older executable back in pl..."
     (file "../src/gdb/testsuite/gdb.base/reread.exp" line 114)
     invoked from within
 "source ../src/gdb/testsuite/gdb.base/reread.exp"
     ("uplevel" body line 1)
     invoked from within
 "uplevel #0 source ../src/gdb/testsuite/gdb.base/reread.exp"
     invoked from within
 "catch "uplevel #0 source $test_file_name""
 testcase ../src/gdb/testsuite/gdb.base/reread.exp completed in 1 seconds
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gdb/testsuite/
2014-07-15  Pedro Alves  <palves@redhat.com>

	* gdb.base/reread.exp: Use clean_restart.
2014-07-15 17:30:34 +01:00
Pierre Langlois 487d975399 Add support for the __flash qualifier on AVR
The __flash qualifier is part of the named address spaces for AVR [1]. It
allows putting read-only data in the flash memory, normally reserved for
code.

When used together with a pointer, the DW_AT_address_class attribute is set
to 1 and allows GDB to detect that when it will be dereferenced, the data
will be loaded from the flash memory (with the LPM instruction).

We can now properly debug the following code:

~~~
const __flash char data_in_flash = 0xab;

int
main (void)
{
  const __flash char *pointer_to_flash = &data_in_flash;
}
~~~

~~~
(gdb) print pointer_to_flash
$1 = 0x1e8 <data_in_flash> "\253"
(gdb) print/x *pointer_to_flash
$2 = 0xab
(gdb) x/x pointer_to_flash
0x1e8 <data_in_flash>: 0xXXXXXXab
~~~

Whereas previously, GDB would revert to the default address space which is
RAM and mapped in higher memory:

~~~
(gdb) print pointer_to_flash
$1 = 0x8001e8 ""
~~~

[1] https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html

2014-07-15  Pierre Langlois  <pierre.langlois@embecosm.com>

gdb/
	* avr-tdep.c (AVR_TYPE_ADDRESS_CLASS_FLASH): New macro.
	(AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH): Likewise.
	(avr_address_to_pointer): Check for AVR_TYPE_ADDRESS_CLASS_FLASH.
	(avr_pointer_to_address): Likewise.
	(avr_address_class_type_flags): New function.
	(avr_address_class_type_flags_to_name): Likewise.
	(avr_address_class_name_to_type_flags): Likewise.
	(avr_gdbarch_init): Set address_class_type_flags,
	address_class_type_flags_to_name and
	address_class_name_to_type_flags.

gdb/testsuite/
	* gdb.arch/avr-flash-qualifer.c: New.
	* gdb.arch/avr-flash-qualifer.exp: New.
2014-07-15 17:03:09 +01:00
Pedro Alves 57745c903f [GDB/Linux] Avoid stale errno
The fix that went into GDBserver is also needed on the GDB side.

Although most compilers follow right-to-left evaluation order, the
order of evaluation of a function call's arguments is really
unspecified.  target_pid_to_str may well clobber errno when we get to
evaluate the third argument to fprintf_unfiltered.

gdb/
2014-07-15  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (kill_callback): Save errno and work with saved
	copy.
2014-07-15 16:22:14 +01:00
Simon Marchi 2d40be181f Handle OP_STRING in dump_subexp_body_standard
For some reason, OP_STRING is not handled in dump_subexp_body_standard.
This makes the output of "set debug expression 1" very bad when a string
is involved. Example:

(gdb) set debug expression 1
(gdb) print "hello"
... (random garbage, possibly segfault)

This commit handles OP_STRING and skips the appropriate number of exp
elements. The line corresponding to the string now looks like:

	    0  OP_STRING             Language-specific string type: 0

gdb/ChangeLog:

2014-07-15  Simon Marchi  <simon.marchi@ericsson.com>

	* expprint.c (dump_subexp_body_standard): Handle OP_STRING.
2014-07-15 11:18:04 -04:00
Pedro Alves ce9e3fe795 [GDBserver] Avoid stale errno
Although most compilers follow right-to-left evaluation order, the
order of evaluation of a function call's arguments is really
unspecified.  target_pid_to_str or ptid_of may well clobber errno when
we get to evaluate the third argument to debug_printf.

gdb/gdbserver/
2014-07-15  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_kill_one_lwp): Save errno and work with saved
	copy.
2014-07-15 15:35:28 +01:00
Edjunior Barbosa Machado 572f65559b 2014-07-14 Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
* ppc-linux-nat.c (ppc_linux_can_use_hw_breakpoint): Report no hardware
	breakpoint support correctly.
2014-07-14 20:18:10 -03:00
Pedro Alves cc1c52ad65 Add missing ChangeLog entry for 15cd413a
Put GDB's terminal settings into effect when paginating
gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* utils.c (prompt_for_continue): Call target_terminal_ours.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* gdb.base/paginate-after-ctrl-c-running.c: New file.
	* gdb.base/paginate-after-ctrl-c-running.exp: New file.
2014-07-14 20:39:53 +01:00
Pedro Alves 8258415802 Put GDB's terminal settings into effect when paginating
When the target is resumed in the foreground, we put the inferior's
terminal settings into effect, and remove stdin from the event loop.
When the target stops, we put GDB's terminal settings into effect
again, and re-register stdin in the event loop, ready for user input.
The former is done by target_terminal_inferior, and the latter by
target_terminal_ours.

There's an intermediate -- target_terminal_ours_for_output -- that is
called when printing output related to target events, and we don't
know yet whether we'll stop the program.  That puts our terminal
settings into effect, enough to get proper results from our output,
but leaves input wired into the inferior.

If such output paginates, then we need the full target_terminal_ours
in order for the user to be able to provide input to answer the
pagination query.

The test in this commit hangs in async-capable targets without the fix
(as the user/test can't answer the pagination query).  It doesn't hang
on sync targets because on those we don't unregister stdin from the
event loop while the target is running (because we block in
target_wait instead of in the event loop in that case).

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* utils.c (prompt_for_continue): Call target_terminal_ours.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* gdb.base/paginate-after-ctrl-c-running.c: New file.
 	* gdb.base/paginate-after-ctrl-c-running.exp: New file.
2014-07-14 20:35:31 +01:00
Pedro Alves 1e9735707b Fix double prompt
If an error is thrown while handling a target event (within
fetch_inferior_event), and, the interpreter is not async (but the
target is), then GDB prints the prompt twice.

One way to see that in action is throw a QUIT while in a pagination
prompt issued from within fetch_inferior_event (or one of its
callees).  E.g. from the test:

 ---Type <return> to continue, or q <return> to quit---
 ^CQuit
 (gdb) (gdb) p 1
 ^^^^^^^^^^^
 $1 = 1
 (gdb)

The issue is that inferior_event_handler swallows errors and notifies
the observers (the interpreters) about the command error, even if the
interpreter is forced sync while we're handling a nested event loop
(for execute_command).  The observers print a prompt, and then when we
get back to the top event loop, we print another (in
start_event_loop).

I see no reason the error should be swallowed here.  Just cancel the
execution related bits and let the error propagate to the top level
(start_event_loop), which re-enables stdin and notifies observers.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* inf-loop.c (inferior_event_handler): Use TRY_CATCH instead of
	catch_errors.  Don't re-enable stdin or notify observers where,
	and rethrow error.
	(fetch_inferior_event_wrapper): Delete.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* gdb.base/double-prompt-target-event-error.c: New file.
	* gdb.base/double-prompt-target-event-error.exp: New file.
2014-07-14 20:34:23 +01:00
Pedro Alves 93d6eb10ed Remove the target from the event loop while in secondary prompts
If a pagination prompt triggers while the target is running, and the
target exits before the user responded to the pagination query, this
happens:

  Starting program: foo
  ---Type <return> to continue, or q <return> to quit---No unwaited-for children left.
  Couldn't get registers: No such process.
  Couldn't get registers: No such process.
  Couldn't get registers: No such process.
  (gdb) Couldn't get registers: No such process.
  (gdb)

To reiterate, the user hasn't replied to the pagination prompt above.

A pagination query nests an event loop (in gdb_readline_wrapper).  In
async mode, in addition to stdin and signal handlers, we'll have the
target also installed in the event loop still.  So if the target
reports an event, that wakes up the nested event loop, which calls
into fetch_inferior_event etc. to handle the event which generates
further output, all while we should be waiting for pagination
confirmation...

(TBC, any target event that generates output ends up spuriously waking
up the pagination, though exits seem to be the worse kind.)

I've played with a couple different approaches to fixing this, while
at the same time trying to avoid being invasive.  Both revolve around
not listening to target events while in a pagination prompt (doing
anything else I think would be a much bigger change).

The approach taken just removes the target from the event loop while
within gdb_readline_wrapper.  The other approach used gdb_select
directly, with only input_fd installed, but that had the issue that it
didn't handle the async signal handlers, and turned out to be a bit
more code than the first version.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* top.c: Include "inf-loop.h".
	(struct gdb_readline_wrapper_cleanup) <target_is_async_orig>: New
	field.
	(gdb_readline_wrapper_cleanup): Make the target async again, if it
	was async before.
	(gdb_readline_wrapper): Store whether the target is async, and
	make it sync.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* gdb.base/paginate-inferior-exit.c: New file.
	* gdb.base/paginate-inferior-exit.exp: New file.
2014-07-14 20:33:16 +01:00
Pedro Alves 0017922d02 Background execution + pagination aborts readline/gdb
If pagination occurs as result of output sent as response to a target
event while the target is executing in the background, subsequent
input aborts readline/gdb:

 $ gdb program
 ...
 (gdb) continue&
 Continuing.
 (gdb)
 ---Type <return> to continue, or q <return> to quit---
 *return*
 ---Type <return> to continue, or q <return> to quit---
 Breakpoint 2, after_sleep () at paginate-bg-execution.c:21
 ---Type <return> to continue, or q <return> to quit---
 21        return; /* after sleep */
 p 1
 readline: readline_callback_read_char() called with no handler!
 *abort/SIGABRT*
 $

gdb_readline_wrapper_line removes the handler after a line is
processed.  Usually, we'll end up re-displaying the prompt, and that
reinstalls the handler.  But if the output is coming out of handling
a stop event, we don't re-display the prompt, and nothing restores the
handler.  So the next input wakes up the event loop and calls into
readline, which aborts.

We should do better with the prompt handling while the target is
running (I think we should coordinate with readline, and
hide/redisplay it around output), but that's a more invasive change
better done post 7.8, so this patch is conservative and just
reinstalls the handler as soon as we're out of the readline line
callback.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* top.c (gdb_readline_wrapper_line): Tweak comment.
	(gdb_readline_wrapper_cleanup): If readline is enabled, reinstall
	the input handler callback.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* gdb.base/paginate-bg-execution.c: New file.
	* gdb.base/paginate-bg-execution.exp: New file.
2014-07-14 20:32:13 +01:00
Pedro Alves 94696ad31c Canceling pagination caused by execution command from command line aborts readline/gdb
This fixes:

 $ ./gdb program -ex "set height 2" -ex "start"
 ...
 Reading symbols from /home/pedro/gdb/tests/threads...done.
 ---Type <return> to continue, or q <return> to quit---^CQuit  << ctrl-c triggers a Quit

 *type something*
 readline: readline_callback_read_char() called with no handler!
 Aborted
 $

Usually, if an error propagates all the way to the top level, we'll
re-enable stdin, in case the command that was running was a
synchronous command.  That's done in the event loop's actual loop
(event-loop.c:start_event_loop).  However, if a foreground execution
command is run before the event loop starts and throws, nothing is
presently reenabling stdin, which leaves sync_execution set.

When we do start the event loop, because sync_execution is still
(mistakenly) set, display_gdb_prompt removes the readline input
callback, even though stdin is registered in the event loop.  Any
input from here on results in readline aborting.

Such commands are run through catch_command_errors,
catch_command_errors_const, so add the tweak there.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* main.c: Include event-top.h.
	(handle_command_errors): New function.
	(catch_command_errors, catch_command_errors_const): Use it.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17072
	* gdb.base/paginate-execution-startup.c: New file.
	* gdb.base/paginate-execution-startup.exp: New file.
	* lib/gdb.exp (pagination_prompt): New global.
	(default_gdb_spawn): New procedure, factored out from
	default_gdb_spawn.
	(default_gdb_start): Adjust to call default_gdb_spawn.
	(gdb_spawn): New procedure.
2014-07-14 20:31:04 +01:00
Pedro Alves bd29394088 testsuite: Introduce gdb_assert
Often we'll do something like:

    if {$ok} {
	fail "whatever"
    } else {
	pass "whatever"
    }

This adds a helper procedure for that, and converts one random place
to use it, as an example.

2014-07-14  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_assert): New procedure.
	* gdb.trace/backtrace.exp (gdb_backtrace_tdp_4): Use it.
2014-07-14 20:30:41 +01:00
Pedro Alves 9d1e69a214 Move catch_command_errors and catch_command_errors_const to main.c
We'll need to add error handling code to commands run before the event
loop starts (commands in .gdbinit, -ex commands, etc.).  Turns out
those are run through catch_command_errors, and, catch_command_errors
is used nowhere else.  Move it (and the _const variant) to main.c, so
that we can further specialize it freely.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* exceptions.c (catch_command_errors, catch_command_errors_const):
	Moved to main.c.
	* exceptions.h (catch_command_errors_ftype)
	(catch_command_errors_const_ftype): Moved to main.c.
	(catch_command_errors, catch_command_errors_const): Delete
	declarations.
	* main.c (catch_command_errors_ftype)
	(catch_command_errors_const_ftype): Moved here from exceptions.h.
	(catch_command_errors, catch_command_errors_const)): Moved here
	from exceptions.c and make static.
2014-07-14 20:30:12 +01:00
Pedro Alves feefc97b59 Eliminate exceptions.c:print_any_exception.
exception_print and exception_fprintf call print_flush, which does all the
same flushing and annotation things that print_any_exception does, and more.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* exceptions.c (print_any_exception): Delete.
	(catch_exceptions_with_msg): Use exception_print instead of
	print_any_exception.
	(catch_errors): Use exception_fprintf instead of
	print_any_exception.
	(catch_command_errors, catch_command_errors_const): Use
	exception_print instead of print_any_exception.
2014-07-14 20:29:30 +01:00
Pedro Alves c933f875f4 Put the inferior's terminal settings in effect while running (fg) infcalls
The "call" and "print" commands presently always run synchronously, in
the foreground, but GDB currently forgets to put the inferior's
terminal settings into effect while running them, on async-capable
targets, resulting in:

 (gdb) print func ()
 hello world

 Program received signal SIGTTOU, Stopped (tty output).
 0x000000373bceb8d0 in __libc_tcdrain (fd=1) at ../sysdeps/unix/sysv/linux/tcdrain.c:29
 29          return INLINE_SYSCALL (ioctl, 3, fd, TCSBRK, 1);
 The program being debugged was signaled while in a function called from GDB.
 GDB remains in the frame where the signal was received.
 To change this behavior use "set unwindonsignal on".
 Evaluation of the expression containing the function
 (func) will be abandoned.
 When the function is done executing, GDB will silently stop.
 (gdb)

That's because target_terminal_inferior skips actually doing anything
if running in the background, and, nothing is setting sync_execution
while running infcalls:

 void
 target_terminal_inferior (void)
 {
   /* A background resume (``run&'') should leave GDB in control of the
      terminal.  Use target_can_async_p, not target_is_async_p, since at
      this point the target is not async yet.  However, if sync_execution
      is not set, we know it will become async prior to resume.  */
   if (target_can_async_p () && !sync_execution)
     return;

This would best be all cleaned up by making GDB not even call
target_terminal_inferior and try to pass the terminal to the inferior
if running in the background, but that's a more invasive fix that is
better done post-7.8.

This was originally caught by a patch later in this series that makes
catch_command_errors use exception_print instead of
print_any_exception.  Note that print_flush calls serial_drain_output
while print_any_exception doesnt't have that bit.  And,
gdb.gdb/python-selftest.exp does:

 gdb_test "call catch_command_errors(execute_command, \"python print 5\", 0, RETURN_MASK_ALL)" \
   "Python not initialized.* = 0"

which without this fix results in SIGTTOU...

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* infcall.c (run_inferior_call): Set 'sync_execution' while
	running the inferior call.

gdb/testsuite/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* gdb.base/execution-termios.c: New file.
	* gdb.base/execution-termios.exp: New file.
2014-07-14 19:55:30 +01:00
Pedro Alves feb6f816c2 Garbage collect value_contents_equal.
Hasn't been used in years.

gdb/
2014-07-14  Pedro Alves  <palves@redhat.com>

	* value.c (value_contents_equal): Delete function.
	* value.h (value_contents_equal): Delete declaration.
2014-07-14 18:48:09 +01:00
Tom Tromey d98b7a16a9 fix PR 17106
This fixes PR 17106, a regression in printing.

The bug is that resolve_dynamic_type follows struct members and
references, but doesn't consider the possibility of infinite
recursion.

This patch fixes the problem by limiting reference following to the
topmost layer of calls -- that is, reference-typed struct members are
never considered as being VLAs.

Built and regtested on x86-64 Fedora 20.
New test case included.

2014-07-14  Tom Tromey  <tromey@redhat.com>

	PR exp/17106:
	* gdbtypes.c (is_dynamic_type_internal): New function, from
	is_dynamic_type.
	(is_dynamic_type): Rewrite.
	(resolve_dynamic_union): Use resolve_dynamic_type_internal.
	(resolve_dynamic_struct): Likewise.
	(resolve_dynamic_type_internal): New function, from
	resolve_dynamic_type.
	(resolve_dynamic_type): Rewrite.

2014-07-14  Tom Tromey  <tromey@redhat.com>

	* gdb.cp/vla-cxx.cc: New file.
	* gdb.cp/vla-cxx.exp: New file.
2014-07-14 10:14:36 -06:00
Tom Tromey 548740d6bd fix record "run" regression
This fixes the record "run" regression pointed out by Marc Khouzam:

    https://sourceware.org/ml/gdb/2014-06/msg00096.html

The bug is that target_require_runnable must agree with the handling
of the "run" target, but currently it is out of sync.  This patch
fixes the problem by changing target_require_runnable to also ignore
the record_stratum.

Built and regtested on x86-64 Fedora 20.
New test case included.

2014-07-14  Tom Tromey  <tromey@redhat.com>

	* target.c (target_require_runnable): Also check record_stratum.
	Update comment.

2014-07-14  Tom Tromey  <tromey@redhat.com>

	* gdb.reverse/rerun-prec.c: New file.
	* gdb.reverse/rerun-prec.exp: New file.
2014-07-14 08:33:05 -06:00
Maciej W. Rozycki a25eb0280d gdb/testsuite: Add a way to send multiple init commands
Right now we provide a board info entry, `gdb_init_command', that allows
one to send a single command to GDB before the program to be debugged is
started.  This is useful e.g. for slow remote targets to change the
default "remotetimeout" setting.  Occasionally I found a need to send
multiple commands instead, however this cannot be achieved with
`gdb_init_command'.

This change therefore extends the mechanism by adding a TCL list of GDB
commands to send, via a board info entry called `gdb_init_commands'.
There is no limit as to the number of commands put there.  The old
`gdb_init_command' mechanism remains supported for compatibility with
existing people's environments.

	* lib/gdb-utils.exp: New file.
	* lib/gdb.exp (gdb_run_cmd): Call gdb_init_commands, replacing
	inline `gdb_init_command' processing.
	(gdb_start_cmd): Likewise.
	* lib/mi-support.exp (mi_run_cmd): Likewise.
	* README: Document `gdb_init_command' and `gdb_init_commands'.
2014-07-12 01:39:40 +01:00
Jan Kratochvil 218c265560 Fix false argv0-symlink.exp FAIL running under a very long directory name
Starting program: /home/jkratoch/redhat/gdb-test-fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gdb/testsuite/gdb.base/argv0-symlink-filelink ^M
[...]
(gdb) print argv[0]^M
$1 = 0x7fffffffda39 "/home/jkratoch/redhat/gdb-test-", 'f' <repeats 169 times>...^M
(gdb) FAIL: gdb.base/argv0-symlink.exp: kept file symbolic link name

after "set print repeats 10000":

print argv[0]^M
$1 = 0x7fffffffda39 "/home/jkratoch/redhat/gdb-test-fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"...^M
(gdb) FAIL: gdb.base/argv0-symlink.exp: kept file symbolic link name

after "set print elements 10000":

print argv[0]^M
$1 = 0x7fffffffda39 "/home/jkratoch/redhat/gdb-test-fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff/gdb/testsuite/gdb.base/argv0-symlink-filelink"^M
(gdb) PASS: gdb.base/argv0-symlink.exp: kept file symbolic link name

gdb/testsuite/
2014-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix false FAIL running under a very long directory name.
	* gdb.base/argv0-symlink.exp: Add "set print repeats 10000"
	and "set print elements 10000".  Twice.
2014-07-11 17:26:42 +02:00
Yao Qi 808f7ab1fc Stop prologue analysis when past the epilogue
We see a fail in gdb.trace/entry-values.exp on armv4t thumb,

bt^M
 #0  0x000086fc in foo (i=0, i@entry=<optimized out>, j=2, j@entry=<optimized out>)^M
 #1  0x00000002 in ?? ()^M
Backtrace stopped: previous frame identical to this frame (corrupt stack?)^M
(gdb) FAIL: gdb.trace/entry-values.exp: bt (1) (pattern 1)

The fail is caused by incorrect prologue analysis, which can be illustrated by
setting a breakpoint on function foo,

(gdb) disassemble foo
Dump of assembler code for function foo:
   0x000086e8 <+0>:	push	{r7, lr}
   0x000086ea <+2>:	sub	sp, #8
   0x000086ec <+4>:	add	r7, sp, #0
   0x000086ee <+6>:	str	r0, [r7, #4]
   0x000086f0 <+8>:	str	r1, [r7, #0]
   0x000086f2 <+10>:	movs	r3, #0
   0x000086f4 <+12>:	adds	r0, r3, #0
   0x000086f6 <+14>:	mov	sp, r7
   0x000086f8 <+16>:	add	sp, #8
   0x000086fa <+18>:	pop	{r7}
   0x000086fc <+20>:	pop	{r1}
   0x000086fe <+22>:	bx	r1
End of assembler dump.
(gdb) b foo
Breakpoint 1 at 0x86fc

As we can see, GDB analyzes the prologue and skip the prologue to the last
instruction but one.  The breakpoint is set within the epilogue, and GDB
skips too many instruction for prologue.  This patch teaches GDB to stop
prologue analysis when goes into the epilogue.  With this patch applied,
GDB is able to unwind correctly,

(gdb) bt
 #0  0x000086f6 in foo (i=0, i@entry=2, j=2, j@entry=3)
 #1  0x00008718 in bar (i=<optimized out>)
 #2  0x00008758 in main ()

gdb:

2014-07-11  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (thumb_analyze_prologue): Break the loop if
	thumb_instruction_restores_sp return true.
2014-07-11 21:34:01 +08:00
Yao Qi 540314bdd8 Match instruction adjusts SP in thumb
This is a refactor patch, that moves matching instructions adjusting
SP into a new function, thumb_instruction_restores_sp.  The second
call to thumb_instruction_restores_sp in thumb_in_function_epilogue_p
is a little different from the original.  The original code matches
'POP <registers> without PC', but thumb_in_function_epilogue_p matches
'POP <registers> (with and without PC)'.  However, GDB found one
instruction about return and is scanning the previous instruction,
which should be an instruction about return too, so the code change
doesn't affect the functionality.

gdb:

2014-07-11  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (thumb_instruction_restores_sp): New function.
	(thumb_in_function_epilogue_p): Call
	thumb_instruction_restores_sp.
2014-07-11 21:33:55 +08:00
Yao Qi 1db01f22f5 Restrict matching add/sub sp, #imm
Currently, GDB matches both add/sub sp, #imm in prologue and epilogue,
which is not very precise.  On the instruction level, the immediate
number in both instruction can't be negative, so 'sub sp, #imm' only
appears in prologue while 'add sp, #imm' only appears in epilogue.
Note that on assembly level, we can write 'add sp, -8', but gas will
translate to 'sub sp, 8' instruction.

This patch is to only match 'sub sp, #imm' in prologue and match
'add sp, #immm' in epilogue.  It paves the way for the following
patch.

gdb:

2014-07-11  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (thumb_analyze_prologue): Don't match instruction
	'add sp, #imm'.
	(thumb_in_function_epilogue_p): Don't match 'sub sp, #imm'.
2014-07-11 21:33:50 +08:00
Gary Benson 3116063bd6 Tidy #include lists
This commit tidies up the #include lists in {i386,amd64}-linux-nat.c,
removing headers that are no longer required and reordering some lines
so that both files roughly match.  Additionally, an unused definition
was removed from the middle of the #include list in i386-linux-nat.c.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (gdbcore.h): Remove include.
	(regset.h): Likewise.
	(nat/linux-btrace.h): Likewise.
	(btrace.h): Likewise.
	(gdb_assert.h): Likewise.
	(string.h): Likewise.
	(sys/uio.h): Likewise.
	(sys/debugreg.h): Likewise.
	(sys/syscall.h): Likewise.
	(sys/procfs.h): Likewise.
	(sys/user.h): Likewise.
	(asm/ptrace.h): Likewise.
	(i386-nat.h): Likewise.
	* i386-linux-nat.c (i386-nat.h): Likewise.
	(regset.h): Likewise.
	(target.h): Likewise.
	(linux-nat.h): Likewise.
	(nat/linux-btrace.h): Likewise.
	(btrace.h): Likewise.
	(gdb_assert.h): Likewise.
	(string.h): Likewise.
	(sys/uio.h): Likewise.
	(sys/user.h): Likewise.
	(sys/procfs.h): Likewise.
	(sys/reg.h): Likewise.
	(sys/debugreg.h): Likewise.
	(ORIG_EAX): Remove definition.
2014-07-11 12:24:28 +01:00
Gary Benson 040baaf6de Move duplicated code into new files
This commit moves the duplicated code in {i386,amd64}-linux-nat.c
into the new files x86-linux-nat.[ch].  Additionally, a new
file i386-linux-nat.h was required to expose a value required
by the 32-bit code in x86-linux-nat.c.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* i386-linux-nat.h: New file.
	* x86-linux-nat.h: Likewise.
	* x86-linux-nat.c: Likewise.
	* Makefile.in (HFILES_NO_SRCDIR): Add the above new headers.
	* config/i386/linux.mh (NATDEPFILES): Add x86-linux-nat.o.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* amd64-linux-nat.c (x86-linux-nat.h): New include.
	(PTRACE_GETREGSET): Now in x86-linux-nat.h.
	(PTRACE_SETREGSET): Likewise.
	(arch_lwp_info): Now in x86-linux-nat.c.
	(have_ptrace_getregset): Now in x86-linux-nat.h.
	(x86_linux_dr_get): Now in x86-linux-nat.c.
	(x86_linux_dr_set): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_prepare_to_resume): Likewise.
	(x86_linux_new_thread): Likewise.
	(x86_linux_new_fork): Likewise.
	(x86_linux_get_thread_area): Likewise.
	(super_post_startup_inferior): Likewise.
	(x86_linux_child_post_startup_inferior): Likewise.
	(AMD64_LINUX_USER64_CS): Likewise.
	(AMD64_LINUX_X32_DS): Likewise.
	(x86_linux_read_description): Likewise.
	(x86_linux_enable_btrace): Likewise.
	(x86_linux_disable_btrace): Likewise.
	(x86_linux_teardown_btrace): Likewise.
	(x86_linux_read_btrace): Likewise.
	(x86_linux_create_target): Likewise.
	(x86_linux_add_target): Likewise.
	* i386-linux-nat.c (x86-linux-nat.h): New include.
	(PTRACE_GETREGSET): Now in x86-linux-nat.h.
	(PTRACE_SETREGSET): Likewise.
	(arch_lwp_info): Now in x86-linux-nat.c.
	(have_ptrace_getregset): Now in x86-linux-nat.h.
	(x86_linux_dr_get): Now in x86-linux-nat.c.
	(x86_linux_dr_set): Likewise.
	(x86_linux_dr_get_addr): Likewise.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.
	(update_debug_registers_callback): Likewise.
	(x86_linux_dr_set_control): Likewise.
	(x86_linux_dr_set_addr): Likewise.
	(x86_linux_prepare_to_resume): Likewise.
	(x86_linux_new_thread): Likewise.
	(x86_linux_new_fork): Likewise.
	(x86_linux_get_thread_area): Likewise.
	(super_post_startup_inferior): Likewise.
	(x86_linux_child_post_startup_inferior): Likewise.
	(AMD64_LINUX_USER64_CS): Likewise.
	(AMD64_LINUX_X32_DS): Likewise.
	(x86_linux_read_description): Likewise.
	(x86_linux_enable_btrace): Likewise.
	(x86_linux_disable_btrace): Likewise.
	(x86_linux_teardown_btrace): Likewise.
	(x86_linux_read_btrace): Likewise.
	(x86_linux_create_target): Likewise.
	(x86_linux_add_target): Likewise.
2014-07-11 12:24:26 +01:00
Gary Benson 1aa7e42c3f Comment and whitespace changes
This commit merges the comments and whitespace in the common
parts of i386-linux-nat.c and amd64-linux-nat.c.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c: Comment and whitespace changes.
	* i386-linux-nat.c: Comment and whitespace changes.
2014-07-11 12:24:22 +01:00
Gary Benson c1e246a060 Pull out common parts of _initialize_{i386,amd64}_linux_nat
This commit adds two new helpers, x86_linux_create_target and
x86_linux_add_target, to hold the parts of _initialize_i386_linux_nat
and _initialize_amd64_linux_nat which are common.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (x86_linux_create_target): New function.
	(x86_linux_add_target): Likewise.
	(_initialize_amd64_linux_nat): Delegate to the above new functions.
	* i386-linux-nat.c (x86_linux_create_target): New function.
	(x86_linux_add_target): Likewise.
	(_initialize_i386_linux_nat): Delegate to the above new functions.
2014-07-11 12:24:11 +01:00
Gary Benson 8c420b8d59 Merge ps_get_thread_area
This commit adds a new helper, x86_linux_get_thread_area, to
hold the common parts of the ps_get_thread_area functions in
i386-linux-nat.c and amd64-linux-nat.c.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (x86_linux_get_thread_area): New function.
	(ps_get_thread_area): Delegate to the above in 32-bit mode.
	* i386-linux-nat.c (x86_linux_get_thread_area): New function.
	(ps_get_thread_area): Delegate to the above.
2014-07-11 12:23:16 +01:00
Gary Benson cb1da100b6 Merge {i386,amd64}_linux_read_description
This commit merges i386_ and amd64_linux_read_description, renaming
both to x86_linux_read_description.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (amd64_linux_read_description): Renamed to
	x86_linux_read_description.  All uses updated.  amd64-specific
	code conditionalized.  Conditionalized i386-specific code added.
	Redundant cast removed.
	* i386-linux-nat.c (i386_linux_read_description): Renamed to
	x86_linux_read_description.  All uses updated.  i386-specific
	code conditionalized.  Conditionalized amd64-specific code added.
	One sizeof replaced with the actual type it is describing.
2014-07-11 12:23:15 +01:00
Gary Benson 2acf3cd065 Rename identical functions
amd64-linux-nat.c and i386-linux-nat.c contain a number of functions
which are identical but for prefix on their names.  This commit
renames all such functions to have the prefix x86_ instead of the
prefixes amd64_ or i386_ and updates all uses of those functions.
The now-identical x86_ functions will be pulled out to a separate
shared file in a later commit.

gdb/
2014-07-11  Gary Benson  <gbenson@redhat.com>

	* amd64-linux-nat.c (amd64_linux_dr_get): Renamed to
	x86_linux_dr_get.  All uses updated.
	(amd64_linux_dr_set): Renamed to
	x86_linux_dr_set.  All uses updated.
	(amd64_linux_dr_get_addr): Renamed to
	x86_linux_dr_get_addr.  All uses updated.
	(amd64_linux_dr_get_control): Renamed to
	x86_linux_dr_get_control.  All uses updated.
	(amd64_linux_dr_get_status): Renamed to
	x86_linux_dr_get_status.  All uses updated.
	(amd64_linux_dr_set_control): Renamed to
	x86_linux_dr_set_control.  All uses updated.
	(amd64_linux_dr_set_addr): Renamed to
	x86_linux_dr_set_addr.  All uses updated.
	(amd64_linux_prepare_to_resume): Renamed to
	x86_linux_prepare_to_resume.  All uses updated.
	(amd64_linux_new_thread): Renamed to
	x86_linux_new_thread.  All uses updated.
	(amd64_linux_new_fork): Renamed to
	x86_linux_new_fork.  All uses updated.
	(amd64_linux_child_post_startup_inferior): Renamed to
	x86_linux_child_post_startup_inferior.  All uses updated.
	(amd64_linux_enable_btrace): Renamed to
	x86_linux_enable_btrace.  All uses updated.
	(amd64_linux_disable_btrace): Renamed to
	x86_linux_disable_btrace.  All uses updated.
	(amd64_linux_teardown_btrace): Renamed to
	x86_linux_teardown_btrace.  All uses updated.
	(amd64_linux_read_btrace): Renamed to
	x86_linux_read_btrace.  All uses updated.
	* i386-linux-nat.c (i386_linux_dr_get): Renamed to
	x86_linux_dr_get.  All uses updated.
	(i386_linux_dr_set): Renamed to
	x86_linux_dr_set.  All uses updated.
	(i386_linux_dr_get_addr): Renamed to
	x86_linux_dr_get_addr.  All uses updated.
	(i386_linux_dr_get_control): Renamed to
	x86_linux_dr_get_control.  All uses updated.
	(i386_linux_dr_get_status): Renamed to
	x86_linux_dr_get_status.  All uses updated.
	(i386_linux_dr_set_control): Renamed to
	x86_linux_dr_set_control.  All uses updated.
	(i386_linux_dr_set_addr): Renamed to
	x86_linux_dr_set_addr.  All uses updated.
	(i386_linux_prepare_to_resume): Renamed to
	x86_linux_prepare_to_resume.  All uses updated.
	(i386_linux_new_thread): Renamed to
	x86_linux_new_thread.  All uses updated.
	(i386_linux_new_fork): Renamed to
	x86_linux_new_fork.  All uses updated.
	(i386_linux_child_post_startup_inferior): Renamed to
	x86_linux_child_post_startup_inferior.  All uses updated.
	(i386_linux_enable_btrace): Renamed to
	x86_linux_enable_btrace.  All uses updated.
	(i386_linux_disable_btrace): Renamed to
	x86_linux_disable_btrace.  All uses updated.
	(i386_linux_teardown_btrace): Renamed to
	x86_linux_teardown_btrace.  All uses updated.
	(i386_linux_read_btrace): Renamed to
	x86_linux_read_btrace.  All uses updated.
2014-07-11 12:23:14 +01:00
Yao Qi 5401fde353 Don't print symbol on address 0x0
We see the following fails on arm-none-eabi target,

print (void*)v_signed_char^M
$190 = (void *) 0x0 <_ftext>^M
(gdb) FAIL: gdb.base/exprs.exp: print (void*)v_signed_char (print
(void*)v_signed_char)

GDB behaves correctly but the test assumes there is no symbol on
address 0x0.  This patch is set print symbol off, so that tests below
can match the address only.

gdb/testsuite:

2014-07-11  Yao Qi  <yao@codesourcery.com>

	* gdb.base/exprs.exp: "set print symbol off".
2014-07-11 19:05:50 +08:00
Pedro Alves e76126e8d1 GDBserver crashes when killing a multi-thread process
Here's an example, with the new test:

 gdbserver :9999 gdb.threads/kill
 gdb gdb.threads/kill
 (gdb) b 52
 Breakpoint 1 at 0x4007f4: file kill.c, line 52.
 Continuing.

 Breakpoint 1, main () at kill.c:52
 52        return 0; /* set break here */
 (gdb) k
 Kill the program being debugged? (y or n) y

 gdbserver :9999 gdb.threads/kill
 Process gdb.base/watch_thread_num created; pid = 9719
 Listening on port 1234
 Remote debugging from host 127.0.0.1
 Killing all inferiors
 Segmentation fault (core dumped)

Backtrace:

 (gdb) bt
 #0  0x00000000004068a0 in find_inferior (list=0x66b060 <all_threads>, func=0x427637 <kill_one_lwp_callback>, arg=0x7fffffffd3fc) at src/gdb/gdbserver/inferiors.c:199
 #1  0x00000000004277b6 in linux_kill (pid=15708) at src/gdb/gdbserver/linux-low.c:966
 #2  0x000000000041354d in kill_inferior (pid=15708) at src/gdb/gdbserver/target.c:163
 #3  0x00000000004107e9 in kill_inferior_callback (entry=0x6704f0) at src/gdb/gdbserver/server.c:2934
 #4  0x0000000000406522 in for_each_inferior (list=0x66b050 <all_processes>, action=0x4107a6 <kill_inferior_callback>) at src/gdb/gdbserver/inferiors.c:57
 #5  0x0000000000412377 in process_serial_event () at src/gdb/gdbserver/server.c:3767
 #6  0x000000000041267c in handle_serial_event (err=0, client_data=0x0) at src/gdb/gdbserver/server.c:3880
 #7  0x00000000004189ff in handle_file_event (event_file_desc=4) at src/gdb/gdbserver/event-loop.c:434
 #8  0x00000000004181c6 in process_event () at src/gdb/gdbserver/event-loop.c:189
 #9  0x0000000000418f45 in start_event_loop () at src/gdb/gdbserver/event-loop.c:552
 #10 0x0000000000411272 in main (argc=3, argv=0x7fffffffd8d8) at src/gdb/gdbserver/server.c:3283

The problem is that linux_wait_for_event deletes lwps that have exited
(even those not passed in as lwps of interest), while the lwp/thread
list is being walked on with find_inferior.  find_inferior can handle
the current iterated inferior being deleted, but not others.

When killing lwps, we don't really care about any of the pending
status handling of linux_wait_for_event.  We can just waitpid the lwps
directly, which is also what GDB does (see
linux-nat.c:kill_wait_callback).  This way the lwps are not deleted
while we're walking the list.  They'll be deleted by linux_mourn
afterwards.

This crash triggers several times when running the testsuite against
GDBserver with the native-gdbserver board (target remote), but as GDB
can't distinguish between GDBserver crashing and "kill" being
sucessful, as in both cases the connection is closed (the 'k' packet
doesn't require a reply), and the inferior is gone, that results in no
FAIL.

The patch adds a generic test that catches the issue with
extended-remote mode (and works fine with native testing too).  Here's
how it fails with the native-extended-gdbserver board without the fix:

 (gdb) info threads
   Id   Target Id         Frame
   6    Thread 15367.15374 0x000000373bcbc98d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
   5    Thread 15367.15373 0x000000373bcbc98d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
   4    Thread 15367.15372 0x000000373bcbc98d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
   3    Thread 15367.15371 0x000000373bcbc98d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
   2    Thread 15367.15370 0x000000373bcbc98d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
 * 1    Thread 15367.15367 main () at .../gdb.threads/kill.c:52
 (gdb) kill
 Kill the program being debugged? (y or n) y
 Remote connection closed
 ^^^^^^^^^^^^^^^^^^^^^^^^
 (gdb) FAIL: gdb.threads/kill.exp: kill

Extended remote should remain connected after the kill.

gdb/gdbserver/
2014-07-11  Pedro Alves  <palves@redhat.com>

	* linux-low.c (kill_wait_lwp): New function, based on
	kill_one_lwp_callback, but use my_waitpid directly.
	(kill_one_lwp_callback, linux_kill): Use it.

gdb/testsuite/
2014-07-11  Pedro Alves  <palves@redhat.com>

	* gdb.threads/kill.c: New file.
	* gdb.threads/kill.exp: New file.
2014-07-11 11:07:13 +01:00
Adrian Sendroiu b9c1d481cc remote: call remote_check_symbols after attaching
When debugging a remote bare-metal target with "target
extended-remote" + attach, GDB won't send a qSymbol packet to initiate
symbol lookup.  This happens because all the previous places in which
GDB might have done this are guarded by conditions that don't hold in
the said scenario: there are no shared libraries, no vsyscall page and
the binary file didn't change in the time passed between the "file"
and the "attach" commands.

To solve this problem remote_check_symbols is called in the
target_post_attach hook.

gdb/
2014-07-11  Adrian Sendroiu  <adrian.sendroiu@freescale.com>

	* remote.c (extended_remote_post_attach): New function.
	(init_extended_remote_ops): Install it as to_post_attach method.
2014-07-11 10:51:48 +01:00
Doug Evans e86c23a851 Revert gdbthread.h (any_running): Declare.
Not properly marked as 1/2.
This reverts commit 1a76d59888.
2014-07-10 12:30:05 -07:00
Doug Evans 1a76d59888 * gdbthread.h (any_running): Declare.
* thread.c (any_running): New function.
2014-07-10 11:15:32 -07:00
Yao Qi 2d6f0de676 Tweak gdb.trace/tfile.c for thumb mode
We see the fail below happens on thumb related multi-libs
(-mthumb -march={armv4t,armv7-a}),

target tfile tfile-basic.tf ^M
warning: Uploaded tracepoint 1 has no source location, using raw address^M
warning: Breakpoint address adjusted from 0x00008959 to 0x00008958.^M
Tracepoint 3 at 0x8958: file /scratch/yqi/arm-none-linux-gnueabi/src/gdb-trunk/gdb/testsuite/gdb.trace/tfile.c, line 91.^M
Created tracepoint 3 for target's tracepoint 1 at 0x8959.^M
warning: Breakpoint address adjusted from 0x00008959 to 0x00008958.^M
warning: Breakpoint address adjusted from 0x00008959 to 0x00008958.^M
warning: Breakpoint address adjusted from 0x00008959 to 0x00008958.^M
(gdb) FAIL: gdb.trace/tfile.exp: complete-command 'target tfile'

The address of write_basic_trace_file is two-bytes aligned,

(gdb) p write_basic_trace_file
$1 = {void (void)} 0x8958 <write_basic_trace_file>

but the ld sets the LSB of every reference to the function address
(indicating the address is in thumb mode), so "&write_basic_trace_file"
in the program becomes 0x8959, which is saved in the trace file.  That
is why the warnnings are emitted.

This patch is to clear the LSB of the function address written to trace
file in thumb and thumb2 mode.  This patch fixes the fail above.

gdb/testsuite:

2014-07-10  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/tfile.c (write_basic_trace_file)
	[__thumb__||__thumb2__]: Clear the Thumb bit of the function
	address written to trace file.
2014-07-10 09:02:01 +08:00
Pedro Alves 7180e04a36 Fix "attach" command vs user input race
On async targets, a synchronous attach is done like this:

   #1 - target_attach is called (PTRACE_ATTACH is issued)
   #2 - a continuation is installed
   #3 - we go back to the event loop
   #4 - target reports stop (SIGSTOP), event loop wakes up, and
        attach continuation is called
   #5 - among other things, the continuation calls
        target_terminal_inferior, which removes stdin from the event
        loop

Note that in #3, GDB is still processing user input.  If the user is
fast enough, e.g., with something like:

  echo -e "attach PID\nset xxx=1" | gdb

... then the "set" command is processed before the attach completes.

We get worse behavior even, if input is a tty and therefore
readline/editing is enabled, with e.g.,:

 (gdb) attach PID\nset xxx=1

we then crash readline/gdb, with:

 Attaching to program: attach-wait-input, process 14537
 readline: readline_callback_read_char() called with no handler!
 Aborted
 $

Fix this by calling target_terminal_inferior before #3 above.

The test covers both scenarios by running with editing/readline forced
to both on and off.

gdb/
2014-07-09  Pedro Alves  <palves@redhat.com>

	* infcmd.c (attach_command_post_wait): Don't call
	target_terminal_inferior here.
	(attach_command): Call it here instead.

gdb/testsuite/
2014-07-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/attach-wait-input.exp: New file.
	* gdb.base/attach-wait-input.c: New file.
2014-07-09 15:59:02 +01:00
Andrew Burgess 9a9a760829 Improve MI -var-info-path-expression for nested struct/union case.
https://sourceware.org/ml/gdb-patches/2014-05/msg00383.html

The MI command -var-info-path-expression currently does not handle
non-anonymous structs / unions nested within other structs / unions,
it will skip parts of the expression.  Consider this example:

  ## START EXAMPLE ##
  $ cat ex.c
  #include <string.h>

  int
  main ()
  {
    struct s1
    {
      int a;
    };

    struct ss
    {
      struct s1 x;
    };

    struct ss an_ss;
    memset (&an_ss, 0, sizeof (an_ss));
    return 0;
  }
  $ gcc -g -o ex.x ex.c
  $ gdb ex.x
  (gdb) break 18
  Breakpoint 1 at 0x80483ba: file ex.c, line 18.
  (gdb) run
  Starting program: /home/user/ex.x

  Breakpoint 1, main () at ex.c:18
  18	  return 0;
  (gdb) interpreter-exec mi "-var-create an_ss * an_ss"
  (gdb) interpreter-exec mi "-var-list-children an_ss"
  ^done,numchild="1",children=[child={name="an_ss.x",exp="x",numchild="1",type="struct s1",thread-id="1"}],has_more="0"
  (gdb) interpreter-exec mi "-var-list-children an_ss.x"
  ^done,numchild="1",children=[child={name="an_ss.x.a",exp="a",numchild="0",type="int",thread-id="1"}],has_more="0"
  (gdb) interpreter-exec mi "-var-list-children an_ss.x.a"
  ^done,numchild="0",has_more="0"
  (gdb) interpreter-exec mi "-var-info-path-expression an_ss.x.a"
  ^done,path_expr="(an_ss).a"
  (gdb) print (an_ss).a
  There is no member named a.
  ## END EXAMPLE ##

Notice that the path expression returned is wrong, and as a result
the print command fails.

This patch adds a new method to the varobj_ops structure called
is_path_expr_parent, to allow language specific control over finding
the parent varobj, the current logic becomes the C/C++ version and is
extended to handle the nested cases.  No other language currently uses
this code, so all other languages just get a default method.

With this patch, the above example now finishes like this:

  ## START EXAMPLE ##
  $ gdb ex.x
  (gdb) break 18
  Breakpoint 1 at 0x80483ba: file ex.c, line 18.
  (gdb) run
  Starting program: /home/user/ex.x

  Breakpoint 1, main () at ex.c:18
  18	  return 0;
  (gdb) interpreter-exec mi "-var-list-children an_ss"
  ^done,numchild="1",children=[child={name="an_ss.x",exp="x",numchild="1",type="struct s1",thread-id="1"}],has_more="0"
  (gdb) interpreter-exec mi "-var-list-children an_ss.x"
  ^done,numchild="1",children=[child={name="an_ss.x.a",exp="a",numchild="0",type="int",thread-id="1"}],has_more="0"
  (gdb) interpreter-exec mi "-var-list-children an_ss.x.a"
  ^done,numchild="0",has_more="0"
  (gdb) interpreter-exec mi "-var-info-path-expression an_ss.x.a"
  ^done,path_expr="((an_ss).x).a"
  (gdb) print ((an_ss).x).a
  $1 = 0
  ## END EXAMPLE ##

Notice that the path expression is now correct, and the print is a
success.

gdb/ChangeLog:

	* ada-varobj.c (ada_varobj_ops): Fill in is_path_expr_parent
	field.
	* c-varobj.c (c_is_path_expr_parent): New function, moved core
	from varobj.c, with additional checks.
	(c_varobj_ops): Fill in is_path_expr_parent field.
	(cplus_varobj_ops): Fill in is_path_expr_parent field.
	* jv-varobj.c (java_varobj_ops): Fill in is_path_expr_parent
	field.
	* varobj.c (is_path_expr_parent): Call is_path_expr_parent varobj
	ops method.
	(varobj_default_is_path_expr_parent): New function.
	* varobj.h (lang_varobj_ops): Add is_path_expr_parent field.
	(varobj_default_is_path_expr_parent): Declare new function.

gdb/testsuite/ChangeLog:

	* gdb.mi/var-cmd.c (do_nested_struct_union_tests): New function
	setting up test structures.
	(main): Call new test function.
	* gdb.mi/mi2-var-child.exp: Create additional breakpoint in new
	test function, continue into test function and walk test
	structures.
2014-07-09 14:47:47 +01:00
Yao Qi 161ac41e03 Fix gdb.trace/entry-values.exp for thumb mode
We see some fails in gdb.trace/entry-values.exp in thumb mode
(-mthumb -march={armv4t,armv7-a}).

In thumb mode, the lsb of references to 'foo' and 'bar' in the assembly
(produced by dwarf assember) is set, so the generated debug
information is incorrect.

This patch copies the approach used by

  [PATCH 4/4] Fix dw2-ifort-parameter.exp on PPC64
  https://sourceware.org/ml/gdb-patches/2014-03/msg00202.html

to introduce new labels 'foo_start' and 'bar_start' which are about
the correct function address (without lsb set).  This patch fixes
these fails we've seen.

gdb/testsuite:

2014-07-08  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/entry-values.c: Define labels 'foo_start' and
	'bar_start' at the beginning of functions 'foo' and 'bar'
	respectively.
	* gdb.trace/entry-values.exp: Use 'foo_start' and 'bar_start'
	instead of 'foo' and 'bar'.
2014-07-08 16:48:22 +08:00
Markus Metzger 1f267ae3d1 reverse-finish: turn internal error into normal error
The reverse-finish command results in an internal error if it cannot determine
the current function.

  (gdb) c
  Continuing.

  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000000000 in ?? ()
  (gdb) reverse-finish
  Run back to call of #0  0x0000000000000000 in ?? ()
  gdb/infcmd.c:1576: internal-error: Finish: couldn't find function.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n) y

This is not an internal error case since the command may be used in scenarios
where there is no function at the current PC, e.g. after calling through a bad
function pointer.

Turn this into a normal error.

gdb/
	* infcmd.c (finish_backward): Turn internal error into normal error.

testsuite/
	* gdb.btrace/segv.c: New.
	* gdb.btrace/segv.exp: New.
2014-07-08 10:07:59 +02:00