Commit Graph

24 Commits

Author SHA1 Message Date
Pedro Alves 7ae1a6a6cc PR server/16255: gdbserver cannot attach to a second inferior that is multi-threaded.
On Linux, we need to explicitly ptrace attach to all lwps of a
process.  Because GDB might not be connected yet when an attach is
requested, and thus it may not be possible to activate thread_db, as
that requires access to symbols (IOW, gdbserver --attach), a while ago
we make linux_attach loop over the lwps as listed by /proc/PID/task to
find the lwps to attach to.

linux_attach_lwp_1 has:

...
  if (initial)
    /* If lwp is the tgid, we handle adding existing threads later.
       Otherwise we just add lwp without bothering about any other
       threads.  */
    ptid = ptid_build (lwpid, lwpid, 0);
  else
    {
      /* Note that extracting the pid from the current inferior is
	 safe, since we're always called in the context of the same
	 process as this new thread.  */
      int pid = pid_of (current_inferior);
      ptid = ptid_build (pid, lwpid, 0);
    }

That "safe" comment referred to linux_attach_lwp being called by
thread-db.c.  But this was clearly missed when a new call to
linux_attach_lwp_1 was added to linux_attach.  As a result,
current_inferior will be set to some random process, and non-initial
lwps of the second inferior get assigned the pid of the wrong
inferior.  E.g., in the case of attaching to two inferiors, for the
second inferior (and so on), non-initial lwps of the second inferior
get assigned the pid of the first inferior.  This doesn't trigger on
the first inferior, when current_inferior is NULL, add_thread switches
the current inferior to the newly added thread.

Rather than making linux_attach switch current_inferior temporarily
(thus avoiding further reliance on global state), or making
linux_attach_lwp_1 get the tgid from /proc, which add extra syscalls,
and will be wrong in case of the user having originally attached
directly to a non-tgid lwp, and then that lwp spawning new clones (the
ptid.pid field of further new clones should be the same as the
original lwp's pid, which is not the tgid), we note that callers of
linux_attach_lwp/linux_attach_lwp_1 always have the right pid handy
already, so they can pass it down along with the lwpid.

The only other reason for the "initial" parameter is to error out
instead of warn in case of attach failure, when we're first attaching
to a process.  There are only three callers of
linux_attach_lwp/linux_attach_lwp_1, and each wants to print a
different warn/error string, so we can just move the error/warn out of
linux_attach_lwp_1 to the callers, thus getting rid of the "initial"
parameter.

There really nothing gdbserver-specific about attaching to two
threaded processes, so this adds a new test under gdb.multi/.  The
test passes cleanly against the native GNU/Linux target, but
fails/triggers the bug against GDBserver (before the patch), with the
native-extended-remote board (as plain remote doesn't support
multi-process).

Tested on x86_64 Fedora 17, with the native-extended-gdbserver board.

gdb/gdbserver/
2014-04-25  Pedro Alves  <palves@redhat.com>

	PR server/16255
	* linux-low.c (linux_attach_fail_reason_string): New function.
	(linux_attach_lwp): Delete.
	(linux_attach_lwp_1): Rename to ...
	(linux_attach_lwp): ... this.  Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach): Adjust to call linux_attach_lwp.  Call error on
	failure to attach to the tgid.  Call warning when failing to
	attach to an lwp.
	* linux-low.h (linux_attach_lwp): Take a ptid instead of a pid as
	argument.  Remove "initial" parameter.  Return int instead of
	void.  Don't error or warn here.
	(linux_attach_fail_reason_string): New declaration.
	* thread-db.c (attach_thread): Adjust to linux_attach_lwp's
	interface change.  Use linux_attach_fail_reason_string.

gdb/
2014-04-25  Pedro Alves  <palves@redhat.com>

	PR server/16255
	* common/linux-ptrace.c (linux_ptrace_attach_warnings): Rename to ...
	(linux_ptrace_attach_fail_reason): ... this.  Remove "warning: "
	and newline from built string.
	* common/linux-ptrace.h (linux_ptrace_attach_warnings): Rename to ...
	(linux_ptrace_attach_fail_reason): ... this.
	* linux-nat.c (linux_nat_attach): Adjust to use
	linux_ptrace_attach_fail_reason.

gdb/testsuite/
2014-04-25  Simon Marchi  <simon.marchi@ericsson.com>
	    Pedro Alves  <palves@redhat.com>

	PR server/16255
	* gdb.multi/multi-attach.c: New file.
	* gdb.multi/multi-attach.exp: New file.
2014-04-25 19:07:33 +01:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Tom Tromey 08c430507d fix multi-arch-exec for parallel mode
I noticed today that multi-arch-exec.exp was failing in parallel mode.

The bug is that multi-arch-exec.c assumes the non-parallel directory
layout.

This patch fixes the problem using the same "BASEDIR" approach used in
other tests.

Tested both ways on x86-64 Fedora 18.
I'm checking this in.

2013-11-13  Tom Tromey  <tromey@redhat.com>

	* gdb.multi/multi-arch-exec.exp: Define BASEDIR when compiling.
	* gdb.multi/multi-arch-exec.c (main): Use BASEDIR.
2013-11-13 10:01:25 -07:00
Tom Tromey 3fef966c5f fix some "exec" tests
A few tests run an inferior that execs some other program.  The name
of this exec'd program is compiled in.  These tests assume the current
test suite directory layout, but fail in parallel mode.

This patch fixes these tests by letting the .exp files pass in the
directory names at compile time.

2013-11-04  Tom Tromey  <tromey@redhat.com>

	* gdb.base/foll-exec.c (main): Use BASEDIR.
	* gdb.base/foll-exec.exp: Define BASEDIR during compilation.
	* gdb.base/foll-vfork.c (main): Use BASEDIR.
	* gdb.base/foll-vfork.exp: Define BASEDIR during compilation.
	* gdb.multi/bkpt-multi-exec.c (main): Use BASEDIR.
	* gdb.multi/bkpt-multi-exec.exp: Define BASEDIR during compilation.
2013-11-04 11:02:10 -07:00
Joel Brobecker 8acc9f485b Update years in copyright notice for the GDB files.
Two modifications:
  1. The addition of 2013 to the copyright year range for every file;
  2. The use of a single year range, instead of potentially multiple
     year ranges, as approved by the FSF.
2013-01-01 06:41:43 +00:00
Doug Evans 4e3f5ae6b7 Enable accidentally commented out code. 2012-12-17 19:40:24 +00:00
Doug Evans e780d813de * gdb.multi/multi-arch-exec.exp: Skip for i*86-linux.
* gdb.multi/multi-arch.exp: Ditto.
2012-12-13 20:40:33 +00:00
Pedro Alves 9107fc8d18 2012-11-09 Pedro Alves <palves@redhat.com>
PR gdb/14306

	* infrun.c: Include target-descriptions.h.
	(follow_exec): Fetch new target description.

gdb/testsuite/
2012-11-09  Pedro Alves  <palves@redhat.com>

	PR gdb/14306

	* gdb.multi/multi-arch-exec.c: New file.
	* gdb.multi/multi-arch-exec.exp: New file.
2012-11-09 12:20:24 +00:00
Pedro Alves 6ecd47299a gdb/
2012-11-09  Pedro Alves  <palves@redhat.com>

	* gdbarch.sh (target_gdbarch) <gdbarch.h>: Reimplement as macro.
	(get_target_gdbarch) <gdbarch.h>: New function.
	(startup_gdbarch) <gdbarch.h>: Declare.
	<gdbarch.c> (target_gdbarch): Delete.
	<gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the
	current inferior's gdbarch.
	<gdbarch.c> (get_target_gdbarch): New function.
	* inferior.c: Include target-descriptions.h.
	(free_inferior): Free target description info.
	(add_inferior_with_spaces): Set the inferior's initial
	architecture.
	(clone_inferior_command): Copy the original inferior's target
	description if it was user specified.
	(initialize_inferiors): Add comment.
	* inferior.h (struct target_desc_info): Forward declare.
	(struct inferior) <gdbarch>: New field.
	* linux-nat.c: Include target-descriptions.h.
	(linux_child_follow_fork): Copy the parent's architecture and
	target description to the child.
	* target-descriptions.c: Include inferior.h.
	(struct target_desc_info): New structure, holding the equivalents
	of ...
	(target_desc_fetched, current_target_desc)
	(target_description_filename): ... these removed globals.
	(get_tdesc_info, target_desc_info_from_user_p)
	(copy_inferior_target_desc_info, target_desc_info_free): New.
	(target_desc_fetched, current_target_desc)
	(target_description_filename): Reimplemented as convenience
	macros.
	(tdesc_filename_cmd_string): New global.
	(set_tdesc_filename_cmd): Copy the string manipulated by the "set
	tdescs filename ..." commands to the per-inferior equivalent.
	(show_tdesc_filename_cmd): Get the value to show from the
	per-inferior description filename.
	(_initilize_target_descriptions): Change the "set/show tdesc
	filename" commands' variable.
	* target-descriptions.h (struct target_desc, struct target_desc_info)
	(struct inferior): Forward declare.
	(target_find_description, target_clear_description)
	(target_current_description): Adjust comments.
	(copy_inferior_target_desc_info, target_desc_info_free)
	(target_desc_info_from_user_p). Declare.

gdb/testsuite/
2012-11-09  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-arch.exp: New.
2012-11-09 01:47:20 +00:00
Tom Tromey 7bb18ae2ad * gdb.multi/watchpoint-multi.exp: Use standard_testfile.
* gdb.multi/bkpt-multi-exec.exp: Use standard_output_file.  Use
	build_executable, not prepare_for_testing.
	* gdb.multi/base.exp: Use standard_output_file.  Use
	build_executable,  not prepare_for_testing.
2012-06-25 21:07:32 +00:00
Doug Evans 957df313b7 * Makefile.in (clean): Remove Fission .dwo and .dwp files.
* gdb.ada/Makefile.in (clean): Ditto.
	* gdb.arch/Makefile.in (clean): Ditto.
	* gdb.asm/Makefile.in (clean): Ditto.
	* gdb.base/Makefile.in (clean): Ditto.
	* gdb.cell/Makefile.in (clean): Ditto.
	* gdb.cp/Makefile.in (clean): Ditto.
	* gdb.disasm/Makefile.in (clean): Ditto.
	* gdb.dwarf2/Makefile.in (clean): Ditto.
	* gdb.fortran/Makefile.in (clean): Ditto.
	* gdb.go/Makefile.in (clean): Ditto.
	* gdb.hp/Makefile.in (clean): Ditto.
	* gdb.hp/gdb.aCC/Makefile.in (clean): Ditto.
	* gdb.hp/gdb.base-hp/Makefile.in (clean): Ditto.
	* gdb.hp/gdb.compat/Makefile.in (clean): Ditto.
	* gdb.hp/gdb.defects/Makefile.in (clean): Ditto.
	* gdb.hp/gdb.objdbg/Makefile.in (clean): Ditto.
	* gdb.java/Makefile.in (clean): Ditto.
	* gdb.linespec/Makefile.in (clean): Ditto.
	* gdb.mi/Makefile.in (clean): Ditto.
	* gdb.modula2/Makefile.in (clean): Ditto.
	* gdb.multi/Makefile.in (clean): Ditto.
	* gdb.objc/Makefile.in (clean): Ditto.
	* gdb.opencl/Makefile.in (clean): Ditto.
	* gdb.opt/Makefile.in (clean): Ditto.
	* gdb.pascal/Makefile.in (clean): Ditto.
	* gdb.python/Makefile.in (clean): Ditto.
	* gdb.reverse/Makefile.in (clean): Ditto.
	* gdb.server/Makefile.in (clean): Ditto.
	* gdb.stabs/Makefile.in (clean): Ditto.
	* gdb.threads/Makefile.in (clean): Ditto.
	* gdb.trace/Makefile.in (clean): Ditto.
	* gdb.xml/Makefile.in (clean): Ditto.
2012-05-17 19:03:59 +00:00
Yao Qi 2d4e03767f gdb/testsuite:
* gdb.base/catch-syscall.exp: Skip it before compilation if target
	doesn't support.
	* gdb.base/foll-exec.exp, gdb.base/foll-fork.exp: Likewise.
	* gdb.base/foll-vfork.exp, gdb.multi/bkpt-multi-exec.exp: Likewise.
2012-05-03 02:05:15 +00:00
Pedro Alves 3d7f4b8126 2012-01-26 Pedro Alves <palves@redhat.com>
Make test messages unique, and more identifiable.
	* gdb.multi/watchpoint-multi.exp: Change test messages.
2012-01-26 10:09:43 +00:00
Jan Kratochvil d0d8b0c667 gdb/
Fix watchpoints to be specific for each inferior.
	* breakpoint.c (watchpoint_in_thread_scope): Verify also
	current_program_space.
	* i386-nat.c (i386_inferior_data_cleanup): New.
	(i386_inferior_data_get): Replace variable inf_data_local by an
	inferior_data call.
	(i386_use_watchpoints): Initialize i386_inferior_data.
	* linux-nat.c (linux_nat_iterate_watchpoint_lwps): Use INFERIOR_PTID
	specific iterate_over_lwps.

gdb/testsuite/
	Fix watchpoints to be specific for each inferior.
	* gdb.multi/watchpoint-multi.c: New file.
	* gdb.multi/watchpoint-multi.exp: New file.
2012-01-24 13:49:58 +00:00
Joel Brobecker 0b30217134 Copyright year update in most files of the GDB Project.
gdb/ChangeLog:

        Copyright year update in most files of the GDB Project.
2012-01-04 08:17:56 +00:00
Michael Snyder af62414197 2011-02-25 Michael Snyder <msnyder@vmware.com>
* inferior.c (detach_inferior_command): Use get_number_or_range.
	(kill_inferior_command): Ditto.
	(remove_inferior_command): Ditto.
	(initialize_inferiors): Make command names plural.
	Update help strings.

2011-02-25  Michael Snyder  <msnyder@vmware.com>

	* gdb.texinfo (Inferiors and Programs): Update commands to show
	that they can accept multiple arguments.

2011-02-25  Michael Snyder  <msnyder@vmware.com>

	* gdb.multi/base.exp: Add test for remove-inferiors.
2011-02-27 20:49:27 +00:00
Michael Snyder c82c0b55e7 2011-02-25 Michael Snyder <msnyder@vmware.com>
* inferior.c (print_inferior): Accept a string instead of an int
	for requested_inferiors, and use get_number_or_range to parse it.
	(info_inferiors_command): Pass args string to print_inferior.
	(initialize_inferiors): Change help string for info inferiors.
	* inferior.h (print_inferior): Export prototype change.

2011-02-25  Michael Snyder  <msnyder@vmware.com>

	* gdb.multi/base.exp: Add tests for info inferiors with args.
2011-02-25 19:19:26 +00:00
Michael Snyder 1d41d745ca 2011-02-22 Michael Snyder <msnyder@vmware.com>
* Makefile.in: Make more clean.
	* gdb.ada/Makefile.in: Ditto.
	* gdb.arch/Makefile.in: Ditto.
	* gdb.asm/Makefile.in: Ditto.
	* gdb.base/Makefile.in: Ditto.
	* gdb.cp/Makefile.in: Ditto.
	* gdb.dwarf2/Makefile.in: Ditto.
	* gdb.java/Makefile.in: Ditto.
	* gdb.mi/Makefile.in: Ditto.
	* gdb.modula2/Makefile.in: Ditto.
	* gdb.python/Makefile.in: Ditto.
	* gdb.server/Makefile.in: Ditto.
	* gdb.stabs/Makefile.in: Ditto.
	* gdb.threads/Makefile.in: Ditto.
	* gdb.trace/Makefile.in: Ditto.
2011-02-22 20:52:49 +00:00
Joel Brobecker 7b6bb8daac run copyright.sh for 2011. 2011-01-01 15:34:07 +00:00
Pedro Alves d8053d4d67 * gdb.multi/base.exp, gdb.multi/bkpt-multi-exec.exp: Use
clean_restart, make sure every test has a distinct message, and
	that messages don't include the executable' full path.
2010-06-18 15:08:29 +00:00
Michael Snyder f6978de9f5 2010-06-08 Michael Snyder <msnyder@vmware.com>
* gdb.ada/assign_1.exp: Use ".*" instead of "" as wildcard regexp.
	* gdb.ada/boolean_expr.exp:
	* gdb.ada/frame_args.exp: Ditto.
	* gdb.ada/lang_switch.exp: Ditto.
	* gdb.ada/ptype_arith_binop.exp: Ditto.
	* gdb.ada/ref_param.exp: Ditto.
	* gdb.ada/type_coercion.exp:Ditto.

	* gdb.asm/asm-source.exp: Ditto.

	* gdb.base/attach.exp: Ditto.
	* gdb.base/bitfields2.exp: Ditto.
	* gdb.base/call-signal-resume.exp: Ditto.
	* gdb.base/callfuncs.exp: Ditto.
	* gdb.base/commands.exp: Ditto.
	* gdb.base/dbx.exp: Ditto.
	* gdb.base/default.exp: Ditto.
	* gdb.base/dump.exp: Ditto.
	* gdb.base/exprs.exp: Ditto.
	* gdb.base/freebpcmd.exp: Ditto.
	* gdb.base/interrupt.exp: Ditto.
	* gdb.base/list.exp: Ditto.
	* gdb.base/long_long.exp: Ditto.
	* gdb.base/maint.exp: Ditto.
	* gdb.base/ptype.exp: Ditto.
	* gdb.base/return.exp: Ditto.
	* gdb.base/setshow.exp: Ditto.
	* gdb.base/sigbpt.exp: Ditto.
	* gdb.base/sigrepeat.exp: Ditto.

	* gdb.cp/classes.exp: Ditto.

	* gdb.dwarf2/dw2-restore.exp: Ditto.

	* gdb.gdb/selftest.exp: Ditto.

	* gdb.multi/base.exp: Ditto.
	* gdb.multi/bkpt-multi-exec.exp: Ditto.

	* gdb.python/py-block.exp: Ditto.
	* gdb.python/py-prettyprint.exp: Ditto.
	* gdb.python/py-template.exp: Ditto.

	* gdb.server/ext-attach.exp: Ditto.
	* gdb.server/ext-run.exp: Ditto.
	* gdb.server/server-mon.exp: Ditto.

	* gdb.threads/fork-thread-pending.exp: Ditto.
	* gdb.threads/hand-call-in-threads.exp: Ditto.
	* gdb.threads/interrupted-hand-call.exp: Ditto.
	* gdb.threads/linux-dp.exp: Ditto.
	* gdb.threads/manythreads.exp: Ditto.
	* gdb.threads/print-threads.exp: Ditto.
	* gdb.threads/pthreads.exp: Ditto.
	* gdb.threads/schedlock.exp: Ditto.
	* gdb.threads/thread-unwindonsignal.exp: Ditto.
	* gdb.threads/threadapply.exp: Ditto.
2010-06-10 19:48:20 +00:00
Michael Snyder 019ebafccd 2010-06-02 Michael Snyder <msnyder@vmware.com>
* gdb.dwarf2/dw2-basic.exp: Use gdb_test_no_output.
	* gdb.dwarf2/dw2-compressed.exp: Ditto.
	* gdb.dwarf2/dw2-intercu.exp: Ditto.
	* gdb.dwarf2/dw2-intermix.exp: Ditto.
	* gdb.dwarf2/dw2-producer.exp: Ditto.
	* gdb.dwarf2/mac-fileno.exp: Ditto.

	* gdb.gdb/observer.exp: Use gdb_test_no_output.
	* gdb.gdb/selftest.exp: Ditto.

	* gdb.multi/base.exp: Use gdb_test_no_output.

	* gdb.opt/inline-cmds.exp: Use gdb_test_no_output.
2010-06-02 21:46:45 +00:00
Joel Brobecker 4c38e0a4fc Update copyright year in most headers.
Automatic update by copyright.sh.
2010-01-01 07:32:07 +00:00
Pedro Alves b321dd9007 Adding files to HEAD that cvs had declared dead due to existing on
the branch only.

       gdb/testsuite/
	* gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork".
	* gdb.base/foll-exec.exp: Adjust to expect a process id before
	"Executing new program".
	* gdb.base/foll-fork.exp: Adjust to spell out "follow-fork".
	* gdb.base/multi-forks.exp: Ditto.  Adjust to the inferior being
	left listed after having been killed.
	* gdb.base/attach.exp: Adjust to spell out "symbol-file".
	* gdb.base/maint.exp: Adjust test.

	* Makefile.in (ALL_SUBDIRS): Add gdb.multi.
	* gdb.multi/Makefile.in: New.
	* gdb.multi/base.exp: New.
	* gdb.multi/goodbye.c: New.
	* gdb.multi/hangout.c: New.
	* gdb.multi/hello.c: New.
	* gdb.multi/bkpt-multi-exec.c: New.
	* gdb.multi/bkpt-multi-exec.exp: New.
	* gdb.multi/crashme.c: New.
2009-10-19 09:56:34 +00:00