binutils-gdb/gdb/linux-nat.c

5027 lines
139 KiB
C
Raw Normal View History

/* GNU/Linux native-dependent code common to multiple platforms.
Copyright (C) 2001-2017 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "inferior.h"
Add new infrun.h header. Move infrun.c declarations out of inferior.h to a new infrun.h file. Tested by building on: i686-w64-mingw32, enable-targets=all x86_64-linux, enable-targets=all i586-pc-msdosdjgpp And also grepped the whole tree for each symbol moved to find where infrun.h might be necessary. gdb/ 2014-05-22 Pedro Alves <palves@redhat.com> * inferior.h (debug_infrun, debug_displaced, stop_on_solib_events) (sync_execution, sched_multi, step_stop_if_no_debug, non_stop) (disable_randomization, enum exec_direction_kind) (execution_direction, stop_registers, start_remote) (clear_proceed_status, proceed, resume, user_visible_resume_ptid) (wait_for_inferior, normal_stop, get_last_target_status) (prepare_for_detach, fetch_inferior_event, init_wait_for_inferior) (insert_step_resume_breakpoint_at_sal) (follow_inferior_reset_breakpoints, stepping_past_instruction_at) (set_step_info, print_stop_event, signal_stop_state) (signal_print_state, signal_pass_state, signal_stop_update) (signal_print_update, signal_pass_update) (update_signals_program_target, clear_exit_convenience_vars) (displaced_step_dump_bytes, update_observer_mode) (signal_catch_update, gdb_signal_from_command): Move declarations ... * infrun.h: ... to this new file. * amd64-tdep.c: Include infrun.h. * annotate.c: Include infrun.h. * arch-utils.c: Include infrun.h. * arm-linux-tdep.c: Include infrun.h. * arm-tdep.c: Include infrun.h. * break-catch-sig.c: Include infrun.h. * breakpoint.c: Include infrun.h. * common/agent.c: Include infrun.h instead of inferior.h. * corelow.c: Include infrun.h. * event-top.c: Include infrun.h. * go32-nat.c: Include infrun.h. * i386-tdep.c: Include infrun.h. * inf-loop.c: Include infrun.h. * infcall.c: Include infrun.h. * infcmd.c: Include infrun.h. * infrun.c: Include infrun.h. * linux-fork.c: Include infrun.h. * linux-nat.c: Include infrun.h. * linux-thread-db.c: Include infrun.h. * monitor.c: Include infrun.h. * nto-tdep.c: Include infrun.h. * procfs.c: Include infrun.h. * record-btrace.c: Include infrun.h. * record-full.c: Include infrun.h. * remote-m32r-sdi.c: Include infrun.h. * remote-mips.c: Include infrun.h. * remote-notif.c: Include infrun.h. * remote-sim.c: Include infrun.h. * remote.c: Include infrun.h. * reverse.c: Include infrun.h. * rs6000-tdep.c: Include infrun.h. * s390-linux-tdep.c: Include infrun.h. * solib-irix.c: Include infrun.h. * solib-osf.c: Include infrun.h. * solib-svr4.c: Include infrun.h. * target.c: Include infrun.h. * top.c: Include infrun.h. * windows-nat.c: Include infrun.h. * mi/mi-interp.c: Include infrun.h. * mi/mi-main.c: Include infrun.h. * python/py-threadevent.c: Include infrun.h.
2014-05-22 13:29:11 +02:00
#include "infrun.h"
#include "target.h"
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
#include "nat/linux-nat.h"
#include "nat/linux-waitpid.h"
#include "gdb_wait.h"
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
#include <unistd.h>
#include <sys/syscall.h>
#include "nat/gdb_ptrace.h"
#include "linux-nat.h"
Move shared native target specific code to gdb/nat https://sourceware.org/gdb/wiki/Common describes the following directory structure: gdb/nat/ Native target backend files. Code that interfaces with the host debug API. E.g., ptrace code, Windows debug API code, procfs code should go here. gdb/target/ Host-independent, target vector specific code (target_ops). gdb/common/ All other shared code. This commit moves all native target backend files currently in gdb/common to gdb/nat. gdb/ 2014-06-20 Gary Benson <gbenson@redhat.com> * common/gdb_thread_db.h: Moved to nat. All includes updated. * common/glibc_thread_db.h: Likewise. * common/i386-cpuid.h: Likewise. * common/i386-gcc-cpuid.h: Likewise. * common/linux-btrace.h: Likewise. * common/linux-osdata.h: Likewise. * common/linux-procfs.h: Likewise. * common/linux-ptrace.h: Likewise. * common/mips-linux-watch.h: Likewise. * common/linux-btrace.c: Moved to nat. * common/linux-osdata.c: Likewise. * common/linux-procfs.c: Likewise. * common/linux-ptrace.c: Likewise. * common/mips-linux-watch.c: Likewise. * nat/gdb_thread_db.h: Moved from common. * nat/glibc_thread_db.h: Likewise. * nat/i386-cpuid.h: Likewise. * nat/i386-gcc-cpuid.h: Likewise. * nat/linux-btrace.c: Likewise. * nat/linux-btrace.h: Likewise. * nat/linux-osdata.c: Likewise. * nat/linux-osdata.h: Likewise. * nat/linux-procfs.c: Likewise. * nat/linux-procfs.h: Likewise. * nat/linux-ptrace.c: Likewise. * nat/linux-ptrace.h: Likewise. * nat/mips-linux-watch.c: Likewise. * nat/mips-linux-watch.h: Likewise. * Makefile.in (HFILES_NO_SRCDIR): Reflect new locations. (object file files): Reordered. * gdb/copyright.py (EXCLUDE_LIST): Reflect new location of glibc_thread_db.h. gdb/gdbserver/ 2014-06-20 Gary Benson <gbenson@redhat.com> * Makefile.in (SFILES): Update locations for files moved from common to nat. (object file files): Reordered. gdb/testsuite/ 2014-06-20 Gary Benson <gbenson@redhat.com> * gdb.arch/i386-avx.exp: Fix include file location. * gdb.arch/i386-sse.exp: Likewise.
2014-06-19 15:46:38 +02:00
#include "nat/linux-ptrace.h"
#include "nat/linux-procfs.h"
Move code to disable ASR to nat/ This patch moves the shared code present on gdb/linux-nat.c:linux_nat_create_inferior and gdb/gdbserver/linux-low.c:linux_create_inferior to nat/linux-personality.c. This code is responsible for disabling address space randomization based on user setting, and using <sys/personality.h> to do that. I decided to put the prototype of the maybe_disable_address_space_randomization on nat/linux-osdata.h because it seemed the best place to put it. I regression-tested this patch on Fedora 20 x86_64, and found no regressions. gdb/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h. (linux-personality.o): New rule. * common/common-defs.h: Include <stdint.h>. * config/aarch64/linux.mh (NATDEPFILES): Include linux-personality.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/s390/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * defs.h: Remove #include <stdint.h> (moved to common/common-defs.h). * linux-nat.c: Include nat/linux-personality.h. Remove #include <sys/personality.h>; do not define ADDR_NO_RANDOMIZE (moved to nat/linux-personality.c). (linux_nat_create_inferior): Remove code to disable address space randomization (moved to nat/linux-personality.c). Create cleanup to disable address space randomization. * nat/linux-personality.c: New file. * nat/linux-personality.h: Likewise. gdb/gdbserver/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add linux-personality.c. (linux-personality.o): New rule. * configure.srv (srv_linux_obj): Add linux-personality.o to the list of objects to be built. * linux-low.c: Include nat/linux-personality.h. (linux_create_inferior): Remove code to disable address space randomization (moved to ../nat/linux-personality.c). Create cleanup to disable address space randomization.
2015-01-15 21:10:49 +01:00
#include "nat/linux-personality.h"
#include "linux-fork.h"
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
#include "gdbthread.h"
#include "gdbcmd.h"
#include "regcache.h"
#include "regset.h"
#include "inf-child.h"
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
#include "inf-ptrace.h"
#include "auxv.h"
#include <sys/procfs.h> /* for elf_gregset etc. */
#include "elf-bfd.h" /* for elfcore_write_* */
#include "gregset.h" /* for gregset */
#include "gdbcore.h" /* for get_exec_file */
#include <ctype.h> /* for isdigit */
remove gdb_stat.h This patch is purely mechanical. It removes gdb_stat.h and changes the code to use sys/stat.h. 2013-11-18 Tom Tromey <tromey@redhat.com> * common/gdb_stat.h: Remove. * ada-lang.c: Use sys/stat.h, not gdb_stat.h. * common/filestuff.c: Use sys/stat.h, not gdb_stat.h. * common/linux-osdata.c: Use sys/stat.h, not gdb_stat.h. * corefile.c: Use sys/stat.h, not gdb_stat.h. * ctf.c: Use sys/stat.h, not gdb_stat.h. * darwin-nat.c: Use sys/stat.h, not gdb_stat.h. * dbxread.c: Use sys/stat.h, not gdb_stat.h. * dwarf2read.c: Use sys/stat.h, not gdb_stat.h. * exec.c: Use sys/stat.h, not gdb_stat.h. * gdbserver/linux-low.c: Use sys/stat.h, not gdb_stat.h. * gdbserver/remote-utils.c: Use sys/stat.h, not gdb_stat.h. * inf-child.c: Use sys/stat.h, not gdb_stat.h. * jit.c: Use sys/stat.h, not gdb_stat.h. * linux-nat.c: Use sys/stat.h, not gdb_stat.h. * m68klinux-nat.c: Use sys/stat.h, not gdb_stat.h. * main.c: Use sys/stat.h, not gdb_stat.h. * mdebugread.c: Use sys/stat.h, not gdb_stat.h. * mi/mi-cmd-env.c: Use sys/stat.h, not gdb_stat.h. * nto-tdep.c: Use sys/stat.h, not gdb_stat.h. * objfiles.c: Use sys/stat.h, not gdb_stat.h. * procfs.c: Use sys/stat.h, not gdb_stat.h. * remote-fileio.c: Use sys/stat.h, not gdb_stat.h. * remote-mips.c: Use sys/stat.h, not gdb_stat.h. * remote.c: Use sys/stat.h, not gdb_stat.h. * rs6000-nat.c: Use sys/stat.h, not gdb_stat.h. * sol-thread.c: Use sys/stat.h, not gdb_stat.h. * solib-spu.c: Use sys/stat.h, not gdb_stat.h. * source.c: Use sys/stat.h, not gdb_stat.h. * symfile.c: Use sys/stat.h, not gdb_stat.h. * symmisc.c: Use sys/stat.h, not gdb_stat.h. * symtab.c: Use sys/stat.h, not gdb_stat.h. * top.c: Use sys/stat.h, not gdb_stat.h. * xcoffread.c: Use sys/stat.h, not gdb_stat.h.
2013-11-06 15:55:51 +01:00
#include <sys/stat.h> /* for struct stat */
#include <fcntl.h> /* for O_RDONLY */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
#include "inf-loop.h"
#include "event-loop.h"
#include "event-top.h"
#include <pwd.h>
#include <sys/types.h>
#include <dirent.h>
#include "xml-support.h"
#include <sys/vfs.h>
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
#include "solib.h"
Move shared native target specific code to gdb/nat https://sourceware.org/gdb/wiki/Common describes the following directory structure: gdb/nat/ Native target backend files. Code that interfaces with the host debug API. E.g., ptrace code, Windows debug API code, procfs code should go here. gdb/target/ Host-independent, target vector specific code (target_ops). gdb/common/ All other shared code. This commit moves all native target backend files currently in gdb/common to gdb/nat. gdb/ 2014-06-20 Gary Benson <gbenson@redhat.com> * common/gdb_thread_db.h: Moved to nat. All includes updated. * common/glibc_thread_db.h: Likewise. * common/i386-cpuid.h: Likewise. * common/i386-gcc-cpuid.h: Likewise. * common/linux-btrace.h: Likewise. * common/linux-osdata.h: Likewise. * common/linux-procfs.h: Likewise. * common/linux-ptrace.h: Likewise. * common/mips-linux-watch.h: Likewise. * common/linux-btrace.c: Moved to nat. * common/linux-osdata.c: Likewise. * common/linux-procfs.c: Likewise. * common/linux-ptrace.c: Likewise. * common/mips-linux-watch.c: Likewise. * nat/gdb_thread_db.h: Moved from common. * nat/glibc_thread_db.h: Likewise. * nat/i386-cpuid.h: Likewise. * nat/i386-gcc-cpuid.h: Likewise. * nat/linux-btrace.c: Likewise. * nat/linux-btrace.h: Likewise. * nat/linux-osdata.c: Likewise. * nat/linux-osdata.h: Likewise. * nat/linux-procfs.c: Likewise. * nat/linux-procfs.h: Likewise. * nat/linux-ptrace.c: Likewise. * nat/linux-ptrace.h: Likewise. * nat/mips-linux-watch.c: Likewise. * nat/mips-linux-watch.h: Likewise. * Makefile.in (HFILES_NO_SRCDIR): Reflect new locations. (object file files): Reordered. * gdb/copyright.py (EXCLUDE_LIST): Reflect new location of glibc_thread_db.h. gdb/gdbserver/ 2014-06-20 Gary Benson <gbenson@redhat.com> * Makefile.in (SFILES): Update locations for files moved from common to nat. (object file files): Reordered. gdb/testsuite/ 2014-06-20 Gary Benson <gbenson@redhat.com> * gdb.arch/i386-avx.exp: Fix include file location. * gdb.arch/i386-sse.exp: Likewise.
2014-06-19 15:46:38 +02:00
#include "nat/linux-osdata.h"
* gdbarch.sh (make_corefile_notes): New architecture callback. * gdbarch.c: Regenerate. * gdbarch.h: Likewise. * gcore.c (write_gcore_file): Try gdbarch_make_corefile_notes before target_make_corefile_notes. If NULL is returned, the target does not support core file generation. * linux-nat.c: Include "linux-tdep.h". (find_signalled_thread, find_stop_signal): Remove. (linux_nat_do_thread_registers): Likewise. (struct linux_nat_corefile_thread_data): Likewise. (linux_nat_corefile_thread_callback): Likewise. (iterate_over_spus): Likewise. (struct linux_spu_corefile_data): Likewise. (linux_spu_corefile_callback): Likewise. (linux_spu_make_corefile_notes): Likewise. (linux_nat_collect_thread_registers): New function. (linux_nat_make_corefile_notes): Replace contents by call to linux_make_corefile_notes passing linux_nat_collect_thread_registers as native-only callback. * linux-tdep.h: Include "bfd.h". (struct regcache): Add forward declaration. (linux_collect_thread_registers_ftype): New typedef. (linux_make_corefile_notes): Add prototype. * linux-tdep.c: Include "gdbthread.h", "gdbcore.h", "regcache.h", "regset.h", and "elf-bfd.h". (find_signalled_thread, find_stop_signal): New functions. (linux_spu_make_corefile_notes): Likewise. (linux_collect_thread_registers): Likewise. (struct linux_corefile_thread_data): New data structure. (linux_corefile_thread_callback): New funcion. (linux_make_corefile_notes): Likewise. (linux_make_corefile_notes_1): Likewise. (linux_init_abi): Install it.
2012-01-20 10:56:56 +01:00
#include "linux-tdep.h"
#include "symfile.h"
#include "agent.h"
#include "tracepoint.h"
#include "buffer.h"
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 02:47:20 +01:00
#include "target-descriptions.h"
PR gdb/7912: * Makefile.in (SFILES): Add filestuff.c (COMMON_OBS): Add filestuff.o. (filestuff.o): New target. * auto-load.c (auto_load_objfile_script_1): Use gdb_fopen_cloexec. * auxv.c (procfs_xfer_auxv): Use gdb_open_cloexec. * cli/cli-cmds.c (shell_escape): Call close_most_fds. * cli/cli-dump.c (fopen_with_cleanup): Use gdb_fopen_cloexec. * common/agent.c (gdb_connect_sync_socket): Use gdb_socket_cloexec. * common/filestuff.c: New file. * common/filestuff.h: New file. * common/linux-osdata.c (linux_common_core_of_thread) (command_from_pid, commandline_from_pid, print_source_lines) (linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Use gdb_fopen_cloexec. * common/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_has_state): Use gdb_fopen_cloexec. * config.in, configure: Rebuild. * configure.ac: Don't check for sys/socket.h. Check for fdwalk, pipe2. * corelow.c (core_open): Use gdb_open_cloexec. * dwarf2read.c (write_psymtabs_to_index): Use gdb_fopen_cloexec. * fork-child.c (fork_inferior): Call close_most_fds. * gdb_bfd.c (gdb_bfd_open): Use gdb_open_cloexec. * inf-child.c (inf_child_fileio_readlink): Use gdb_open_cloexec. * linux-nat.c (linux_nat_thread_name, linux_proc_pending_signals): Use gdb_fopen_cloexec. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use gdb_open_cloexec. (linux_async_pipe): Use gdb_pipe_cloexec. * remote-fileio.c (remote_fileio_func_open): Use gdb_open_cloexec. * remote.c (remote_file_put, remote_file_get): Use gdb_fopen_cloexec. * ser-pipe.c (pipe_open): Use gdb_socketpair_cloexec, close_most_fds. * ser-tcp.c (net_open): Use gdb_socket_cloexec. * ser-unix.c (hardwire_open): Use gdb_open_cloexec. * solib.c (solib_find): Use gdb_open_cloexec. * source.c (openp, find_and_open_source): Use gdb_open_cloexec. * tracepoint.c (tfile_start): Use gdb_fopen_cloexec. (tfile_open): Use gdb_open_cloexec. * tui/tui-io.c (tui_initialize_io): Use gdb_pipe_cloexec. * ui-file.c (gdb_fopen): Use gdb_fopen_cloexec. * xml-support.c (xml_fetch_content_from_file): Use gdb_fopen_cloexec. * main.c (captured_main): Call notice_open_fds. gdbserver * Makefile.in (SFILES): Add filestuff.c. (OBS): Add filestuff.o. (filestuff.o): New target. * config.in, configure: Rebuild. * configure.ac: Check for fdwalk, pipe2.
2013-04-22 18:46:15 +02:00
#include "filestuff.h"
start change to progspace independence This patch starts changing minimal symbols to be independent of the program space. Specifically, it adds a new objfile parameter to MSYMBOL_VALUE_ADDRESS and changes all the code to use it. This is needed so we can change gdb to apply the section offset when a minsym's address is computed, as opposed to baking the offsets into the symbol itself. A few spots still need the unrelocated address. For these, we introduce MSYMBOL_VALUE_RAW_ADDRESS. As a convenience, we also add the new macro BMSYMBOL_VALUE_ADDRESS, which computes the address of a bound minimal symbol. This just does the obvious thing with the fields. Note that this change does not actually enable program space independence. That requires more changes to gdb. However, to ensure that these changes compile properly, this patch does add the needed section lookup code to MSYMBOL_VALUE_ADDRESS -- it just ensures it has no effect at runtime by multiplying the offset by 0. 2014-02-26 Tom Tromey <tromey@redhat.com> * ada-lang.c (ada_main_name): Update. (ada_add_standard_exceptions): Update. * ada-tasks.c (ada_tasks_inferior_data_sniffer): Update. * aix-thread.c (pdc_symbol_addrs, pd_enable): Update. * arm-tdep.c (skip_prologue_function, arm_skip_stub): Update. * auxv.c (ld_so_xfer_auxv): Update. * avr-tdep.c (avr_scan_prologue): Update. * ax-gdb.c (gen_var_ref): Update. * blockframe.c (get_pc_function_start) (find_pc_partial_function_gnu_ifunc): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Update. * bsd-uthread.c (bsd_uthread_lookup_address): Update. * c-valprint.c (c_val_print): Update. * coff-pe-read.c (add_pe_forwarded_sym): Update. * common/agent.c (agent_look_up_symbols): Update. * dbxread.c (find_stab_function_addr, end_psymtab): Update. * dwarf2loc.c (call_site_to_target_addr): Update. * dwarf2read.c (dw2_find_pc_sect_symtab): Update. * elfread.c (elf_gnu_ifunc_record_cache) (elf_gnu_ifunc_resolve_by_got): Update. * findvar.c (default_read_var_value): Update. * frame.c (inside_main_func): Update. * frv-tdep.c (frv_frame_this_id): Update. * glibc-tdep.c (glibc_skip_solib_resolver): Update. * gnu-v3-abi.c (gnuv3_get_typeid, gnuv3_skip_trampoline): Update. * hppa-hpux-tdep.c (hppa64_hpux_search_dummy_call_sequence) (hppa_hpux_find_dummy_bpaddr): Update. * hppa-tdep.c (hppa_symbol_address): Update. * infcmd.c (until_next_command): Update. * jit.c (jit_read_descriptor, jit_breakpoint_re_set_internal): Update. * linespec.c (minsym_found, add_minsym): Update. * linux-nat.c (get_signo): Update. * linux-thread-db.c (inferior_has_bug): Update. * m32c-tdep.c (m32c_return_value) (m32c_m16c_address_to_pointer): Update. * m32r-tdep.c (m32r_frame_this_id): Update. * m68hc11-tdep.c (m68hc11_get_register_info): Update. * machoread.c (macho_resolve_oso_sym_with_minsym): Update. * maint.c (maintenance_translate_address): Update. * minsyms.c (lookup_minimal_symbol_by_pc_name): Update. (frob_address): New function. (lookup_minimal_symbol_by_pc_section_1): Use raw addresses, frob_address. Rename parameter to "pc_in". (compare_minimal_symbols, compact_minimal_symbols): Use raw addresses. (find_solib_trampoline_target, minimal_symbol_upper_bound): Update. * mips-linux-tdep.c (mips_linux_skip_resolver): Update. * mips-tdep.c (mips_skip_pic_trampoline_code): Update. * objc-lang.c (find_objc_msgsend): Update. * objfiles.c (objfile_relocate1): Update. * obsd-tdep.c (obsd_skip_solib_resolver): Update. * p-valprint.c (pascal_val_print): Update. * parse.c (write_exp_msymbol): Update. * ppc-linux-tdep.c (ppc_linux_spe_context_lookup) (ppc_elfv2_skip_entrypoint): Update. * ppc-sysv-tdep.c (convert_code_addr_to_desc_addr): Update. * printcmd.c (build_address_symbolic, msym_info) (address_info): Update. * proc-service.c (ps_pglobal_lookup): Update. * psymtab.c (find_pc_sect_psymtab_closer) (find_pc_sect_psymtab, find_pc_sect_symtab_from_partial): Change msymbol parameter to bound_minimal_symbol. * ravenscar-thread.c (get_running_thread_id): Update. * remote.c (remote_check_symbols): Update. * sh64-tdep.c (sh64_elf_make_msymbol_special): Use raw address. * sol2-tdep.c (sol2_skip_solib_resolver): Update. * solib-dsbt.c (lm_base): Update. * solib-frv.c (lm_base, main_got): Update. * solib-irix.c (locate_base): Update. * solib-som.c (som_solib_create_inferior_hook) (link_map_start): Update. * solib-spu.c (spu_enable_break, ocl_enable_break): Update. * solib-svr4.c (elf_locate_base, enable_break): Update. * spu-tdep.c (spu_get_overlay_table, spu_catch_start) (flush_ea_cache): Update. * stabsread.c (define_symbol, scan_file_globals): Update. * stack.c (find_frame_funname): Update. * symfile-debug.c (debug_qf_expand_symtabs_matching) (debug_qf_find_pc_sect_symtab): Update. * symfile.c (simple_read_overlay_table) (simple_overlay_update): Update. * symfile.h (struct quick_symbol_functions) <find_pc_sect_symtab>: Change type of msymbol to bound_minimal_symbol. * symmisc.c (dump_msymbols): Update. * symtab.c (find_pc_sect_symtab_via_partial) (find_pc_sect_psymtab, find_pc_sect_line, skip_prologue_sal) (search_symbols, print_msymbol_info): Update. * symtab.h (MSYMBOL_VALUE_RAW_ADDRESS): New macro. (MSYMBOL_VALUE_ADDRESS): Redefine. (BMSYMBOL_VALUE_ADDRESS): New macro. * tracepoint.c (scope_info): Update. * tui/tui-disasm.c (tui_find_disassembly_address) (tui_get_begin_asm_address): Update. * valops.c (find_function_in_inferior): Update. * value.c (value_static_field, value_fn_field): Update.
2013-08-15 16:46:35 +02:00
#include "objfiles.h"
#include "nat/linux-namespaces.h"
#include "fileio.h"
#ifndef SPUFS_MAGIC
#define SPUFS_MAGIC 0x23c9b64e
#endif
/* This comment documents high-level logic of this file.
Waiting for events in sync mode
===============================
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
When waiting for an event in a specific thread, we just use waitpid,
passing the specific pid, and not passing WNOHANG.
When waiting for an event in all threads, waitpid is not quite good:
- If the thread group leader exits while other threads in the thread
group still exist, waitpid(TGID, ...) hangs. That waitpid won't
return an exit status until the other threads in the group are
reaped.
- When a non-leader thread execs, that thread just vanishes without
reporting an exit (so we'd hang if we waited for it explicitly in
that case). The exec event is instead reported to the TGID pid.
The solution is to always use -1 and WNOHANG, together with
sigsuspend.
First, we use non-blocking waitpid to check for events. If nothing is
found, we use sigsuspend to wait for SIGCHLD. When SIGCHLD arrives,
it means something happened to a child process. As soon as we know
there's an event, we get back to calling nonblocking waitpid.
Note that SIGCHLD should be blocked between waitpid and sigsuspend
calls, so that we don't miss a signal. If SIGCHLD arrives in between,
when it's blocked, the signal becomes pending and sigsuspend
immediately notices it and returns.
Waiting for events in async mode (TARGET_WNOHANG)
=================================================
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
In async mode, GDB should always be ready to handle both user input
and target events, so neither blocking waitpid nor sigsuspend are
viable options. Instead, we should asynchronously notify the GDB main
event loop whenever there's an unprocessed event from the target. We
detect asynchronous target events by handling SIGCHLD signals. To
notify the event loop about target events, the self-pipe trick is used
--- a pipe is registered as waitable event source in the event loop,
the event loop select/poll's on the read end of this pipe (as well on
other event sources, e.g., stdin), and the SIGCHLD handler writes a
byte to this pipe. This is more portable than relying on
pselect/ppoll, since on kernels that lack those syscalls, libc
emulates them with select/poll+sigprocmask, and that is racy
(a.k.a. plain broken).
Obviously, if we fail to notify the event loop if there's a target
event, it's bad. OTOH, if we notify the event loop when there's no
event from the target, linux_nat_wait will detect that there's no real
event to report, and return event of type TARGET_WAITKIND_IGNORE.
This is mostly harmless, but it will waste time and is better avoided.
The main design point is that every time GDB is outside linux-nat.c,
we have a SIGCHLD handler installed that is called when something
happens to the target and notifies the GDB event loop. Whenever GDB
core decides to handle the event, and calls into linux-nat.c, we
process things as in sync mode, except that the we never block in
sigsuspend.
While processing an event, we may end up momentarily blocked in
waitpid calls. Those waitpid calls, while blocking, are guarantied to
return quickly. E.g., in all-stop mode, before reporting to the core
that an LWP hit a breakpoint, all LWPs are stopped by sending them
SIGSTOP, and synchronously waiting for the SIGSTOP to be reported.
Note that this is different from blocking indefinitely waiting for the
next event --- here, we're already handling an event.
Use of signals
==============
We stop threads by sending a SIGSTOP. The use of SIGSTOP instead of another
signal is not entirely significant; we just need for a signal to be delivered,
so that we can intercept it. SIGSTOP's advantage is that it can not be
blocked. A disadvantage is that it is not a real-time signal, so it can only
be queued once; we do not keep track of other sources of SIGSTOP.
Two other signals that can't be blocked are SIGCONT and SIGKILL. But we can't
use them, because they have special behavior when the signal is generated -
not when it is delivered. SIGCONT resumes the entire thread group and SIGKILL
kills the entire thread group.
A delivered SIGSTOP would stop the entire thread group, not just the thread we
tkill'd. But we never let the SIGSTOP be delivered; we always intercept and
cancel it (by PTRACE_CONT without passing SIGSTOP).
We could use a real-time signal instead. This would solve those problems; we
could use PTRACE_GETSIGINFO to locate the specific stop signals sent by GDB.
But we would still have to have some support for SIGSTOP, since PTRACE_ATTACH
generates it, and there are races with trying to find a signal that is not
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
blocked.
Exec events
===========
The case of a thread group (process) with 3 or more threads, and a
thread other than the leader execs is worth detailing:
On an exec, the Linux kernel destroys all threads except the execing
one in the thread group, and resets the execing thread's tid to the
tgid. No exit notification is sent for the execing thread -- from the
ptracer's perspective, it appears as though the execing thread just
vanishes. Until we reap all other threads except the leader and the
execing thread, the leader will be zombie, and the execing thread will
be in `D (disc sleep)' state. As soon as all other threads are
reaped, the execing thread changes its tid to the tgid, and the
previous (zombie) leader vanishes, giving place to the "new"
leader. */
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
#endif
/* Does the current host support PTRACE_GETREGSET? */
Convert have_ptrace_getregset to a tri-state boolean have_ptrace_getregset is a tri-state variable (-1, 0, 1), and we have some conditions like "if (have_ptrace_getregset)", which is not correct. I'll explain why it is not correct in the following example. This fix to this problem to replace the test (have_ptrace_getregset) to test (have_ptrace_getregset == 1) or (have_ptrace_getregset == -1) etc. However Doug thinks it hinders readability https://sourceware.org/ml/gdb-patches/2015-05/msg00692.html so I decide to add a new enum tribool and change have_ptrace_getregset to it, in order to make these tests more readable. have_ptrace_getregset is initialised to -1, and is adjusted to 0 or 1 in $ARCH_linux_read_description according to the capability of the kernel. However, it is possible that have_ptrace_getregset is used before it is set to 0 or 1, which means it is still -1. This is shown below. (gdb) run Starting program: gdb/testsuite/gdb.base/break Breakpoint 2, amd64_linux_fetch_inferior_registers (ops=0xceaa80, regcache=0xe72000, regnum=16) at git/gdb/amd64-linux-nat.c:128 128 { top?p have_ptrace_getregset $1 = TRIBOOL_UNKNOWN top?c Continuing. Breakpoint 2, amd64_linux_fetch_inferior_registers (ops=0xceaa80, regcache=0xe72000, regnum=16) at git/gdb/amd64-linux-nat.c:128 128 { top?c Continuing. Breakpoint 1, x86_linux_read_description (ops=0xceaa80) at git/gdb/x86-linux-nat.c:117 117 { PTRACE_GETREGSET command is used even GDB doesn't know whether PTRACE_GETREGSET is supported or not. It is wrong, but works on x86. However it doesn't work on arm-linux if the kernel doesn't support PTRACE_GETREGSET at all. We'll get: (gdb) run Starting program: gdb/testsuite/gdb.base/break warning: Unable to fetch general register. PC register is not available gdb: 2015-06-23 Yao Qi <yao.qi@linaro.org> * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Check whether have_ptrace_getregset is TRIBOOL_TRUE explicitly. (amd64_linux_store_inferior_registers): Likewise. * arm-linux-nat.c (fetch_fpregister): Likewise. (fetch_fpregs, store_fpregister): Likewise. (store_fpregister, store_fpregs): Likewise. (fetch_register, fetch_regs): Likewise. (store_register, store_regs): Likewise. (fetch_vfp_regs, store_vfp_regs): Likewise. (arm_linux_read_description): Check have_ptrace_getregset is TRIBOOL_UNKNOWN. Set have_ptrace_getregset to TRIBOOL_TRUE or TRIBOOL_FALSE. * i386-linux-nat.c (fetch_xstateregs): Check have_ptrace_getregset is not TRIBOOL_TRUE. (store_xstateregs): Likewise. * linux-nat.c (have_ptrace_getregset): Change its type to enum tribool. * linux-nat.h (tribool): New enum. * x86-linux-nat.c (x86_linux_read_description): Use enum tribool. Check whether have_ptrace_getregset is TRIBOOL_TRUE.
2015-06-23 15:03:11 +02:00
enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
/* The single-threaded native GNU/Linux target_ops. We save a pointer for
the use of the multi-threaded target. */
static struct target_ops *linux_ops;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
static struct target_ops linux_ops_saved;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* The method to call, if any, when a new thread is attached. */
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
static void (*linux_nat_new_thread) (struct lwp_info *);
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
/* The method to call, if any, when a new fork is attached. */
static linux_nat_new_fork_ftype *linux_nat_new_fork;
/* The method to call, if any, when a process is no longer
attached. */
static linux_nat_forget_process_ftype *linux_nat_forget_process_hook;
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
/* Hook to call prior to resuming a thread. */
static void (*linux_nat_prepare_to_resume) (struct lwp_info *);
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* The method to call, if any, when the siginfo object needs to be
converted between the layout returned by ptrace, and the layout in
the architecture of the inferior. */
static int (*linux_nat_siginfo_fixup) (siginfo_t *,
gdb_byte *,
int);
/* The saved to_xfer_partial method, inherited from inf-ptrace.c.
Called by our to_xfer_partial. */
static target_xfer_partial_ftype *super_xfer_partial;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
Allow making GDB not automatically connect to the native target. Sometimes it's useful to be able to disable the automatic connection to the native target. E.g., sometimes GDB disconnects from the extended-remote target I was debugging, without me noticing it, and then I do "run". That starts the program locally, and only after a little head scratch session do I figure out the program is running locally instead of remotely as intended. Same thing with "attach", "info os", etc. With the patch, we now can have this instead: (gdb) set auto-connect-native-target off (gdb) target extended-remote :9999 ... *gdb disconnects* (gdb) run Don't know how to run. Try "help target". To still be able to connect to the native target with auto-connect-native-target set to off, I've made "target native" work instead of erroring out as today. Before: (gdb) target native Use the "run" command to start a native process. After: (gdb) target native Done. Use the "run" command to start a process. (gdb) maint print target-stack The current target stack is: - native (Native process) - exec (Local exec file) - None (None) (gdb) run Starting program: ./a.out ... I've also wanted this for the testsuite, when running against the native-extended-gdbserver.exp board (runs against gdbserver in extended-remote mode). With a non-native-target board, it's always a bug to launch a program with the native target. Turns out we still have one such case this patch catches: (gdb) break main Breakpoint 1 at 0x4009e5: file ../../../src/gdb/testsuite/gdb.base/coremaker.c, line 138. (gdb) run Don't know how to run. Try "help target". (gdb) FAIL: gdb.base/corefile.exp: run: with core On the patch itself, probably the least obvious bit is the need to go through all targets, and move the unpush_target call to after the generic_mourn_inferior call instead of before. This is what inf-ptrace.c does too, ever since multi-process support was added. The reason inf-ptrace.c does things in that order is that in the current multi-process/single-target model, we shouldn't unpush the target if there are still other live inferiors being debugged. The check for that is "have_inferiors ()" (a misnomer nowadays...), which does: have_inferiors (void) { for (inf = inferior_list; inf; inf = inf->next) if (inf->pid != 0) return 1; It's generic_mourn_inferior that ends up clearing inf->pid, so we need to call it before the have_inferiors check. To make all native targets behave the same WRT to explicit "target native", I've added an inf_child_maybe_unpush_target function that targets call instead of calling unpush_target directly, and as that includes the have_inferiors check, I needed to adjust the targets. Tested on x86_64 Fedora 20, native, and also with the extended-gdbserver board. Confirmed a cross build of djgpp gdb still builds. Smoke tested a cross build of Windows gdb under Wine. Untested otherwise. gdb/ 2014-05-21 Pedro Alves <palves@redhat.com> * inf-child.c (inf_child_ops, inf_child_explicitly_opened): New globals. (inf_child_open_target): New function. (inf_child_open): Use inf_child_open_target to push the target instead of erroring out. (inf_child_disconnect, inf_child_close) (inf_child_maybe_unpush_target): New functions. (inf_child_target): Install inf_child_disconnect and inf_child_close. Store a pointer to the returned object. * inf-child.h (inf_child_open_target, inf_child_maybe_unpush): New declarations. * target.c (auto_connect_native_target): New global. (show_default_run_target): New function. (find_default_run_target): Return NULL if automatically connecting to the native target is disabled. (_initialize_target): Install set/show auto-connect-native-target. * NEWS: Mention "set auto-connect-native-target", and "target native". * linux-nat.c (super_close): New global. (linux_nat_close): Call super_close. (linux_nat_add_target): Store a pointer to the base class's to_close method. * inf-ptrace.c (inf_ptrace_mourn_inferior, inf_ptrace_detach): Use inf_child_maybe_unpush. * inf-ttrace.c (inf_ttrace_him): Don't push the target if it is already pushed. (inf_ttrace_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (inf_ttrace_attach): Don't push the target if it is already pushed. (inf_ttrace_detach): Use inf_child_maybe_unpush_target. * darwin-nat.c (darwin_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (darwin_attach_pid): Don't push the target if it is already pushed. * gnu-nat.c (gnu_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (gnu_detach): Use inf_child_maybe_unpush_target. * go32-nat.c (go32_create_inferior): Don't push the target if it is already pushed. (go32_mourn_inferior): Use inf_child_maybe_unpush_target. * nto-procfs.c (procfs_is_nto_target): Adjust comment. (procfs_open): Rename to ... (procfs_open_1): ... this. Add target_ops parameter. Adjust comments. Can target_preopen before changing node. Call inf_child_open_target to push the target explicitly. (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_create_inferior): Don't push the target if it is already pushed. (nto_native_ops): New global. (procfs_open): Reimplement. (procfs_native_open): New function. (init_procfs_targets): Install procfs_native_open as to_open of "target native". Store a pointer to the "native" target in nto_native_ops. * procfs.c (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (procfs_init_inferior): Don't push the target if it is already pushed. * windows-nat.c (do_initial_windows_stuff): Don't push the target if it is already pushed. (windows_detach): Use inf_child_maybe_unpush_target. (windows_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. gdb/doc/ 2014-05-21 Pedro Alves <palves@redhat.com> * gdb.texinfo (Starting): Document "set/show auto-connect-native-target". (Target Commands): Document "target native". gdb/testsuite/ 2014-05-21 Pedro Alves <palves@redhat.com> * boards/gdbserver-base.exp (GDBFLAGS): Set to "set auto-connect-native-target off". * gdb.base/auto-connect-native-target.c: New file. * gdb.base/auto-connect-native-target.exp: New file.
2014-05-21 19:30:47 +02:00
/* The saved to_close method, inherited from inf-ptrace.c.
Called by our to_close. */
static void (*super_close) (struct target_ops *);
gdb/ * dwarf2loc.c (entry_values_debug): Add 'unsigned'. (_initialize_dwarf2loc): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * dwarf2loc.h: Update the declaration of 'entry_values_debug'. * dwarf2read.c (dwarf2_die_debug): Add 'unsigned'. (_initialize_dwarf2_read): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * darwin-nat.c (dwarwin_debug_flag): Add 'unsigned'. (_initialize_darwin_inferior): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.c (frame_debug): Add 'unsigned'. (_intialize_frame): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.h: Update the declaration of 'frame_debug'. * gdbtypes.c (overload_debug): Add 'unsigned'. (_initialize_gdbtypes): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * inferior.h: Update declaration of 'debug_infrun'. * infrun.c (debug_infrun): Add 'unsigned'. (_initialize_infrun): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * jit.c (jit_debug): Add 'unsigned'. (_initialize_jit): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-nat.c (debug_linux_nat): Add 'unsigned'. (_initialize_linux_nat): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-thread-db.c (libthread_db_debug): Add 'unsigned'. (_initialize_thread_db): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * machoread.c (mach_o_debug_level): Add 'unsigned'. (_initialize_machoread): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * mi/mi-cmd-var.c: Update the declaration of 'varobjdebug'. * microblaze-tdep.c (microblaze_debug_flag): Add 'unsigned'. (_initialize_microblaze_tdep): Call add_setshow_zuinteger_cmd intead of add_setshow_zinteger_cmd. * mips-tdep.c (mips_debug): Add 'unsigned'. (_initialize_mips_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * monitor.c (monitor_debug): Add 'unsigned'. (_initialize_remote_monitors): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * observer.c (observer_debug): Add 'unsigned'. (_initialize_observer): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * parse.c (expressiondebug): Add 'unsigned'. (_initialize_parse): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.c (record_debug): Add 'unsigned'. (_initialize_record): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.h: Update the declaration of 'record_debug'. * stap-probe.c (stap_expression_debug): Add 'unsigned'. (_initialize_stap_probe): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * serial.c (global_serial_debug_p): Add 'unsigned'. (_initialize_serial): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-dsbt.c (solib_dsbt_debug): Add 'unsigned'. (_initialize_dsbt_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-frv.c (solib_frv_debug): Add 'unsigned'. (_initialize_frv_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * target.c (targetdebug): Add 'unsigned'. (initialize_targets): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * valops.c (overload_debug): Add 'unsigned'. * varobj.c (varobjdebug): Add 'unsigned'. (_initialize_varobj): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * xtensa-tdep.c (xtensa_debug_level): Add 'unsigned'. (_initialize_xtensa_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * arch-utils.h: Remove the declaration of 'gdbarch_debug'. * gdbarch.sh (gdbarch_debug): Add 'unsigned'. (extern void _initialize_gdbarch): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * gdbarch.c, gdbarch.h: Re-generated.
2012-08-02 11:36:40 +02:00
static unsigned int debug_linux_nat;
2005-02-24 Andrew Cagney <cagney@gnu.org> Add show_VARIABLE functions, update add_setshow call. * varobj.c (_initialize_varobj, show_varobjdebug): Add and update. * valprint.c (_initialize_valprint, show_print_max) (show_stop_print_at_null, show_repeat_count_threshold) (show_prettyprint_structs, show_unionprint) (show_prettyprint_arrays, show_addressprint, show_input_radix) (show_output_radix): Ditto. * valops.c (_initialize_valops, show_overload_resolution): Ditto. * utils.c (initialize_utils, show_chars_per_line) (show_lines_per_page, show_demangle, show_pagination_enabled) (show_sevenbit_strings, show_asm_demangle): Ditto * tui/tui-win.c (_initialize_tui_win, show_tui_border_kind) (show_tui_border_mode, show_tui_active_border_mode): Ditto. * top.c (init_main, show_new_async_prompt) (show_async_command_editing_p, show_write_history_p) (show_history_size, show_history_filename, show_caution) (show_annotation_level, init_main): Ditto. * target.c (initialize_targets, show_targetdebug) (show_trust_readonly): Ditto. * symfile.c (_initialize_symfile, show_symbol_reloading) (show_ext_args, show_download_write_size) (show_debug_file_directory): Ditto. * source.c (_initialize_source, show_lines_to_list): Ditto. * solib.c (_initialize_solib, show_auto_solib_add) (show_solib_search_path): Ditto. * p-valprint.c (_initialize_pascal_valprint) (show_pascal_static_field_print): Ditto. * printcmd.c (_initialize_printcmd, show_max_symbolic_offset) (show_print_symbol_filename): Add and update. * parse.c (_initialize_parse, show_expressiondebug): Dito. * observer.c (_initialize_observer, show_observer_debug): Dito. * maint.c (_initialize_maint_cmds, show_watchdog) (show_maintenance_profile_p): Dito. * linux-nat.c (_initialize_linux_nat, show_debug_linux_nat): Dito. * infrun.c (_initialize_infrun, show_debug_infrun) (show_stop_on_solib_events, show_follow_fork_mode_string) (show_scheduler_mode, show_step_stop_if_no_debug): Ditto. * infcall.c (_initialize_infcall, show_coerce_float_to_double_p) (show_unwind_on_signal_p): Ditto. * gdbtypes.c (build_gdbtypes, show_opaque_type_resolution) (_initialize_gdbtypes, show_overload_debug): Ditto. * gdb-events.c, gdb-events.sh (_initialize_gdb_events) (show_gdb_events_debug): Ditto. * gdbarch.c, gdbarch.sh (show_gdbarch_debug) (_initialize_gdbarch): Ditto. * frame.c (_initialize_frame, show_backtrace_past_main) (show_backtrace_past_entry, show_backtrace_limit) (show_frame_debug): Ditto. * exec.c (_initialize_exec, show_write_files): Ditto. * dwarf2read.c (_initialize_dwarf2_read) (show_dwarf2_max_cache_age): Ditto. * demangle.c (_initialize_demangler) (show_demangling_style_names): Ditto. * dcache.c (_initialize_dcache, show_dcache_enabled_p): Ditto. * cp-valprint.c (show_static_field_print) (_initialize_cp_valprint, show_vtblprint, show_objectprint): Ditto. * corefile.c (_initialize_core, show_gnutarget_string): Ditto. * cli/cli-logging.c (_initialize_cli_logging) (show_logging_overwrite, show_logging_redirect) (show_logging_filename): Ditto. * cli/cli-cmds.c (show_info_verbose, show_history_expansion_p) (init_cli_cmds, show_baud_rate, show_remote_debug) (show_remote_timeout, show_max_user_call_depth): Ditto. * charset.c (show_host_charset_name, show_target_charset_name) (initialize_charset): Ditto. * breakpoint.c (show_can_use_hw_watchpoints) (show_pending_break_support, _initialize_breakpoint): Ditto.
2005-02-24 14:51:36 +01:00
static void
show_debug_linux_nat (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Debugging of GNU/Linux lwp module is %s.\n"),
value);
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
struct simple_pid_list
{
int pid;
int status;
struct simple_pid_list *next;
};
struct simple_pid_list *stopped_pids;
/* Whether target_thread_events is in effect. */
static int report_thread_events;
/* Async mode support. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* The read/write ends of the pipe registered as waitable file in the
event loop. */
static int linux_nat_event_pipe[2] = { -1, -1 };
/* True if we're currently in async mode. */
#define linux_is_async_p() (linux_nat_event_pipe[0] != -1)
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Flush the event pipe. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
static void
async_file_flush (void)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
int ret;
char buf;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
do
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
ret = read (linux_nat_event_pipe[0], &buf, 1);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
while (ret >= 0 || (ret == -1 && errno == EINTR));
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Put something (anything, doesn't matter what, or how much) in event
pipe, so that the select/poll in the event-loop realizes we have
something to process. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
static void
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
async_file_mark (void)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
int ret;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* It doesn't really matter what the pipe contains, as long we end
up with something in it. Might as well flush the previous
left-overs. */
async_file_flush ();
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
do
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
ret = write (linux_nat_event_pipe[1], "+", 1);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
while (ret == -1 && errno == EINTR);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Ignore EAGAIN. If the pipe is full, the event loop will already
be awakened anyway. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
static int kill_lwp (int lwpid, int signo);
static int stop_callback (struct lwp_info *lp, void *data);
GNU/Linux: Stop using libthread_db/td_ta_thr_iter TL;DR - GDB can hang if something refreshes the thread list out of the target while the target is running. GDB hangs inside td_ta_thr_iter. The fix is to not use that libthread_db function anymore. Long version: Running the testsuite against my all-stop-on-top-of-non-stop series is still exposing latent non-stop bugs. I was originally seeing this with the multi-create.exp test, back when we were still using libthread_db thread event breakpoints. The all-stop-on-top-of-non-stop series forces a thread list refresh each time GDB needs to start stepping over a breakpoint (to pause all threads). That test hits the thread event breakpoint often, resulting in a bunch of step-over operations, thus a bunch of thread list refreshes while some threads in the target are running. The commit adds a real non-stop mode test that triggers the issue, based on multi-create.exp, that does an explicit "info threads" when a breakpoint is hit. IOW, it does the same things the as-ns series was doing when testing multi-create.exp. The bug is a race, so it unfortunately takes several runs for the test to trigger it. In fact, even when setting the test running in a loop, it sometimes takes several minutes for it to trigger for me. The race is related to libthread_db's td_ta_thr_iter. This is libthread_db's entry point for walking the thread list of the inferior. Sometimes, when GDB refreshes the thread list from the target, libthread_db's td_ta_thr_iter can somehow see glibc's thread list as a cycle, and get stuck in an infinite loop. The issue is that when a thread exits, its thread control structure in glibc is moved from a "used" list to a "cache" list. These lists are simply circular linked lists where the "next/prev" pointers are embedded in the thread control structure itself. The "next" pointer of the last element of the list points back to the list's sentinel "head". There's only one set of "next/prev" pointers for both lists; thus a thread can only be in one of the lists at a time, not in both simultaneously. So when thread C exits, simplifying, the following happens. A-C are threads. stack_used and stack_cache are the list's heads. Before: stack_used -> A -> B -> C -> (&stack_used) stack_cache -> (&stack_cache) After: stack_used -> A -> B -> (&stack_used) stack_cache -> C -> (&stack_cache) td_ta_thr_iter starts by iterating at the list's head's next, and iterates until it sees a thread whose next pointer points to the list's head again. Thus in the before case above, C's next points to stack_used, indicating end of list. In the same case, the stack_cache list is empty. For each thread being iterated, td_ta_thr_iter reads the whole thread object out of the inferior. This includes the thread's "next" pointer. In the scenario above, it may happen that td_ta_thr_iter is iterating thread B and has already read B's thread structure just before thread C exits and its control structure moves to the cached list. Now, recall that td_ta_thr_iter is running in the context of GDB, and there's no locking between GDB and the inferior. From it's local copy of B, td_ta_thr_iter believes that the next thread after B is thread C, so it happilly continues iterating to C, a thread that has already exited, and is now in the stack cache list. After iterating C, td_ta_thr_iter finds the stack_cache head, which because it is not stack_used, td_ta_thr_iter assumes it's just another thread. After this, unless the reverse race triggers, GDB gets stuck in td_ta_thr_iter forever walking the stack_cache list, as no thread in thatlist has a next pointer that points back to stack_used (the terminating condition). Before fully understanding the issue, I tried adding cycle detection to GDB's td_ta_thr_iter callback. However, td_ta_thr_iter skips calling the callback in some cases, which means that it's possible that the callback isn't called at all, making it impossible for GDB to break the loop. I did manage to get GDB stuck in that state more than once. Fortunately, we can avoid the issue altogether. We don't really need td_ta_thr_iter for live debugging nowadays, given PTRACE_EVENT_CLONE. We already know how to map and lwp id to a thread id without iterating (thread_from_lwp), so use that more. gdb/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_handle_extended_wait): Call thread_db_notice_clone whenever a new clone LWP is detected. (linux_stop_and_wait_all_lwps, linux_unstop_all_lwps): New functions. * linux-nat.h (thread_db_attach_lwp): Delete declaration. (thread_db_notice_clone, linux_stop_and_wait_all_lwps) (linux_unstop_all_lwps): Declare. * linux-thread-db.c (struct thread_get_info_inout): Delete. (thread_get_info_callback): Delete. (thread_from_lwp): Use td_thr_get_info and record_thread. (thread_db_attach_lwp): Delete. (thread_db_notice_clone): New function. (try_thread_db_load_1): If /proc is mounted and shows the process'es task list, walk over all LWPs and call thread_from_lwp instead of relying on td_ta_thr_iter. (attach_thread): Don't call check_thread_signals here. Split the tail part of the function (which adds the thread to the core GDB thread list) to ... (record_thread): ... this function. Call check_thread_signals here. (thread_db_wait): Don't call thread_db_find_new_threads_1. Always call thread_from_lwp. (thread_db_update_thread_list): Rename to ... (thread_db_update_thread_list_org): ... this. (thread_db_update_thread_list): New function. (thread_db_find_thread_from_tid): Delete. (thread_db_get_ada_task_ptid): Simplify. * nat/linux-procfs.c: Include <sys/stat.h>. (linux_proc_task_list_dir_exists): New function. * nat/linux-procfs.h (linux_proc_task_list_dir_exists): Declare. gdb/gdbserver/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * thread-db.c: Include "nat/linux-procfs.h". (thread_db_init): Skip listing new threads if the kernel supports PTRACE_EVENT_CLONE and /proc/PID/task/ is accessible. gdb/testsuite/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * gdb.threads/multi-create-ns-info-thr.exp: New file.
2015-02-20 21:21:59 +01:00
static int resume_stopped_resumed_lwps (struct lwp_info *lp, void *data);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
static void block_child_signals (sigset_t *prev_mask);
static void restore_child_signals_mask (sigset_t *prev_mask);
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
struct lwp_info;
static struct lwp_info *add_lwp (ptid_t ptid);
static void purge_lwp_list (int pid);
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
static void delete_lwp (ptid_t ptid);
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
static struct lwp_info *find_lwp_pid (ptid_t ptid);
static int lwp_status_pending_p (struct lwp_info *lp);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
static int sigtrap_is_event (int status);
static int (*linux_nat_status_is_event) (int status) = sigtrap_is_event;
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
static void save_stop_reason (struct lwp_info *lp);
/* LWP accessors. */
/* See nat/linux-nat.h. */
ptid_t
ptid_of_lwp (struct lwp_info *lwp)
{
return lwp->ptid;
}
/* See nat/linux-nat.h. */
2015-03-24 15:05:44 +01:00
void
lwp_set_arch_private_info (struct lwp_info *lwp,
struct arch_lwp_info *info)
{
lwp->arch_private = info;
}
/* See nat/linux-nat.h. */
struct arch_lwp_info *
lwp_arch_private_info (struct lwp_info *lwp)
{
return lwp->arch_private;
}
/* See nat/linux-nat.h. */
int
lwp_is_stopped (struct lwp_info *lwp)
{
return lwp->stopped;
}
/* See nat/linux-nat.h. */
enum target_stop_reason
lwp_stop_reason (struct lwp_info *lwp)
{
return lwp->stop_reason;
}
/* See nat/linux-nat.h. */
int
lwp_is_stepping (struct lwp_info *lwp)
{
return lwp->step;
}
/* Trivial list manipulation functions to keep track of a list of
new stopped processes. */
static void
add_to_pid_list (struct simple_pid_list **listp, int pid, int status)
{
Replace some xmalloc-family functions with XNEW-family ones This patch is part of the make-gdb-buildable-in-C++ effort. The idea is to change some calls to the xmalloc family of functions to calls to the equivalents in the XNEW family. This avoids adding an explicit cast, so it keeps the code a bit more readable. Some of them also map relatively well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be possible to do scripted replacements if needed. I only changed calls that were obviously allocating memory for one or multiple "objects". Allocation of variable sizes (such as strings or buffer handling) will be for later (and won't use XNEW). - xmalloc (sizeof (struct foo)) -> XNEW (struct foo) - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num) - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo) - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num) - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num) - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo) - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num) - alloca (sizeof (struct foo)) -> XALLOCA (struct foo) - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num) Some instances of xmalloc followed by memset to zero the buffer were replaced by XCNEW or XCNEWVEC. I regtested on x86-64, Ubuntu 14.04, but the patch touches many architecture-specific files. For those I'll have to rely on the buildbot or people complaining that I broke their gdb. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_add_process): Likewise. * aarch64-tdep.c (aarch64_gdbarch_init): Likewise. * ada-exp.y (write_ambiguous_var): Likewise. * ada-lang.c (resolve_subexp): Likewise. (user_select_syms): Likewise. (assign_aggregate): Likewise. (ada_evaluate_subexp): Likewise. (cache_symbol): Likewise. * addrmap.c (allocate_key): Likewise. (addrmap_create_mutable): Likewise. * aix-thread.c (sync_threadlists): Likewise. * alpha-tdep.c (alpha_push_dummy_call): Likewise. (alpha_gdbarch_init): Likewise. * amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise. * arm-linux-nat.c (arm_linux_add_process): Likewise. * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise. * arm-tdep.c (push_stack_item): Likewise. (arm_displaced_step_copy_insn): Likewise. (arm_gdbarch_init): Likewise. (_initialize_arm_tdep): Likewise. * avr-tdep.c (push_stack_item): Likewise. * ax-general.c (new_agent_expr): Likewise. * block.c (block_initialize_namespace): Likewise. * breakpoint.c (alloc_counted_command_line): Likewise. (update_dprintf_command_list): Likewise. (parse_breakpoint_sals): Likewise. (decode_static_tracepoint_spec): Likewise. (until_break_command): Likewise. (clear_command): Likewise. (update_global_location_list): Likewise. (get_breakpoint_objfile_data) Likewise. * btrace.c (ftrace_new_function): Likewise. (btrace_set_insn_history): Likewise. (btrace_set_call_history): Likewise. * buildsym.c (add_symbol_to_list): Likewise. (record_pending_block): Likewise. (start_subfile): Likewise. (start_buildsym_compunit): Likewise. (push_subfile): Likewise. (end_symtab_get_static_block): Likewise. (buildsym_init): Likewise. * cli/cli-cmds.c (source_command): Likewise. * cli/cli-decode.c (add_cmd): Likewise. * cli/cli-script.c (build_command_line): Likewise. (setup_user_args): Likewise. (realloc_body_list): Likewise. (process_next_line): Likewise. (copy_command_lines): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (read_pe_exported_syms): Likewise. * coffread.c (coff_locate_sections): Likewise. (coff_symtab_read): Likewise. (coff_read_struct_type): Likewise. * common/cleanups.c (make_my_cleanup2): Likewise. * common/common-exceptions.c (throw_it): Likewise. * common/filestuff.c (make_cleanup_close): Likewise. * common/format.c (parse_format_string): Likewise. * common/queue.h (DEFINE_QUEUE_P): Likewise. * compile/compile-object-load.c (munmap_list_add): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * compile/compile.c (append_args): Likewise. * corefile.c (specify_exec_file_hook): Likewise. * cp-support.c (make_symbol_overload_list): Likewise. * cris-tdep.c (push_stack_item): Likewise. (cris_gdbarch_init): Likewise. * ctf.c (ctf_trace_file_writer_new): Likewise. * dbxread.c (init_header_files): Likewise. (add_new_header_file): Likewise. (init_bincl_list): Likewise. (dbx_end_psymtab): Likewise. (start_psymtab): Likewise. (dbx_end_psymtab): Likewise. * dcache.c (dcache_init): Likewise. * dictionary.c (dict_create_hashed): Likewise. (dict_create_hashed_expandable): Likewise. (dict_create_linear): Likewise. (dict_create_linear_expandable): Likewise. * dtrace-probe.c (dtrace_process_dof_probe): Likewise. * dummy-frame.c (register_dummy_frame_dtor): Likewise. * dwarf2-frame-tailcall.c (cache_new_ref1): Likewise. * dwarf2-frame.c (dwarf2_build_frame_info): Likewise. (decode_frame_entry_1): Likewise. * dwarf2expr.c (new_dwarf_expr_context): Likewise. * dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise. * dwarf2read.c (dwarf2_has_info): Likewise. (create_signatured_type_table_from_index): Likewise. (dwarf2_read_index): Likewise. (dw2_get_file_names_reader): Likewise. (create_all_type_units): Likewise. (read_cutu_die_from_dwo): Likewise. (init_tu_and_read_dwo_dies): Likewise. (init_cutu_and_read_dies): Likewise. (create_all_comp_units): Likewise. (queue_comp_unit): Likewise. (inherit_abstract_dies): Likewise. (read_call_site_scope): Likewise. (dwarf2_add_field): Likewise. (dwarf2_add_typedef): Likewise. (dwarf2_add_member_fn): Likewise. (attr_to_dynamic_prop): Likewise. (abbrev_table_alloc_abbrev): Likewise. (abbrev_table_read_table): Likewise. (add_include_dir): Likewise. (add_file_name): Likewise. (dwarf_decode_line_header): Likewise. (dwarf2_const_value_attr): Likewise. (dwarf_alloc_block): Likewise. (parse_macro_definition): Likewise. (set_die_type): Likewise. (write_psymtabs_to_index): Likewise. (create_cus_from_index): Likewise. (dwarf2_create_include_psymtab): Likewise. (process_psymtab_comp_unit_reader): Likewise. (build_type_psymtab_dependencies): Likewise. (read_comp_units_from_section): Likewise. (compute_compunit_symtab_includes): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (load_partial_dies): Likewise. (dwarf2_symbol_mark_computed): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_read_minimal_symbols): Likewise. * environ.c (make_environ): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * event-loop.c (create_file_handler): Likewise. (create_async_signal_handler): Likewise. (create_async_event_handler): Likewise. (create_timer): Likewise. * exec.c (build_section_table): Likewise. * fbsd-nat.c (fbsd_remember_child): Likewise. * fork-child.c (fork_inferior): Likewise. * frv-tdep.c (new_variant): Likewise. * gdbarch.sh (gdbarch_alloc): Likewise. (append_name): Likewise. * gdbtypes.c (rank_function): Likewise. (copy_type_recursive): Likewise. (add_dyn_prop): Likewise. * gnu-nat.c (make_proc): Likewise. (make_inf): Likewise. (gnu_write_inferior): Likewise. * gnu-v3-abi.c (build_gdb_vtable_type): Likewise. (build_std_type_info_type): Likewise. * guile/scm-param.c (compute_enum_list): Likewise. * guile/scm-utils.c (gdbscm_parse_function_args): Likewise. * guile/scm-value.c (gdbscm_value_call): Likewise. * h8300-tdep.c (h8300_gdbarch_init): Likewise. * hppa-tdep.c (hppa_init_objfile_priv_data): Likewise. (read_unwind_info): Likewise. * ia64-tdep.c (ia64_gdbarch_init): Likewise. * infcall.c (dummy_frame_context_saver_setup): Likewise. (call_function_by_hand_dummy): Likewise. * infcmd.c (step_once): Likewise. (finish_forward): Likewise. (attach_command): Likewise. (notice_new_inferior): Likewise. * inferior.c (add_inferior_silent): Likewise. * infrun.c (add_displaced_stepping_state): Likewise. (save_infcall_control_state): Likewise. (save_inferior_ptid): Likewise. (_initialize_infrun): Likewise. * jit.c (bfd_open_from_target_memory): Likewise. (jit_gdbarch_data_init): Likewise. * language.c (add_language): Likewise. * linespec.c (decode_line_2): Likewise. * linux-nat.c (add_to_pid_list): Likewise. (add_initial_lwp): Likewise. * linux-thread-db.c (add_thread_db_info): Likewise. (record_thread): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_gdbarch_init): Likewise. * m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise. * m68k-tdep.c (m68k_gdbarch_init): Likewise. * m88k-tdep.c (m88k_analyze_prologue): Likewise. * macrocmd.c (macro_define_command): Likewise. * macroexp.c (gather_arguments): Likewise. * macroscope.c (sal_macro_scope): Likewise. * macrotab.c (new_macro_table): Likewise. * mdebugread.c (push_parse_stack): Likewise. (parse_partial_symbols): Likewise. (parse_symbol): Likewise. (psymtab_to_symtab_1): Likewise. (new_block): Likewise. (new_psymtab): Likewise. (mdebug_build_psymtabs): Likewise. (add_pending): Likewise. (elfmdebug_build_psymtabs): Likewise. * mep-tdep.c (mep_gdbarch_init): Likewise. * mi/mi-main.c (mi_execute_command): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. * minidebug.c (lzma_open): Likewise. * minsyms.c (terminate_minimal_symbol_table): Likewise. * mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise. * mips-tdep.c (mips_gdbarch_init): Likewise. * mn10300-tdep.c (mn10300_gdbarch_init): Likewise. * msp430-tdep.c (msp430_gdbarch_init): Likewise. * mt-tdep.c (mt_registers_info): Likewise. * nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise. * nat/linux-btrace.c (linux_enable_bts): Likewise. (linux_enable_pt): Likewise. * nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise. (linux_xfer_osdata_processgroups): Likewise. * nios2-tdep.c (nios2_gdbarch_init): Likewise. * nto-procfs.c (procfs_meminfo): Likewise. * objc-lang.c (start_msglist): Likewise. (selectors_info): Likewise. (classes_info): Likewise. (find_methods): Likewise. * objfiles.c (allocate_objfile): Likewise. (update_section_map): Likewise. * osabi.c (gdbarch_register_osabi): Likewise. (gdbarch_register_osabi_sniffer): Likewise. * parse.c (start_arglist): Likewise. * ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise. (hwdebug_insert_point): Likewise. * printcmd.c (display_command): Likewise. (ui_printf): Likewise. * procfs.c (create_procinfo): Likewise. (load_syscalls): Likewise. (proc_get_LDT_entry): Likewise. (proc_update_threads): Likewise. * prologue-value.c (make_pv_area): Likewise. (pv_area_store): Likewise. * psymtab.c (extend_psymbol_list): Likewise. (init_psymbol_list): Likewise. (allocate_psymtab): Likewise. * python/py-inferior.c (add_thread_object): Likewise. * python/py-param.c (compute_enum_values): Likewise. * python/py-value.c (valpy_call): Likewise. * python/py-varobj.c (py_varobj_iter_next): Likewise. * python/python.c (ensure_python_env): Likewise. * record-btrace.c (record_btrace_start_replaying): Likewise. * record-full.c (record_full_reg_alloc): Likewise. (record_full_mem_alloc): Likewise. (record_full_end_alloc): Likewise. (record_full_core_xfer_partial): Likewise. * regcache.c (get_thread_arch_aspace_regcache): Likewise. * remote-fileio.c (remote_fileio_init_fd_map): Likewise. * remote-notif.c (remote_notif_state_allocate): Likewise. * remote.c (demand_private_info): Likewise. (remote_notif_stop_alloc_reply): Likewise. (remote_enable_btrace): Likewise. * reverse.c (save_bookmark_command): Likewise. * rl78-tdep.c (rl78_gdbarch_init): Likewise. * rx-tdep.c (rx_gdbarch_init): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. * ser-go32.c (dos_get_tty_state): Likewise. (dos_copy_tty_state): Likewise. * ser-mingw.c (ser_windows_open): Likewise. (ser_console_wait_handle): Likewise. (ser_console_get_tty_state): Likewise. (make_pipe_state): Likewise. (net_windows_open): Likewise. * ser-unix.c (hardwire_get_tty_state): Likewise. (hardwire_copy_tty_state): Likewise. * solib-aix.c (solib_aix_new_lm_info): Likewise. * solib-dsbt.c (dsbt_current_sos): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (frv_current_sos): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_bfd_fopen): Likewise. * solib-svr4.c (lm_info_read): Likewise. (svr4_copy_library_list): Likewise. (svr4_default_sos): Likewise. * source.c (find_source_lines): Likewise. (line_info): Likewise. (add_substitute_path_rule): Likewise. * spu-linux-nat.c (spu_bfd_open): Likewise. * spu-tdep.c (info_spu_dma_cmdlist): Likewise. * stabsread.c (dbx_lookup_type): Likewise. (read_type): Likewise. (read_member_functions): Likewise. (read_struct_fields): Likewise. (read_baseclasses): Likewise. (read_args): Likewise. (_initialize_stabsread): Likewise. * stack.c (func_command): Likewise. * stap-probe.c (handle_stap_probe): Likewise. * symfile.c (addrs_section_sort): Likewise. (addr_info_make_relative): Likewise. (load_section_callback): Likewise. (add_symbol_file_command): Likewise. (init_filename_language_table): Likewise. * symtab.c (create_filename_seen_cache): Likewise. (sort_search_symbols_remove_dups): Likewise. (search_symbols): Likewise. * target.c (make_cleanup_restore_target_terminal): Likewise. * thread.c (new_thread): Likewise. (enable_thread_stack_temporaries): Likewise. (make_cleanup_restore_current_thread): Likewise. (thread_apply_all_command): Likewise. * tic6x-tdep.c (tic6x_gdbarch_init): Likewise. * top.c (gdb_readline_wrapper): Likewise. * tracefile-tfile.c (tfile_trace_file_writer_new): Likewise. * tracepoint.c (trace_find_line_command): Likewise. (all_tracepoint_actions_and_cleanup): Likewise. (make_cleanup_restore_current_traceframe): Likewise. (get_uploaded_tp): Likewise. (get_uploaded_tsv): Likewise. * tui/tui-data.c (tui_alloc_generic_win_info): Likewise. (tui_alloc_win_info): Likewise. (tui_alloc_content): Likewise. (tui_add_content_elements): Likewise. * tui/tui-disasm.c (tui_find_disassembly_address): Likewise. (tui_set_disassem_content): Likewise. * ui-file.c (ui_file_new): Likewise. (stdio_file_new): Likewise. (tee_file_new): Likewise. * utils.c (make_cleanup_restore_integer): Likewise. (add_internal_problem_command): Likewise. * v850-tdep.c (v850_gdbarch_init): Likewise. * valops.c (find_oload_champ): Likewise. * value.c (allocate_value_lazy): Likewise. (record_latest_value): Likewise. (create_internalvar): Likewise. * varobj.c (install_variable): Likewise. (new_variable): Likewise. (new_root_variable): Likewise. (cppush): Likewise. (_initialize_varobj): Likewise. * windows-nat.c (windows_make_so): Likewise. * x86-nat.c (x86_add_process): Likewise. * xcoffread.c (arrange_linetable): Likewise. (allocate_include_entry): Likewise. (process_linenos): Likewise. (SYMBOL_DUP): Likewise. (xcoff_start_psymtab): Likewise. (xcoff_end_psymtab): Likewise. * xml-support.c (gdb_xml_parse_attr_ulongest): Likewise. * xtensa-tdep.c (xtensa_register_type): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Likewise. (compile_bytecodes): Likewise. * dll.c (loaded_dll): Likewise. * event-loop.c (append_callback_event): Likewise. (create_file_handler): Likewise. (create_file_event): Likewise. * hostio.c (handle_open): Likewise. * inferiors.c (add_thread): Likewise. (add_process): Likewise. * linux-aarch64-low.c (aarch64_linux_new_process): Likewise. * linux-arm-low.c (arm_new_process): Likewise. (arm_new_thread): Likewise. * linux-low.c (add_to_pid_list): Likewise. (linux_add_process): Likewise. (handle_extended_wait): Likewise. (add_lwp): Likewise. (enqueue_one_deferred_signal): Likewise. (enqueue_pending_signal): Likewise. (linux_resume_one_lwp_throw): Likewise. (linux_resume_one_thread): Likewise. (linux_read_memory): Likewise. (linux_write_memory): Likewise. * linux-mips-low.c (mips_linux_new_process): Likewise. (mips_linux_new_thread): Likewise. (mips_add_watchpoint): Likewise. * linux-x86-low.c (initialize_low_arch): Likewise. * lynx-low.c (lynx_add_process): Likewise. * mem-break.c (set_raw_breakpoint_at): Likewise. (set_breakpoint): Likewise. (add_condition_to_breakpoint): Likewise. (add_commands_to_breakpoint): Likewise. (clone_agent_expr): Likewise. (clone_one_breakpoint): Likewise. * regcache.c (new_register_cache): Likewise. * remote-utils.c (look_up_one_symbol): Likewise. * server.c (queue_stop_reply): Likewise. (start_inferior): Likewise. (queue_stop_reply_callback): Likewise. (handle_target_event): Likewise. * spu-low.c (fetch_ppc_memory): Likewise. (store_ppc_memory): Likewise. * target.c (set_target_ops): Likewise. * thread-db.c (thread_db_load_search): Likewise. (try_thread_db_load_1): Likewise. * tracepoint.c (add_tracepoint): Likewise. (add_tracepoint_action): Likewise. (create_trace_state_variable): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtro): Likewise. (add_while_stepping_state): Likewise. * win32-low.c (child_add_thread): Likewise. (get_image_name): Likewise.
2015-08-26 23:16:07 +02:00
struct simple_pid_list *new_pid = XNEW (struct simple_pid_list);
new_pid->pid = pid;
new_pid->status = status;
new_pid->next = *listp;
*listp = new_pid;
}
static int
pull_pid_from_list (struct simple_pid_list **listp, int pid, int *statusp)
{
struct simple_pid_list **p;
for (p = listp; *p != NULL; p = &(*p)->next)
if ((*p)->pid == pid)
{
struct simple_pid_list *next = (*p)->next;
*statusp = (*p)->status;
xfree (*p);
*p = next;
return 1;
}
return 0;
}
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
/* Return the ptrace options that we want to try to enable. */
static int
linux_nat_ptrace_options (int attached)
{
int options = 0;
if (!attached)
options |= PTRACE_O_EXITKILL;
options |= (PTRACE_O_TRACESYSGOOD
| PTRACE_O_TRACEVFORKDONE
| PTRACE_O_TRACEVFORK
| PTRACE_O_TRACEFORK
| PTRACE_O_TRACEEXEC);
return options;
}
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
/* Initialize ptrace warnings and check for supported ptrace
[Linux] Ask kernel to kill inferior when GDB terminates This patch enhances GDB on GNU/Linux systems in the situation where we are debugging an inferior that was created from GDB (as opposed to attached to), by asking the kernel to kill the inferior if GDB terminates without doing it itself. This would typically happen when GDB encounters a problem and crashes, or when it gets killed by an external process. This can be observed by starting a program under GDB, and then killing GDB with signal 9. After GDB is killed, the inferior still remains. This patch also fixes GDBserver similarly. This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL feature. On older kernels, the behavior remains unchanged. gdb/ChangeLog: * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not already defined. (linux_enable_event_reporting): Add parameter "attached". * nat/linux-ptrace.c (linux_test_for_exitkill): New forward declaration. New function. (linux_check_ptrace_features): Add linux_test_for_exitkill call. (linux_enable_event_reporting): Add new parameter "attached". Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is nonzero. * linux-nat.c (linux_init_ptrace): Add parameter "attached". Use it. Update function description. (linux_child_post_attach, linux_child_post_startup_inferior): Update call to linux_enable_event_reporting. gdb/gdbserver/ChangeLog: * linux-low.c (linux_low_filter_event): Update call to linux_enable_event_reporting following the addition of a new parameter to that function. Tested on x86_64-linux, native and native-gdbserver. I also verified by hand that the inferior gets killed when killing GDB in the "run" case, while the inferior remains in the "attach" case. Same for GDBserver.
2014-11-11 07:07:21 +01:00
features given PID.
ATTACHED should be nonzero iff we attached to the inferior. */
static void
[Linux] Ask kernel to kill inferior when GDB terminates This patch enhances GDB on GNU/Linux systems in the situation where we are debugging an inferior that was created from GDB (as opposed to attached to), by asking the kernel to kill the inferior if GDB terminates without doing it itself. This would typically happen when GDB encounters a problem and crashes, or when it gets killed by an external process. This can be observed by starting a program under GDB, and then killing GDB with signal 9. After GDB is killed, the inferior still remains. This patch also fixes GDBserver similarly. This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL feature. On older kernels, the behavior remains unchanged. gdb/ChangeLog: * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not already defined. (linux_enable_event_reporting): Add parameter "attached". * nat/linux-ptrace.c (linux_test_for_exitkill): New forward declaration. New function. (linux_check_ptrace_features): Add linux_test_for_exitkill call. (linux_enable_event_reporting): Add new parameter "attached". Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is nonzero. * linux-nat.c (linux_init_ptrace): Add parameter "attached". Use it. Update function description. (linux_child_post_attach, linux_child_post_startup_inferior): Update call to linux_enable_event_reporting. gdb/gdbserver/ChangeLog: * linux-low.c (linux_low_filter_event): Update call to linux_enable_event_reporting following the addition of a new parameter to that function. Tested on x86_64-linux, native and native-gdbserver. I also verified by hand that the inferior gets killed when killing GDB in the "run" case, while the inferior remains in the "attach" case. Same for GDBserver.
2014-11-11 07:07:21 +01:00
linux_init_ptrace (pid_t pid, int attached)
{
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
int options = linux_nat_ptrace_options (attached);
linux_enable_event_reporting (pid, options);
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
linux_ptrace_init_warnings ();
}
static void
linux_child_post_attach (struct target_ops *self, int pid)
{
[Linux] Ask kernel to kill inferior when GDB terminates This patch enhances GDB on GNU/Linux systems in the situation where we are debugging an inferior that was created from GDB (as opposed to attached to), by asking the kernel to kill the inferior if GDB terminates without doing it itself. This would typically happen when GDB encounters a problem and crashes, or when it gets killed by an external process. This can be observed by starting a program under GDB, and then killing GDB with signal 9. After GDB is killed, the inferior still remains. This patch also fixes GDBserver similarly. This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL feature. On older kernels, the behavior remains unchanged. gdb/ChangeLog: * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not already defined. (linux_enable_event_reporting): Add parameter "attached". * nat/linux-ptrace.c (linux_test_for_exitkill): New forward declaration. New function. (linux_check_ptrace_features): Add linux_test_for_exitkill call. (linux_enable_event_reporting): Add new parameter "attached". Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is nonzero. * linux-nat.c (linux_init_ptrace): Add parameter "attached". Use it. Update function description. (linux_child_post_attach, linux_child_post_startup_inferior): Update call to linux_enable_event_reporting. gdb/gdbserver/ChangeLog: * linux-low.c (linux_low_filter_event): Update call to linux_enable_event_reporting following the addition of a new parameter to that function. Tested on x86_64-linux, native and native-gdbserver. I also verified by hand that the inferior gets killed when killing GDB in the "run" case, while the inferior remains in the "attach" case. Same for GDBserver.
2014-11-11 07:07:21 +01:00
linux_init_ptrace (pid, 1);
}
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
static void
linux_child_post_startup_inferior (struct target_ops *self, ptid_t ptid)
{
[Linux] Ask kernel to kill inferior when GDB terminates This patch enhances GDB on GNU/Linux systems in the situation where we are debugging an inferior that was created from GDB (as opposed to attached to), by asking the kernel to kill the inferior if GDB terminates without doing it itself. This would typically happen when GDB encounters a problem and crashes, or when it gets killed by an external process. This can be observed by starting a program under GDB, and then killing GDB with signal 9. After GDB is killed, the inferior still remains. This patch also fixes GDBserver similarly. This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL feature. On older kernels, the behavior remains unchanged. gdb/ChangeLog: * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not already defined. (linux_enable_event_reporting): Add parameter "attached". * nat/linux-ptrace.c (linux_test_for_exitkill): New forward declaration. New function. (linux_check_ptrace_features): Add linux_test_for_exitkill call. (linux_enable_event_reporting): Add new parameter "attached". Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is nonzero. * linux-nat.c (linux_init_ptrace): Add parameter "attached". Use it. Update function description. (linux_child_post_attach, linux_child_post_startup_inferior): Update call to linux_enable_event_reporting. gdb/gdbserver/ChangeLog: * linux-low.c (linux_low_filter_event): Update call to linux_enable_event_reporting following the addition of a new parameter to that function. Tested on x86_64-linux, native and native-gdbserver. I also verified by hand that the inferior gets killed when killing GDB in the "run" case, while the inferior remains in the "attach" case. Same for GDBserver.
2014-11-11 07:07:21 +01:00
linux_init_ptrace (ptid_get_pid (ptid), 0);
}
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
/* Return the number of known LWPs in the tgid given by PID. */
static int
num_lwps (int pid)
{
int count = 0;
struct lwp_info *lp;
for (lp = lwp_list; lp; lp = lp->next)
if (ptid_get_pid (lp->ptid) == pid)
count++;
return count;
}
/* Call delete_lwp with prototype compatible for make_cleanup. */
static void
delete_lwp_cleanup (void *lp_voidp)
{
Add some more casts (1/2) Note: I needed to split this patch in two, otherwise it's too big for the mailing list. This patch adds explicit casts to situations where a void pointer is assigned to a pointer to the "real" type. Building in C++ mode requires those assignments to use an explicit cast. This includes, for example: - callback arguments (cleanups, comparison functions, ...) - data attached to some object (objfile, program space, etc) in the form of a void pointer - "user data" passed to some function This patch comes from the commit "(mostly) auto-generated patch to insert casts needed for C++", taken from Pedro's C++ branch. Only files built on x86 with --enable-targets=all are modified, so the native files for other arches will need to be dealt with separately. I built-tested this with --enable-targets=all and reg-tested. To my surprise, a test case (selftest.exp) had to be adjusted. Here's the ChangeLog entry. Again, this was relatively quick to make despite the length, thanks to David Malcom's script, although I don't believe it's very useful information in that particular case... gdb/ChangeLog: * aarch64-tdep.c (aarch64_make_prologue_cache): Add cast(s). (aarch64_make_stub_cache): Likewise. (value_of_aarch64_user_reg): Likewise. * ada-lang.c (ada_inferior_data_cleanup): Likewise. (get_ada_inferior_data): Likewise. (get_ada_pspace_data): Likewise. (ada_pspace_data_cleanup): Likewise. (ada_complete_symbol_matcher): Likewise. (ada_exc_search_name_matches): Likewise. * ada-tasks.c (get_ada_tasks_pspace_data): Likewise. (get_ada_tasks_inferior_data): Likewise. * addrmap.c (addrmap_mutable_foreach_worker): Likewise. (splay_obstack_alloc): Likewise. (splay_obstack_free): Likewise. * alpha-linux-tdep.c (alpha_linux_supply_gregset): Likewise. (alpha_linux_collect_gregset): Likewise. (alpha_linux_supply_fpregset): Likewise. (alpha_linux_collect_fpregset): Likewise. * alpha-mdebug-tdep.c (alpha_mdebug_frame_unwind_cache): Likewise. * alpha-tdep.c (alpha_lds): Likewise. (alpha_sts): Likewise. (alpha_sigtramp_frame_unwind_cache): Likewise. (alpha_heuristic_frame_unwind_cache): Likewise. (alpha_supply_int_regs): Likewise. (alpha_fill_int_regs): Likewise. (alpha_supply_fp_regs): Likewise. (alpha_fill_fp_regs): Likewise. * alphanbsd-tdep.c (alphanbsd_supply_fpregset): Likewise. (alphanbsd_aout_supply_gregset): Likewise. (alphanbsd_supply_gregset): Likewise. * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise. (amd64_x32_linux_init_abi): Likewise. * amd64-nat.c (amd64_supply_native_gregset): Likewise. (amd64_collect_native_gregset): Likewise. * amd64-tdep.c (amd64_frame_cache): Likewise. (amd64_sigtramp_frame_cache): Likewise. (amd64_epilogue_frame_cache): Likewise. (amd64_supply_fxsave): Likewise. (amd64_supply_xsave): Likewise. (amd64_collect_fxsave): Likewise. (amd64_collect_xsave): Likewise. * amd64-windows-tdep.c (amd64_windows_frame_cache): Likewise. * amd64obsd-tdep.c (amd64obsd_trapframe_cache): Likewise. * arm-linux-tdep.c (arm_linux_supply_gregset): Likewise. (arm_linux_collect_gregset): Likewise. (arm_linux_supply_nwfpe): Likewise. (arm_linux_collect_nwfpe): Likewise. (arm_linux_supply_vfp): Likewise. (arm_linux_collect_vfp): Likewise. * arm-tdep.c (arm_find_mapping_symbol): Likewise. (arm_prologue_unwind_stop_reason): Likewise. (arm_prologue_this_id): Likewise. (arm_prologue_prev_register): Likewise. (arm_exidx_data_free): Likewise. (arm_find_exidx_entry): Likewise. (arm_stub_this_id): Likewise. (arm_m_exception_this_id): Likewise. (arm_m_exception_prev_register): Likewise. (arm_normal_frame_base): Likewise. (gdb_print_insn_arm): Likewise. (arm_objfile_data_free): Likewise. (arm_record_special_symbol): Likewise. (value_of_arm_user_reg): Likewise. * armbsd-tdep.c (armbsd_supply_fpregset): Likewise. (armbsd_supply_gregset): Likewise. * auto-load.c (auto_load_pspace_data_cleanup): Likewise. (get_auto_load_pspace_data): Likewise. (hash_loaded_script_entry): Likewise. (eq_loaded_script_entry): Likewise. (clear_section_scripts): Likewise. (collect_matching_scripts): Likewise. * auxv.c (auxv_inferior_data_cleanup): Likewise. (get_auxv_inferior_data): Likewise. * avr-tdep.c (avr_frame_unwind_cache): Likewise. * ax-general.c (do_free_agent_expr_cleanup): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. (target_bfd_xclose): Likewise. (target_bfd_get_section_table): Likewise. * bfin-tdep.c (bfin_frame_cache): Likewise. * block.c (find_block_in_blockvector): Likewise. (call_site_for_pc): Likewise. (block_find_non_opaque_type_preferred): Likewise. * break-catch-sig.c (signal_catchpoint_insert_location): Likewise. (signal_catchpoint_remove_location): Likewise. (signal_catchpoint_breakpoint_hit): Likewise. (signal_catchpoint_print_one): Likewise. (signal_catchpoint_print_mention): Likewise. (signal_catchpoint_print_recreate): Likewise. * break-catch-syscall.c (get_catch_syscall_inferior_data): Likewise. * breakpoint.c (do_cleanup_counted_command_line): Likewise. (bp_location_compare_addrs): Likewise. (get_first_locp_gte_addr): Likewise. (check_tracepoint_command): Likewise. (do_map_commands_command): Likewise. (get_breakpoint_objfile_data): Likewise. (free_breakpoint_probes): Likewise. (do_captured_breakpoint_query): Likewise. (compare_breakpoints): Likewise. (bp_location_compare): Likewise. (bpstat_remove_breakpoint_callback): Likewise. (do_delete_breakpoint_cleanup): Likewise. * bsd-uthread.c (bsd_uthread_set_supply_uthread): Likewise. (bsd_uthread_set_collect_uthread): Likewise. (bsd_uthread_activate): Likewise. (bsd_uthread_fetch_registers): Likewise. (bsd_uthread_store_registers): Likewise. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt_raw): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. (do_btrace_data_cleanup): Likewise. * c-typeprint.c (find_typedef_for_canonicalize): Likewise. * charset.c (cleanup_iconv): Likewise. (do_cleanup_iterator): Likewise. * cli-out.c (cli_uiout_dtor): Likewise. (cli_table_begin): Likewise. (cli_table_body): Likewise. (cli_table_end): Likewise. (cli_table_header): Likewise. (cli_begin): Likewise. (cli_end): Likewise. (cli_field_int): Likewise. (cli_field_skip): Likewise. (cli_field_string): Likewise. (cli_field_fmt): Likewise. (cli_spaces): Likewise. (cli_text): Likewise. (cli_message): Likewise. (cli_wrap_hint): Likewise. (cli_flush): Likewise. (cli_redirect): Likewise. (out_field_fmt): Likewise. (field_separator): Likewise. (cli_out_set_stream): Likewise. * cli/cli-cmds.c (compare_symtabs): Likewise. * cli/cli-dump.c (call_dump_func): Likewise. (restore_section_callback): Likewise. * cli/cli-script.c (clear_hook_in_cleanup): Likewise. (do_restore_user_call_depth): Likewise. (do_free_command_lines_cleanup): Likewise. * coff-pe-read.c (get_section_vmas): Likewise. (pe_as16): Likewise. (pe_as32): Likewise. * coffread.c (coff_symfile_read): Likewise. * common/agent.c (agent_look_up_symbols): Likewise. * common/filestuff.c (do_close_cleanup): Likewise. * common/format.c (free_format_pieces_cleanup): Likewise. * common/vec.c (vec_o_reserve): Likewise. * compile/compile-c-support.c (print_one_macro): Likewise. * compile/compile-c-symbols.c (hash_symbol_error): Likewise. (eq_symbol_error): Likewise. (del_symbol_error): Likewise. (error_symbol_once): Likewise. (gcc_convert_symbol): Likewise. (gcc_symbol_address): Likewise. (hash_symname): Likewise. (eq_symname): Likewise. * compile/compile-c-types.c (hash_type_map_instance): Likewise. (eq_type_map_instance): Likewise. (insert_type): Likewise. (convert_type): Likewise. * compile/compile-object-load.c (munmap_listp_free_cleanup): Likewise. (setup_sections): Likewise. (link_hash_table_free): Likewise. (copy_sections): Likewise. * compile/compile-object-run.c (do_module_cleanup): Likewise. * compile/compile.c (compile_print_value): Likewise. (do_rmdir): Likewise. (cleanup_compile_instance): Likewise. (cleanup_unlink_file): Likewise. * completer.c (free_completion_tracker): Likewise. * corelow.c (add_to_spuid_list): Likewise. * cp-namespace.c (reset_directive_searched): Likewise. * cp-support.c (reset_directive_searched): Likewise. * cris-tdep.c (cris_sigtramp_frame_unwind_cache): Likewise. (cris_frame_unwind_cache): Likewise. * d-lang.c (builtin_d_type): Likewise. * d-namespace.c (reset_directive_searched): Likewise. * dbxread.c (dbx_free_symfile_info): Likewise. (do_free_bincl_list_cleanup): Likewise. * disasm.c (hash_dis_line_entry): Likewise. (eq_dis_line_entry): Likewise. (dis_asm_print_address): Likewise. (fprintf_disasm): Likewise. (do_ui_file_delete): Likewise. * doublest.c (convert_floatformat_to_doublest): Likewise. * dummy-frame.c (pop_dummy_frame_bpt): Likewise. (dummy_frame_prev_register): Likewise. (dummy_frame_this_id): Likewise. * dwarf2-frame-tailcall.c (cache_hash): Likewise. (cache_eq): Likewise. (cache_find): Likewise. (tailcall_frame_this_id): Likewise. (dwarf2_tailcall_prev_register_first): Likewise. (tailcall_frame_prev_register): Likewise. (tailcall_frame_dealloc_cache): Likewise. (tailcall_frame_prev_arch): Likewise. * dwarf2-frame.c (dwarf2_frame_state_free): Likewise. (dwarf2_frame_set_init_reg): Likewise. (dwarf2_frame_init_reg): Likewise. (dwarf2_frame_set_signal_frame_p): Likewise. (dwarf2_frame_signal_frame_p): Likewise. (dwarf2_frame_set_adjust_regnum): Likewise. (dwarf2_frame_adjust_regnum): Likewise. (clear_pointer_cleanup): Likewise. (dwarf2_frame_cache): Likewise. (find_cie): Likewise. (dwarf2_frame_find_fde): Likewise. * dwarf2expr.c (dwarf_expr_address_type): Likewise. (free_dwarf_expr_context_cleanup): Likewise. * dwarf2loc.c (locexpr_find_frame_base_location): Likewise. (locexpr_get_frame_base): Likewise. (loclist_find_frame_base_location): Likewise. (loclist_get_frame_base): Likewise. (dwarf_expr_dwarf_call): Likewise. (dwarf_expr_get_base_type): Likewise. (dwarf_expr_push_dwarf_reg_entry_value): Likewise. (dwarf_expr_get_obj_addr): Likewise. (entry_data_value_coerce_ref): Likewise. (entry_data_value_copy_closure): Likewise. (entry_data_value_free_closure): Likewise. (get_frame_address_in_block_wrapper): Likewise. (dwarf2_evaluate_property): Likewise. (dwarf2_compile_property_to_c): Likewise. (needs_frame_read_addr_from_reg): Likewise. (needs_frame_get_reg_value): Likewise. (needs_frame_frame_base): Likewise. (needs_frame_frame_cfa): Likewise. (needs_frame_tls_address): Likewise. (needs_frame_dwarf_call): Likewise. (needs_dwarf_reg_entry_value): Likewise. (get_ax_pc): Likewise. (locexpr_read_variable): Likewise. (locexpr_read_variable_at_entry): Likewise. (locexpr_read_needs_frame): Likewise. (locexpr_describe_location): Likewise. (locexpr_tracepoint_var_ref): Likewise. (locexpr_generate_c_location): Likewise. (loclist_read_variable): Likewise. (loclist_read_variable_at_entry): Likewise. (loclist_describe_location): Likewise. (loclist_tracepoint_var_ref): Likewise. (loclist_generate_c_location): Likewise. * dwarf2read.c (line_header_hash_voidp): Likewise. (line_header_eq_voidp): Likewise. (dwarf2_has_info): Likewise. (dwarf2_get_section_info): Likewise. (locate_dwz_sections): Likewise. (hash_file_name_entry): Likewise. (eq_file_name_entry): Likewise. (delete_file_name_entry): Likewise. (dw2_setup): Likewise. (dw2_get_file_names_reader): Likewise. (dw2_find_pc_sect_compunit_symtab): Likewise. (hash_signatured_type): Likewise. (eq_signatured_type): Likewise. (add_signatured_type_cu_to_table): Likewise. (create_debug_types_hash_table): Likewise. (lookup_dwo_signatured_type): Likewise. (lookup_dwp_signatured_type): Likewise. (lookup_signatured_type): Likewise. (hash_type_unit_group): Likewise. (eq_type_unit_group): Likewise. (get_type_unit_group): Likewise. (process_psymtab_comp_unit_reader): Likewise. (sort_tu_by_abbrev_offset): Likewise. (process_skeletonless_type_unit): Likewise. (psymtabs_addrmap_cleanup): Likewise. (dwarf2_read_symtab): Likewise. (psymtab_to_symtab_1): Likewise. (die_hash): Likewise. (die_eq): Likewise. (load_full_comp_unit_reader): Likewise. (reset_die_in_process): Likewise. (free_cu_line_header): Likewise. (handle_DW_AT_stmt_list): Likewise. (hash_dwo_file): Likewise. (eq_dwo_file): Likewise. (hash_dwo_unit): Likewise. (eq_dwo_unit): Likewise. (create_dwo_cu_reader): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (lookup_dwo_unit_in_dwp): Likewise. (dwarf2_locate_dwo_sections): Likewise. (dwarf2_locate_common_dwp_sections): Likewise. (dwarf2_locate_v2_dwp_sections): Likewise. (hash_dwp_loaded_cutus): Likewise. (eq_dwp_loaded_cutus): Likewise. (lookup_dwo_cutu): Likewise. (abbrev_table_free_cleanup): Likewise. (dwarf2_free_abbrev_table): Likewise. (find_partial_die_in_comp_unit): Likewise. (free_line_header_voidp): Likewise. (follow_die_offset): Likewise. (follow_die_sig_1): Likewise. (free_heap_comp_unit): Likewise. (free_stack_comp_unit): Likewise. (dwarf2_free_objfile): Likewise. (per_cu_offset_and_type_hash): Likewise. (per_cu_offset_and_type_eq): Likewise. (get_die_type_at_offset): Likewise. (partial_die_hash): Likewise. (partial_die_eq): Likewise. (dwarf2_per_objfile_free): Likewise. (hash_strtab_entry): Likewise. (eq_strtab_entry): Likewise. (add_string): Likewise. (hash_symtab_entry): Likewise. (eq_symtab_entry): Likewise. (delete_symtab_entry): Likewise. (cleanup_mapped_symtab): Likewise. (add_indices_to_cpool): Likewise. (hash_psymtab_cu_index): Likewise. (eq_psymtab_cu_index): Likewise. (add_address_entry_worker): Likewise. (unlink_if_set): Likewise. (write_one_signatured_type): Likewise. (save_gdb_index_command): Likewise. * elfread.c (elf_symtab_read): Likewise. (elf_gnu_ifunc_cache_hash): Likewise. (elf_gnu_ifunc_cache_eq): Likewise. (elf_gnu_ifunc_record_cache): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_get_probes): Likewise. (probe_key_free): Likewise. * f-lang.c (builtin_f_type): Likewise. * frame-base.c (frame_base_append_sniffer): Likewise. (frame_base_set_default): Likewise. (frame_base_find_by_frame): Likewise. * frame-unwind.c (frame_unwind_prepend_unwinder): Likewise. (frame_unwind_append_unwinder): Likewise. (frame_unwind_find_by_frame): Likewise. * frame.c (frame_addr_hash): Likewise. (frame_addr_hash_eq): Likewise. (frame_stash_find): Likewise. (do_frame_register_read): Likewise. (unwind_to_current_frame): Likewise. (frame_cleanup_after_sniffer): Likewise. * frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise. * frv-tdep.c (frv_frame_unwind_cache): Likewise. * ft32-tdep.c (ft32_frame_cache): Likewise. * gcore.c (do_bfd_delete_cleanup): Likewise. (gcore_create_callback): Likewise. * gdb_bfd.c (hash_bfd): Likewise. (eq_bfd): Likewise. (gdb_bfd_open): Likewise. (free_one_bfd_section): Likewise. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (get_section_descriptor): Likewise. (gdb_bfd_map_section): Likewise. (gdb_bfd_crc): Likewise. (gdb_bfd_mark_parent): Likewise. (gdb_bfd_record_inclusion): Likewise. (gdb_bfd_requires_relocations): Likewise. (print_one_bfd): Likewise. * gdbtypes.c (type_pair_hash): Likewise. (type_pair_eq): Likewise. (builtin_type): Likewise. (objfile_type): Likewise. * gnu-v3-abi.c (vtable_ptrdiff_type): Likewise. (vtable_address_point_offset): Likewise. (gnuv3_get_vtable): Likewise. (hash_value_and_voffset): Likewise. (eq_value_and_voffset): Likewise. (compare_value_and_voffset): Likewise. (compute_vtable_size): Likewise. (gnuv3_get_typeid_type): Likewise. * go-lang.c (builtin_go_type): Likewise. * guile/scm-block.c (bkscm_hash_block_smob): Likewise. (bkscm_eq_block_smob): Likewise. (bkscm_objfile_block_map): Likewise. (bkscm_del_objfile_blocks): Likewise. * guile/scm-breakpoint.c (bpscm_build_bp_list): Likewise. * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): Likewise. (gdbscm_disasm_print_address): Likewise. * guile/scm-frame.c (frscm_hash_frame_smob): Likewise. (frscm_eq_frame_smob): Likewise. (frscm_inferior_frame_map): Likewise. (frscm_del_inferior_frames): Likewise. * guile/scm-gsmob.c (gdbscm_add_objfile_ref): Likewise. * guile/scm-objfile.c (ofscm_handle_objfile_deleted): Likewise. (ofscm_objfile_smob_from_objfile): Likewise. * guile/scm-ports.c (ioscm_write): Likewise. (ioscm_file_port_delete): Likewise. (ioscm_file_port_rewind): Likewise. (ioscm_file_port_put): Likewise. (ioscm_file_port_write): Likewise. * guile/scm-progspace.c (psscm_handle_pspace_deleted): Likewise. (psscm_pspace_smob_from_pspace): Likewise. * guile/scm-safe-call.c (scscm_recording_pre_unwind_handler): Likewise. (scscm_recording_unwind_handler): Likewise. (gdbscm_with_catch): Likewise. (scscm_call_0_body): Likewise. (scscm_call_1_body): Likewise. (scscm_call_2_body): Likewise. (scscm_call_3_body): Likewise. (scscm_call_4_body): Likewise. (scscm_apply_1_body): Likewise. (scscm_eval_scheme_string): Likewise. (gdbscm_safe_eval_string): Likewise. (scscm_source_scheme_script): Likewise. (gdbscm_safe_source_script): Likewise. * guile/scm-string.c (gdbscm_call_scm_to_stringn): Likewise. (gdbscm_call_scm_from_stringn): Likewise. * guile/scm-symbol.c (syscm_hash_symbol_smob): Likewise. (syscm_eq_symbol_smob): Likewise. (syscm_get_symbol_map): Likewise. (syscm_del_objfile_symbols): Likewise. * guile/scm-symtab.c (stscm_hash_symtab_smob): Likewise. (stscm_eq_symtab_smob): Likewise. (stscm_objfile_symtab_map): Likewise. (stscm_del_objfile_symtabs): Likewise. * guile/scm-type.c (tyscm_hash_type_smob): Likewise. (tyscm_eq_type_smob): Likewise. (tyscm_type_map): Likewise. (tyscm_copy_type_recursive): Likewise. (save_objfile_types): Likewise. * guile/scm-utils.c (extract_arg): Likewise. * h8300-tdep.c (h8300_frame_cache): Likewise. * hppa-linux-tdep.c (hppa_linux_sigtramp_frame_unwind_cache): Likewise. * hppa-tdep.c (compare_unwind_entries): Likewise. (find_unwind_entry): Likewise. (hppa_frame_cache): Likewise. (hppa_stub_frame_unwind_cache): Likewise. * hppanbsd-tdep.c (hppanbsd_supply_gregset): Likewise. * hppaobsd-tdep.c (hppaobsd_supply_gregset): Likewise. (hppaobsd_supply_fpregset): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * i386-tdep.c (i386_frame_cache): Likewise. (i386_epilogue_frame_cache): Likewise. (i386_sigtramp_frame_cache): Likewise. (i386_supply_gregset): Likewise. (i386_collect_gregset): Likewise. (i386_gdbarch_init): Likewise. * i386obsd-tdep.c (i386obsd_aout_supply_regset): Likewise. (i386obsd_trapframe_cache): Likewise. * i387-tdep.c (i387_supply_fsave): Likewise. (i387_collect_fsave): Likewise. (i387_supply_fxsave): Likewise. (i387_collect_fxsave): Likewise. (i387_supply_xsave): Likewise. (i387_collect_xsave): Likewise. * ia64-tdep.c (ia64_frame_cache): Likewise. (ia64_sigtramp_frame_cache): Likewise. * infcmd.c (attach_command_continuation): Likewise. (attach_command_continuation_free_args): Likewise. * inferior.c (restore_inferior): Likewise. (delete_thread_of_inferior): Likewise. * inflow.c (inflow_inferior_data_cleanup): Likewise. (get_inflow_inferior_data): Likewise. (inflow_inferior_exit): Likewise. * infrun.c (displaced_step_clear_cleanup): Likewise. (restore_current_uiout_cleanup): Likewise. (release_stop_context_cleanup): Likewise. (do_restore_infcall_suspend_state_cleanup): Likewise. (do_restore_infcall_control_state_cleanup): Likewise. (restore_inferior_ptid): Likewise. * inline-frame.c (block_starting_point_at): Likewise. * iq2000-tdep.c (iq2000_frame_cache): Likewise. * jit.c (get_jit_objfile_data): Likewise. (get_jit_program_space_data): Likewise. (jit_object_close_impl): Likewise. (jit_find_objf_with_entry_addr): Likewise. (jit_breakpoint_deleted): Likewise. (jit_unwind_reg_set_impl): Likewise. (jit_unwind_reg_get_impl): Likewise. (jit_dealloc_cache): Likewise. (jit_frame_sniffer): Likewise. (jit_frame_prev_register): Likewise. (jit_prepend_unwinder): Likewise. (jit_inferior_exit_hook): Likewise. (free_objfile_data): Likewise. * jv-lang.c (jv_per_objfile_free): Likewise. (get_dynamics_objfile): Likewise. (get_java_class_symtab): Likewise. (builtin_java_type): Likewise. * language.c (language_string_char_type): Likewise. (language_bool_type): Likewise. (language_lookup_primitive_type): Likewise. (language_lookup_primitive_type_as_symbol): Likewise. * linespec.c (hash_address_entry): Likewise. (eq_address_entry): Likewise. (iterate_inline_only): Likewise. (iterate_name_matcher): Likewise. (decode_line_2_compare_items): Likewise. (collect_one_symbol): Likewise. (compare_symbols): Likewise. (compare_msymbols): Likewise. (add_symtabs_to_list): Likewise. (collect_symbols): Likewise. (compare_msyms): Likewise. (add_minsym): Likewise. (cleanup_linespec_result): Likewise. * linux-fork.c (inferior_call_waitpid_cleanup): Likewise. * linux-nat.c (delete_lwp_cleanup): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (resume_stopped_resumed_lwps): Likewise. * linux-tdep.c (get_linux_gdbarch_data): Likewise. (invalidate_linux_cache_inf): Likewise. (get_linux_inferior_data): Likewise. (linux_find_memory_regions_thunk): Likewise. (linux_make_mappings_callback): Likewise. (linux_corefile_thread_callback): Likewise. (find_mapping_size): Likewise. * linux-thread-db.c (find_new_threads_callback): Likewise. * lm32-tdep.c (lm32_frame_cache): Likewise. * m2-lang.c (builtin_m2_type): Likewise. * m32c-tdep.c (m32c_analyze_frame_prologue): Likewise. * m32r-linux-tdep.c (m32r_linux_sigtramp_frame_cache): Likewise. (m32r_linux_supply_gregset): Likewise. (m32r_linux_collect_gregset): Likewise. * m32r-tdep.c (m32r_frame_unwind_cache): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * m68k-tdep.c (m68k_frame_cache): Likewise. * m68kbsd-tdep.c (m68kbsd_supply_fpregset): Likewise. (m68kbsd_supply_gregset): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise. * m88k-tdep.c (m88k_frame_cache): Likewise. (m88k_supply_gregset): Likewise. gdb/gdbserver/ChangeLog: * dll.c (match_dll): Add cast(s). (unloaded_dll): Likewise. * linux-low.c (second_thread_of_pid_p): Likewise. (delete_lwp_callback): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (linux_set_resume_request): Likewise. * server.c (accumulate_file_name_length): Likewise. (emit_dll_description): Likewise. (handle_qxfer_threads_worker): Likewise. (visit_actioned_threads): Likewise. * thread-db.c (any_thread_of): Likewise. * tracepoint.c (same_process_p): Likewise. (match_blocktype): Likewise. (build_traceframe_info_xml): Likewise. gdb/testsuite/ChangeLog: * gdb.gdb/selftest.exp (do_steps_and_nexts): Adjust expected source line.
2015-09-25 20:08:07 +02:00
struct lwp_info *lp = (struct lwp_info *) lp_voidp;
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
delete_lwp (lp->ptid);
}
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
/* Target hook for follow_fork. On entry inferior_ptid must be the
ptid of the followed inferior. At return, inferior_ptid will be
unchanged. */
static int
linux_child_follow_fork (struct target_ops *ops, int follow_child,
int detach_fork)
{
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
if (!follow_child)
{
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
struct lwp_info *child_lp = NULL;
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
int status = W_STOPCODE (0);
struct cleanup *old_chain;
int has_vforked;
ptid_t parent_ptid, child_ptid;
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
int parent_pid, child_pid;
has_vforked = (inferior_thread ()->pending_follow.kind
== TARGET_WAITKIND_VFORKED);
parent_ptid = inferior_ptid;
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
parent_pid = ptid_get_lwp (parent_ptid);
child_pid = ptid_get_lwp (child_ptid);
/* We're already attached to the parent, by default. */
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
old_chain = save_inferior_ptid ();
inferior_ptid = child_ptid;
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
child_lp = add_lwp (inferior_ptid);
child_lp->stopped = 1;
child_lp->last_resume_kind = resume_stop;
/* Detach new forked process? */
if (detach_fork)
{
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
make_cleanup (delete_lwp_cleanup, child_lp);
if (linux_nat_prepare_to_resume != NULL)
linux_nat_prepare_to_resume (child_lp);
/* When debugging an inferior in an architecture that supports
hardware single stepping on a kernel without commit
6580807da14c423f0d0a708108e6df6ebc8bc83d, the vfork child
process starts with the TIF_SINGLESTEP/X86_EFLAGS_TF bits
set if the parent process had them set.
To work around this, single step the child process
once before detaching to clear the flags. */
if (!gdbarch_software_single_step_p (target_thread_architecture
(child_lp->ptid)))
{
linux_disable_event_reporting (child_pid);
if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0)
perror_with_name (_("Couldn't do single step"));
if (my_waitpid (child_pid, &status, 0) < 0)
perror_with_name (_("Couldn't wait vfork process"));
}
if (WIFSTOPPED (status))
Fix a bunch of fork related regressions. I'm seeing a ton of new FAILs in fork-related tests. Like, these and many more: +FAIL: gdb.base/disp-step-syscall.exp: vfork: continue to vfork (2nd time) (timeout) +FAIL: gdb.base/disp-step-syscall.exp: vfork: display/i $pc (timeout) ... -PASS: gdb.base/foll-vfork.exp: exec: vfork parent follow, through step: step +FAIL: gdb.base/foll-vfork.exp: exec: vfork parent follow, through step: step (timeout) -PASS: gdb.base/foll-vfork.exp: exec: vfork parent follow, to bp: continue to bp +FAIL: gdb.base/foll-vfork.exp: exec: vfork parent follow, to bp: continue to bp (timeout) ... FAIL: gdb.threads/watchpoint-fork.exp: parent: multithreaded: breakpoint (A) after the first fork (timeout) FAIL: gdb.threads/watchpoint-fork.exp: parent: multithreaded: watchpoint A after the first fork (timeout) FAIL: gdb.base/fileio.exp: System(3) call (timeout) FAIL: gdb.threads/watchpoint-fork.exp: parent: multithreaded: watchpoint B after the first fork (timeout) -PASS: gdb.base/multi-forks.exp: run to exit 2 +FAIL: gdb.base/multi-forks.exp: run to exit 2 (timeout) ... PASS: gdb.base/watch-vfork.exp: Watchpoint on global variable (hw) -PASS: gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (hw) +FAIL: gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (hw) (timeout) PASS: gdb.base/watch-vfork.exp: Watchpoint on global variable (sw) -PASS: gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) +FAIL: gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) Three issues with https://sourceware.org/ml/gdb-patches/2014-06/msg00348.html (c077881a). - The inner 'status' local is shadowing the outer 'status' local, thus PTRACE_DETACH is never seeing the status it intends to pass on the inferior. - With that fixed, we then try to pass down the SIGTRAP that results from the step to the inferior. Need to filter out signals that are in nopass state. - For software single-step archs, the current code is equivalent to: int status = 0; if (WIFSTOPPED (status)) ptrace (PTRACE_DETACH, child_pid, 0, WSTOPSIG (status)); ... and status == 0 is WIFEXITED, not WIFSTOPPED, so we're never detaching. gdb/ 2014-06-09 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_child_follow_fork): Initialize status with W_STOPCODE (0) instead of 0. Remove shodowing 'status' local from inner block. Only pass the signal to PTRACE_DETACH if in pass state.
2014-06-09 15:53:51 +02:00
{
int signo;
signo = WSTOPSIG (status);
if (signo != 0
&& !signal_pass_state (gdb_signal_from_host (signo)))
signo = 0;
ptrace (PTRACE_DETACH, child_pid, 0, signo);
}
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
/* Resets value of inferior_ptid to parent ptid. */
gdb/ Fix watchpoints across inferior fork. * amd64-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (amd64_linux_prepare_to_resume): New comment on Linux kernel. * i386-linux-nat.c (update_debug_registers_callback): Update the comment for linux_nat_iterate_watchpoint_lwps. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use linux_nat_iterate_watchpoint_lwps. (i386_linux_prepare_to_resume): New comment on Linux kernel. * i386-nat.c: Include inferior.h. (dr_mirror): Remove. (i386_inferior_data, struct i386_inferior_data) (i386_inferior_data_get): New. (i386_debug_reg_state): Use i386_inferior_data_get. (i386_cleanup_dregs, i386_update_inferior_debug_regs) (i386_insert_watchpoint, i386_remove_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): New variable state, use i386_debug_reg_state instead of DR_MIRROR. * linux-nat.c (delete_lwp): New declaration. (num_lwps): Move here from downwards. (delete_lwp_cleanup): New. (linux_child_follow_fork): Create new child_lp, call linux_nat_new_thread and linux_nat_prepare_to_resume before calling PTRACE_DETACH. (num_lwps): Move upwards. (linux_nat_iterate_watchpoint_lwps): New. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): New. (linux_nat_iterate_watchpoint_lwps_ftype): New declaration. gdb/testsuite/ Fix watchpoints across inferior fork. * gdb.threads/watchpoint-fork-child.c: New file. * gdb.threads/watchpoint-fork-mt.c: New file. * gdb.threads/watchpoint-fork-parent.c: New file. * gdb.threads/watchpoint-fork-st.c: New file. * gdb.threads/watchpoint-fork.exp: New file. * gdb.threads/watchpoint-fork.h: New file.
2012-01-24 14:46:55 +01:00
do_cleanups (old_chain);
}
else
{
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Let the thread_db layer learn about this new process. */
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
check_for_thread_db ();
}
Refactor native follow-fork. This patch reorganizes the code that implements follow-fork and detach-on-fork in preparation for implementation of those features for the extended-remote target. The function linux-nat.c:linux_child_follow_fork contained target-independent code mixed in with target-dependent code. The target-independent pieces need to be accessible for the host-side implementation of follow-fork for extended-remote Linux targets. The changes are fairly mechanical. A new routine, follow_fork_inferior, is implemented in infrun.c, containing those parts of linux_child_follow_fork that manage inferiors and the inferior list. The parts of linux_child_follow_fork that deal with LWPs and target-specifics were left in-place. Although the order of some operations was changed, the resulting functionality was not. Modifications were made to the other native target follow-fork functions, inf_ttrace_follow_fork and inf_ptrace_follow_fork, that should allow them to work with follow_fork_inferior. Some other adjustments were necessary in inf-ttrace.c. The changes to inf-ttrace.c and inf-ptrace.c were not tested. gdb/ChangeLog: * inf-ptrace.c (inf_ptrace_follow_fork): Remove target-independent code so as to work with follow_fork_inferior. * inf-ttrace.c (inf_ttrace_follow_fork): Ditto. (inf_ttrace_create_inferior): Remove reference to inf_ttrace_vfork_ppid. (inf_ttrace_attach): Ditto. (inf_ttrace_detach): Ditto. (inf_ttrace_kill): Use current_inferior instead of inf_ttrace_vfork_ppid. (inf_ttrace_wait): Eliminate use of inf_ttrace_vfork_ppid, report TARGET_WAITKIND_VFORK_DONE event, delete HACK that switched the inferior away from the parent. * infrun.c (follow_fork): Call follow_fork_inferior instead of target_follow_fork. (follow_fork_inferior): New function. (follow_inferior_reset_breakpoints): Make function static. * infrun.h (follow_inferior_reset_breakpoints): Remove declaration. * linux-nat.c (linux_child_follow_fork): Move target-independent code to infrun.c:follow_fork_inferior.
2014-09-30 20:01:57 +02:00
do_cleanups (old_chain);
if (has_vforked)
{
struct lwp_info *parent_lp;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
parent_lp = find_lwp_pid (parent_ptid);
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
gdb_assert (linux_supports_tracefork () >= 0);
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
if (linux_supports_tracevforkdone ())
{
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LCFF: waiting for VFORK_DONE on %d\n",
parent_pid);
parent_lp->stopped = 1;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* We'll handle the VFORK_DONE event like any other
event, in target_wait. */
}
else
{
/* We can't insert breakpoints until the child has
finished with the shared memory region. We need to
wait until that happens. Ideal would be to just
call:
- ptrace (PTRACE_SYSCALL, parent_pid, 0, 0);
- waitpid (parent_pid, &status, __WALL);
However, most architectures can't handle a syscall
being traced on the way out if it wasn't traced on
the way in.
We might also think to loop, continuing the child
until it exits or gets a SIGTRAP. One problem is
that the child might call ptrace with PTRACE_TRACEME.
There's no simple and reliable way to figure out when
the vforked child will be done with its copy of the
shared memory. We could step it out of the syscall,
two instructions, let it go, and then single-step the
parent once. When we have hardware single-step, this
would work; with software single-step it could still
be made to work but we'd have to be able to insert
single-step breakpoints in the child, and we'd have
to insert -just- the single-step breakpoint in the
parent. Very awkward.
In the end, the best we can do is to make sure it
runs for a little while. Hopefully it will be out of
range of any breakpoints we reinsert. Usually this
is only the single-step breakpoint at vfork's return
point. */
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
"LCFF: no VFORK_DONE "
"support, sleeping a bit\n");
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
usleep (10000);
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Pretend we've seen a PTRACE_EVENT_VFORK_DONE event,
and leave it pending. The next linux_nat_resume call
will notice a pending event, and bypasses actually
resuming the inferior. */
parent_lp->status = 0;
parent_lp->waitstatus.kind = TARGET_WAITKIND_VFORK_DONE;
parent_lp->stopped = 1;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* If we're in async mode, need to tell the event loop
there's something here to process. */
if (target_is_async_p ())
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
async_file_mark ();
}
}
}
else
{
struct lwp_info *child_lp;
child_lp = add_lwp (inferior_ptid);
child_lp->stopped = 1;
child_lp->last_resume_kind = resume_stop;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Let the thread_db layer learn about this new process. */
check_for_thread_db ();
}
return 0;
}
2010-01-11 Thiago Jung Bauermann <bauerman@br.ibm.com> Convert hardware watchpoints to use breakpoint_ops. gdb/ * breakpoint.h (breakpoint_ops) <insert>: Rename to... <insert_location>: ... this. Return int instead of void. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. (breakpoint_ops) <remove>: Rename to... <remove_location>: ... this. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. * breakpoint.c (insert_catchpoint): Delete function. (insert_bp_location): Call the watchpoint or catchpoint's breakpoint_ops.insert method. (remove_breakpoint_1): Call the watchpoint or catchpoint's breakpoint_ops.remove method. (insert_watchpoint, remove_watchpoint): New functions. (watchpoint_breakpoint_ops): New structure. (watch_command_1): Initialize the OPS field. * inf-child.c (inf_child_insert_fork_catchpoint) (inf_child_remove_fork_catchpoint, inf_child_insert_vfork_catchpoint) (inf_child_remove_vfork_catchpoint, inf_child_insert_exec_catchpoint) (inf_child_remove_exec_catchpoint, inf_child_set_syscall_catchpoint): Delete functions. (inf_child_target): Remove initialization of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint. * target.c (update_current_target): Change default implementation of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint to return_one. (debug_to_insert_fork_catchpoint, debug_to_insert_vfork_catchpoint) (debug_to_insert_exec_catchpoint): Report return value. * target.h (to_insert_fork_catchpoint, to_insert_vfork_catchpoint) (to_insert_exec_catchpoint): Change declaration to return int instead of void. gdb/testsuite/ * gdb.base/foll-exec.exp: Adapt to new error string when the catchpoint type is not supported. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise.
2011-01-11 20:16:23 +01:00
static int
linux_child_insert_fork_catchpoint (struct target_ops *self, int pid)
{
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
return !linux_supports_tracefork ();
}
static int
linux_child_remove_fork_catchpoint (struct target_ops *self, int pid)
{
return 0;
}
2010-01-11 Thiago Jung Bauermann <bauerman@br.ibm.com> Convert hardware watchpoints to use breakpoint_ops. gdb/ * breakpoint.h (breakpoint_ops) <insert>: Rename to... <insert_location>: ... this. Return int instead of void. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. (breakpoint_ops) <remove>: Rename to... <remove_location>: ... this. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. * breakpoint.c (insert_catchpoint): Delete function. (insert_bp_location): Call the watchpoint or catchpoint's breakpoint_ops.insert method. (remove_breakpoint_1): Call the watchpoint or catchpoint's breakpoint_ops.remove method. (insert_watchpoint, remove_watchpoint): New functions. (watchpoint_breakpoint_ops): New structure. (watch_command_1): Initialize the OPS field. * inf-child.c (inf_child_insert_fork_catchpoint) (inf_child_remove_fork_catchpoint, inf_child_insert_vfork_catchpoint) (inf_child_remove_vfork_catchpoint, inf_child_insert_exec_catchpoint) (inf_child_remove_exec_catchpoint, inf_child_set_syscall_catchpoint): Delete functions. (inf_child_target): Remove initialization of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint. * target.c (update_current_target): Change default implementation of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint to return_one. (debug_to_insert_fork_catchpoint, debug_to_insert_vfork_catchpoint) (debug_to_insert_exec_catchpoint): Report return value. * target.h (to_insert_fork_catchpoint, to_insert_vfork_catchpoint) (to_insert_exec_catchpoint): Change declaration to return int instead of void. gdb/testsuite/ * gdb.base/foll-exec.exp: Adapt to new error string when the catchpoint type is not supported. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise.
2011-01-11 20:16:23 +01:00
static int
linux_child_insert_vfork_catchpoint (struct target_ops *self, int pid)
{
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
return !linux_supports_tracefork ();
}
static int
linux_child_remove_vfork_catchpoint (struct target_ops *self, int pid)
{
return 0;
}
2010-01-11 Thiago Jung Bauermann <bauerman@br.ibm.com> Convert hardware watchpoints to use breakpoint_ops. gdb/ * breakpoint.h (breakpoint_ops) <insert>: Rename to... <insert_location>: ... this. Return int instead of void. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. (breakpoint_ops) <remove>: Rename to... <remove_location>: ... this. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. * breakpoint.c (insert_catchpoint): Delete function. (insert_bp_location): Call the watchpoint or catchpoint's breakpoint_ops.insert method. (remove_breakpoint_1): Call the watchpoint or catchpoint's breakpoint_ops.remove method. (insert_watchpoint, remove_watchpoint): New functions. (watchpoint_breakpoint_ops): New structure. (watch_command_1): Initialize the OPS field. * inf-child.c (inf_child_insert_fork_catchpoint) (inf_child_remove_fork_catchpoint, inf_child_insert_vfork_catchpoint) (inf_child_remove_vfork_catchpoint, inf_child_insert_exec_catchpoint) (inf_child_remove_exec_catchpoint, inf_child_set_syscall_catchpoint): Delete functions. (inf_child_target): Remove initialization of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint. * target.c (update_current_target): Change default implementation of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint to return_one. (debug_to_insert_fork_catchpoint, debug_to_insert_vfork_catchpoint) (debug_to_insert_exec_catchpoint): Report return value. * target.h (to_insert_fork_catchpoint, to_insert_vfork_catchpoint) (to_insert_exec_catchpoint): Change declaration to return int instead of void. gdb/testsuite/ * gdb.base/foll-exec.exp: Adapt to new error string when the catchpoint type is not supported. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise.
2011-01-11 20:16:23 +01:00
static int
linux_child_insert_exec_catchpoint (struct target_ops *self, int pid)
{
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
return !linux_supports_tracefork ();
}
static int
linux_child_remove_exec_catchpoint (struct target_ops *self, int pid)
{
return 0;
}
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
static int
linux_child_set_syscall_catchpoint (struct target_ops *self,
int pid, int needed, int any_count,
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
int table_size, int *table)
{
Unify ptrace options discovery code and make both GDB and gdbserver use it. gdb/ * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-nat.h and nat/linux-waitpid.h. (linux-waitpid.o): New object file rule. * common/linux-ptrace.c: Include nat/linux-waitpid.h. (current_ptrace_options): Moved from linux-nat.c. (linux_ptrace_test_ret_to_nx): Use type casts for ptrace parameters. (linux_fork_to_function): New function. (linux_grandchild_function): Likewise. (linux_child_function): Likewise. (linux_check_ptrace_features): New function, heavily based on linux-nat.c:linux_test_for_tracefork. (linux_enable_event_reporting): New function. (ptrace_supports_feature): Likewise. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * common/linux-ptrace.h (HAS_NOMMU): Moved from gdbserver/linux-low.c. (linux_enable_event_reporting): New declaration. (linux_supports_tracefork): Likewise. (linux_supports_traceclone): Likewise. (linux_supports_tracevforkdone): Likewise. (linux_supports_tracesysgood): Likewise. * config.in (PTRACE_TYPE_ARG4): Regenerate. * config/aarch64/linux.mh (NATDEPFILES): Add linux-waitpid.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/linux.mh (NATDEPFILES): Likewise.. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * configure.ac (AC_CACHE_CHECK): Add void * to the list of ptrace's 4th argument's types. Check the type of PTRACE_TYPE_ARG4. * configure: Regenerate. * linux-nat.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (SYSCALL_SIGTRAP): Moved to nat/linux-nat.h. (linux_supports_tracefork_flag): Remove. (linux_supports_tracesysgood_flag): Likewise. (linux_supports_tracevforkdone_flag): Likewise. (current_ptrace_options): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (my_waitpid): Remove. (linux_test_for_tracefork): Renamed to linux_check_ptrace_features and moved to common/linux-ptrace.c. (linux_test_for_tracesysgood): Remove. (linux_supports_tracesysgood): Remove. (linux_supports_tracefork): Remove. (linux_supports_tracevforkdone): Remove. (linux_enable_tracesysgood): Remove. (linux_enable_event_reporting): Remove. (linux_init_ptrace): New function. (linux_child_post_attach): Call linux_init_ptrace. (linux_child_post_startup_inferior): Call linux_init_ptrace. (linux_child_follow_fork): Call linux_supports_tracefork and linux_supports_tracevforkdone. (linux_child_insert_fork_catchpoint): Call linux_supports_tracefork. (linux_child_insert_vfork_catchpoint): Likewise. (linux_child_set_syscall_catchpoint): Call linux_supports_tracesysgood. (lin_lwp_attach_lwp): Call linux_supports_tracefork. * nat/linux-nat.h: New file. * nat/linux-waitpid.c: New file. * nat/linux-waitpid.h: New file. gdb/gdbserver/ * Makefile.in: Explain why ../target and ../nat are not listed as include file search paths. (linux-waitpid.o): New object file rule. * configure.srv (srv_native_linux_obj): New variable. Replace all occurrences of linux native object files with $srv_native_linux_obj. * linux-low.c: Include nat/linux-nat.h and nat/linux-waitpid.h. (HAS_NOMMU): Move defining logic to common/linux-ptrace.c. (linux_enable_event_reporting): Remove declaration. (my_waitpid): Moved to common/linux-waitpid.c. (linux_wait_for_event): Pass ptid when calling linux_enable_event_reporting. (linux_supports_tracefork_flag): Remove. (linux_enable_event_reporting): Likewise. (linux_tracefork_grandchild): Remove. (STACK_SIZE): Moved to common/linux-ptrace.c. (linux_tracefork_child): Remove. (linux_test_for_tracefork): Remove. (linux_look_up_symbols): Call linux_supports_traceclone. (initialize_low): Remove call to linux_test_for_tracefork. * linux-low.h (PTRACE_TYPE_ARG3): Move to common/linux-ptrace.h. (PTRACE_TYPE_ARG4): Likewise. Include linux-ptrace.h.
2013-08-23 01:46:30 +02:00
if (!linux_supports_tracesysgood ())
2010-01-11 Thiago Jung Bauermann <bauerman@br.ibm.com> Convert hardware watchpoints to use breakpoint_ops. gdb/ * breakpoint.h (breakpoint_ops) <insert>: Rename to... <insert_location>: ... this. Return int instead of void. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. (breakpoint_ops) <remove>: Rename to... <remove_location>: ... this. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. * breakpoint.c (insert_catchpoint): Delete function. (insert_bp_location): Call the watchpoint or catchpoint's breakpoint_ops.insert method. (remove_breakpoint_1): Call the watchpoint or catchpoint's breakpoint_ops.remove method. (insert_watchpoint, remove_watchpoint): New functions. (watchpoint_breakpoint_ops): New structure. (watch_command_1): Initialize the OPS field. * inf-child.c (inf_child_insert_fork_catchpoint) (inf_child_remove_fork_catchpoint, inf_child_insert_vfork_catchpoint) (inf_child_remove_vfork_catchpoint, inf_child_insert_exec_catchpoint) (inf_child_remove_exec_catchpoint, inf_child_set_syscall_catchpoint): Delete functions. (inf_child_target): Remove initialization of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint. * target.c (update_current_target): Change default implementation of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint to return_one. (debug_to_insert_fork_catchpoint, debug_to_insert_vfork_catchpoint) (debug_to_insert_exec_catchpoint): Report return value. * target.h (to_insert_fork_catchpoint, to_insert_vfork_catchpoint) (to_insert_exec_catchpoint): Change declaration to return int instead of void. gdb/testsuite/ * gdb.base/foll-exec.exp: Adapt to new error string when the catchpoint type is not supported. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise.
2011-01-11 20:16:23 +01:00
return 1;
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
/* On GNU/Linux, we ignore the arguments. It means that we only
enable the syscall catchpoints, but do not disable them.
2010-01-11 Thiago Jung Bauermann <bauerman@br.ibm.com> Convert hardware watchpoints to use breakpoint_ops. gdb/ * breakpoint.h (breakpoint_ops) <insert>: Rename to... <insert_location>: ... this. Return int instead of void. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. (breakpoint_ops) <remove>: Rename to... <remove_location>: ... this. Accept pointer to struct bp_location instead of pointer to struct breakpoint. Adapt all implementations. * breakpoint.c (insert_catchpoint): Delete function. (insert_bp_location): Call the watchpoint or catchpoint's breakpoint_ops.insert method. (remove_breakpoint_1): Call the watchpoint or catchpoint's breakpoint_ops.remove method. (insert_watchpoint, remove_watchpoint): New functions. (watchpoint_breakpoint_ops): New structure. (watch_command_1): Initialize the OPS field. * inf-child.c (inf_child_insert_fork_catchpoint) (inf_child_remove_fork_catchpoint, inf_child_insert_vfork_catchpoint) (inf_child_remove_vfork_catchpoint, inf_child_insert_exec_catchpoint) (inf_child_remove_exec_catchpoint, inf_child_set_syscall_catchpoint): Delete functions. (inf_child_target): Remove initialization of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint. * target.c (update_current_target): Change default implementation of to_insert_fork_catchpoint, to_remove_fork_catchpoint, to_insert_vfork_catchpoint, to_remove_vfork_catchpoint, to_insert_exec_catchpoint, to_remove_exec_catchpoint and to_set_syscall_catchpoint to return_one. (debug_to_insert_fork_catchpoint, debug_to_insert_vfork_catchpoint) (debug_to_insert_exec_catchpoint): Report return value. * target.h (to_insert_fork_catchpoint, to_insert_vfork_catchpoint) (to_insert_exec_catchpoint): Change declaration to return int instead of void. gdb/testsuite/ * gdb.base/foll-exec.exp: Adapt to new error string when the catchpoint type is not supported. * gdb.base/foll-fork.exp: Likewise. * gdb.base/foll-vfork.exp: Likewise.
2011-01-11 20:16:23 +01:00
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
Also, we do not use the `table' information because we do not
filter system calls here. We let GDB do the logic for us. */
return 0;
}
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* List of known LWPs, keyed by LWP PID. This speeds up the common
case of mapping a PID returned from the kernel to our corresponding
lwp_info data structure. */
static htab_t lwp_lwpid_htab;
/* Calculate a hash from a lwp_info's LWP PID. */
static hashval_t
lwp_info_hash (const void *ap)
{
const struct lwp_info *lp = (struct lwp_info *) ap;
pid_t pid = ptid_get_lwp (lp->ptid);
return iterative_hash_object (pid, 0);
}
/* Equality function for the lwp_info hash table. Compares the LWP's
PID. */
static int
lwp_lwpid_htab_eq (const void *a, const void *b)
{
const struct lwp_info *entry = (const struct lwp_info *) a;
const struct lwp_info *element = (const struct lwp_info *) b;
return ptid_get_lwp (entry->ptid) == ptid_get_lwp (element->ptid);
}
/* Create the lwp_lwpid_htab hash table. */
static void
lwp_lwpid_htab_create (void)
{
lwp_lwpid_htab = htab_create (100, lwp_info_hash, lwp_lwpid_htab_eq, NULL);
}
/* Add LP to the hash table. */
static void
lwp_lwpid_htab_add_lwp (struct lwp_info *lp)
{
void **slot;
slot = htab_find_slot (lwp_lwpid_htab, lp, INSERT);
gdb_assert (slot != NULL && *slot == NULL);
*slot = lp;
}
/* Head of doubly-linked list of known LWPs. Sorted by reverse
creation order. This order is assumed in some cases. E.g.,
reaping status after killing alls lwps of a process: the leader LWP
must be reaped last. */
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
struct lwp_info *lwp_list;
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Add LP to sorted-by-reverse-creation-order doubly-linked list. */
static void
lwp_list_add (struct lwp_info *lp)
{
lp->next = lwp_list;
if (lwp_list != NULL)
lwp_list->prev = lp;
lwp_list = lp;
}
/* Remove LP from sorted-by-reverse-creation-order doubly-linked
list. */
static void
lwp_list_remove (struct lwp_info *lp)
{
/* Remove from sorted-by-creation-order list. */
if (lp->next != NULL)
lp->next->prev = lp->prev;
if (lp->prev != NULL)
lp->prev->next = lp->next;
if (lp == lwp_list)
lwp_list = lp->next;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Original signal mask. */
static sigset_t normal_mask;
/* Signal mask for use with sigsuspend in linux_nat_wait, initialized in
_initialize_linux_nat. */
static sigset_t suspend_mask;
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Signals to block to make that sigsuspend work. */
static sigset_t blocked_mask;
/* SIGCHLD action. */
struct sigaction sigchld_action;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Block child signals (SIGCHLD and linux threads signals), and store
the previous mask in PREV_MASK. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
static void
block_child_signals (sigset_t *prev_mask)
{
/* Make sure SIGCHLD is blocked. */
if (!sigismember (&blocked_mask, SIGCHLD))
sigaddset (&blocked_mask, SIGCHLD);
sigprocmask (SIG_BLOCK, &blocked_mask, prev_mask);
}
/* Restore child signals mask, previously returned by
block_child_signals. */
static void
restore_child_signals_mask (sigset_t *prev_mask)
{
sigprocmask (SIG_SETMASK, prev_mask, NULL);
}
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
/* Mask of signals to pass directly to the inferior. */
static sigset_t pass_mask;
/* Update signals to pass to the inferior. */
static void
linux_nat_pass_signals (struct target_ops *self,
int numsigs, unsigned char *pass_signals)
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
{
int signo;
sigemptyset (&pass_mask);
for (signo = 1; signo < NSIG; signo++)
{
int target_signo = gdb_signal_from_host (signo);
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
if (target_signo < numsigs && pass_signals[target_signo])
sigaddset (&pass_mask, signo);
}
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Prototypes for local functions. */
static int stop_wait_callback (struct lwp_info *lp, void *data);
static char *linux_child_pid_to_exec_file (struct target_ops *self, int pid);
Linux: don't resume new LWPs until we've pulled all events out of the kernel Since the starvation avoidance series (https://sourceware.org/ml/gdb-patches/2014-12/msg00631.html), both GDB and GDBserver pull all events out of ptrace before deciding which event to process. There's one problem with that though. Because we resume new threads immediately when we see a PTRACE_EVENT_CLONE event, if the program constantly spawns threads fast enough, new threads can spawn threads faster we can pull events out of the kernel, and thus we'd get stuck in an infinite loop, never returning any event to the core to process. I occasionally see this happen with the attach-many-short-lived-threads.exp test against gdbserver. The fix is to delay resuming new threads until we've pulled out all events out of the kernel. On native, we already have the resume_stopped_resumed_lwps function that knows to resume LWPs that are stopped with no event to report to the core. So the patch just adds another use. GDBserver didn't have the equivalent yet, so the patch adds one. Tested on x86_64 Fedora 20, native and gdbserver (remote and extended-remote). gdb/gdbserver/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-low.c (handle_extended_wait): Don't resume LWPs here. (resume_stopped_resumed_lwps): New function. (linux_wait_for_event_filtered): Use it. gdb/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-nat.c (handle_extended_wait): Don't resume LWPs here. (wait_lwp): Don't call wait_lwp if linux_handle_extended_wait returns true. (resume_stopped_resumed_lwps): Don't check whether the thread is marked as executing. (linux_nat_wait_1): Use resume_stopped_resumed_lwps.
2015-02-04 19:13:28 +01:00
static int resume_stopped_resumed_lwps (struct lwp_info *lp, void *data);
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
static int check_ptrace_stopped_lwp_gone (struct lwp_info *lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
/* Destroy and free LP. */
static void
lwp_free (struct lwp_info *lp)
{
xfree (lp->arch_private);
xfree (lp);
}
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Traversal function for purge_lwp_list. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
static int
lwp_lwpid_htab_remove_pid (void **slot, void *info)
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
{
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
struct lwp_info *lp = (struct lwp_info *) *slot;
int pid = *(int *) info;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
if (ptid_get_pid (lp->ptid) == pid)
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
{
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
htab_clear_slot (lwp_lwpid_htab, slot);
lwp_list_remove (lp);
lwp_free (lp);
}
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
return 1;
}
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Remove all LWPs belong to PID from the lwp list. */
static void
purge_lwp_list (int pid)
{
htab_traverse_noresize (lwp_lwpid_htab, lwp_lwpid_htab_remove_pid, &pid);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
}
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
/* Add the LWP specified by PTID to the list. PTID is the first LWP
in the process. Return a pointer to the structure describing the
new LWP.
This differs from add_lwp in that we don't let the arch specific
bits know about this new thread. Current clients of this callback
take the opportunity to install watchpoints in the new thread, and
we shouldn't do that for the first thread. If we're spawning a
child ("run"), the thread executes the shell wrapper first, and we
shouldn't touch it until it execs the program we want to debug.
For "attach", it'd be okay to call the callback, but it's not
necessary, because watchpoints can't yet have been inserted into
the inferior. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static struct lwp_info *
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
add_initial_lwp (ptid_t ptid)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
struct lwp_info *lp;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
gdb_assert (ptid_lwp_p (ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Replace some xmalloc-family functions with XNEW-family ones This patch is part of the make-gdb-buildable-in-C++ effort. The idea is to change some calls to the xmalloc family of functions to calls to the equivalents in the XNEW family. This avoids adding an explicit cast, so it keeps the code a bit more readable. Some of them also map relatively well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be possible to do scripted replacements if needed. I only changed calls that were obviously allocating memory for one or multiple "objects". Allocation of variable sizes (such as strings or buffer handling) will be for later (and won't use XNEW). - xmalloc (sizeof (struct foo)) -> XNEW (struct foo) - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num) - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo) - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num) - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num) - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo) - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num) - alloca (sizeof (struct foo)) -> XALLOCA (struct foo) - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num) Some instances of xmalloc followed by memset to zero the buffer were replaced by XCNEW or XCNEWVEC. I regtested on x86-64, Ubuntu 14.04, but the patch touches many architecture-specific files. For those I'll have to rely on the buildbot or people complaining that I broke their gdb. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_add_process): Likewise. * aarch64-tdep.c (aarch64_gdbarch_init): Likewise. * ada-exp.y (write_ambiguous_var): Likewise. * ada-lang.c (resolve_subexp): Likewise. (user_select_syms): Likewise. (assign_aggregate): Likewise. (ada_evaluate_subexp): Likewise. (cache_symbol): Likewise. * addrmap.c (allocate_key): Likewise. (addrmap_create_mutable): Likewise. * aix-thread.c (sync_threadlists): Likewise. * alpha-tdep.c (alpha_push_dummy_call): Likewise. (alpha_gdbarch_init): Likewise. * amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise. * arm-linux-nat.c (arm_linux_add_process): Likewise. * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise. * arm-tdep.c (push_stack_item): Likewise. (arm_displaced_step_copy_insn): Likewise. (arm_gdbarch_init): Likewise. (_initialize_arm_tdep): Likewise. * avr-tdep.c (push_stack_item): Likewise. * ax-general.c (new_agent_expr): Likewise. * block.c (block_initialize_namespace): Likewise. * breakpoint.c (alloc_counted_command_line): Likewise. (update_dprintf_command_list): Likewise. (parse_breakpoint_sals): Likewise. (decode_static_tracepoint_spec): Likewise. (until_break_command): Likewise. (clear_command): Likewise. (update_global_location_list): Likewise. (get_breakpoint_objfile_data) Likewise. * btrace.c (ftrace_new_function): Likewise. (btrace_set_insn_history): Likewise. (btrace_set_call_history): Likewise. * buildsym.c (add_symbol_to_list): Likewise. (record_pending_block): Likewise. (start_subfile): Likewise. (start_buildsym_compunit): Likewise. (push_subfile): Likewise. (end_symtab_get_static_block): Likewise. (buildsym_init): Likewise. * cli/cli-cmds.c (source_command): Likewise. * cli/cli-decode.c (add_cmd): Likewise. * cli/cli-script.c (build_command_line): Likewise. (setup_user_args): Likewise. (realloc_body_list): Likewise. (process_next_line): Likewise. (copy_command_lines): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (read_pe_exported_syms): Likewise. * coffread.c (coff_locate_sections): Likewise. (coff_symtab_read): Likewise. (coff_read_struct_type): Likewise. * common/cleanups.c (make_my_cleanup2): Likewise. * common/common-exceptions.c (throw_it): Likewise. * common/filestuff.c (make_cleanup_close): Likewise. * common/format.c (parse_format_string): Likewise. * common/queue.h (DEFINE_QUEUE_P): Likewise. * compile/compile-object-load.c (munmap_list_add): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * compile/compile.c (append_args): Likewise. * corefile.c (specify_exec_file_hook): Likewise. * cp-support.c (make_symbol_overload_list): Likewise. * cris-tdep.c (push_stack_item): Likewise. (cris_gdbarch_init): Likewise. * ctf.c (ctf_trace_file_writer_new): Likewise. * dbxread.c (init_header_files): Likewise. (add_new_header_file): Likewise. (init_bincl_list): Likewise. (dbx_end_psymtab): Likewise. (start_psymtab): Likewise. (dbx_end_psymtab): Likewise. * dcache.c (dcache_init): Likewise. * dictionary.c (dict_create_hashed): Likewise. (dict_create_hashed_expandable): Likewise. (dict_create_linear): Likewise. (dict_create_linear_expandable): Likewise. * dtrace-probe.c (dtrace_process_dof_probe): Likewise. * dummy-frame.c (register_dummy_frame_dtor): Likewise. * dwarf2-frame-tailcall.c (cache_new_ref1): Likewise. * dwarf2-frame.c (dwarf2_build_frame_info): Likewise. (decode_frame_entry_1): Likewise. * dwarf2expr.c (new_dwarf_expr_context): Likewise. * dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise. * dwarf2read.c (dwarf2_has_info): Likewise. (create_signatured_type_table_from_index): Likewise. (dwarf2_read_index): Likewise. (dw2_get_file_names_reader): Likewise. (create_all_type_units): Likewise. (read_cutu_die_from_dwo): Likewise. (init_tu_and_read_dwo_dies): Likewise. (init_cutu_and_read_dies): Likewise. (create_all_comp_units): Likewise. (queue_comp_unit): Likewise. (inherit_abstract_dies): Likewise. (read_call_site_scope): Likewise. (dwarf2_add_field): Likewise. (dwarf2_add_typedef): Likewise. (dwarf2_add_member_fn): Likewise. (attr_to_dynamic_prop): Likewise. (abbrev_table_alloc_abbrev): Likewise. (abbrev_table_read_table): Likewise. (add_include_dir): Likewise. (add_file_name): Likewise. (dwarf_decode_line_header): Likewise. (dwarf2_const_value_attr): Likewise. (dwarf_alloc_block): Likewise. (parse_macro_definition): Likewise. (set_die_type): Likewise. (write_psymtabs_to_index): Likewise. (create_cus_from_index): Likewise. (dwarf2_create_include_psymtab): Likewise. (process_psymtab_comp_unit_reader): Likewise. (build_type_psymtab_dependencies): Likewise. (read_comp_units_from_section): Likewise. (compute_compunit_symtab_includes): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (load_partial_dies): Likewise. (dwarf2_symbol_mark_computed): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_read_minimal_symbols): Likewise. * environ.c (make_environ): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * event-loop.c (create_file_handler): Likewise. (create_async_signal_handler): Likewise. (create_async_event_handler): Likewise. (create_timer): Likewise. * exec.c (build_section_table): Likewise. * fbsd-nat.c (fbsd_remember_child): Likewise. * fork-child.c (fork_inferior): Likewise. * frv-tdep.c (new_variant): Likewise. * gdbarch.sh (gdbarch_alloc): Likewise. (append_name): Likewise. * gdbtypes.c (rank_function): Likewise. (copy_type_recursive): Likewise. (add_dyn_prop): Likewise. * gnu-nat.c (make_proc): Likewise. (make_inf): Likewise. (gnu_write_inferior): Likewise. * gnu-v3-abi.c (build_gdb_vtable_type): Likewise. (build_std_type_info_type): Likewise. * guile/scm-param.c (compute_enum_list): Likewise. * guile/scm-utils.c (gdbscm_parse_function_args): Likewise. * guile/scm-value.c (gdbscm_value_call): Likewise. * h8300-tdep.c (h8300_gdbarch_init): Likewise. * hppa-tdep.c (hppa_init_objfile_priv_data): Likewise. (read_unwind_info): Likewise. * ia64-tdep.c (ia64_gdbarch_init): Likewise. * infcall.c (dummy_frame_context_saver_setup): Likewise. (call_function_by_hand_dummy): Likewise. * infcmd.c (step_once): Likewise. (finish_forward): Likewise. (attach_command): Likewise. (notice_new_inferior): Likewise. * inferior.c (add_inferior_silent): Likewise. * infrun.c (add_displaced_stepping_state): Likewise. (save_infcall_control_state): Likewise. (save_inferior_ptid): Likewise. (_initialize_infrun): Likewise. * jit.c (bfd_open_from_target_memory): Likewise. (jit_gdbarch_data_init): Likewise. * language.c (add_language): Likewise. * linespec.c (decode_line_2): Likewise. * linux-nat.c (add_to_pid_list): Likewise. (add_initial_lwp): Likewise. * linux-thread-db.c (add_thread_db_info): Likewise. (record_thread): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_gdbarch_init): Likewise. * m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise. * m68k-tdep.c (m68k_gdbarch_init): Likewise. * m88k-tdep.c (m88k_analyze_prologue): Likewise. * macrocmd.c (macro_define_command): Likewise. * macroexp.c (gather_arguments): Likewise. * macroscope.c (sal_macro_scope): Likewise. * macrotab.c (new_macro_table): Likewise. * mdebugread.c (push_parse_stack): Likewise. (parse_partial_symbols): Likewise. (parse_symbol): Likewise. (psymtab_to_symtab_1): Likewise. (new_block): Likewise. (new_psymtab): Likewise. (mdebug_build_psymtabs): Likewise. (add_pending): Likewise. (elfmdebug_build_psymtabs): Likewise. * mep-tdep.c (mep_gdbarch_init): Likewise. * mi/mi-main.c (mi_execute_command): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. * minidebug.c (lzma_open): Likewise. * minsyms.c (terminate_minimal_symbol_table): Likewise. * mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise. * mips-tdep.c (mips_gdbarch_init): Likewise. * mn10300-tdep.c (mn10300_gdbarch_init): Likewise. * msp430-tdep.c (msp430_gdbarch_init): Likewise. * mt-tdep.c (mt_registers_info): Likewise. * nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise. * nat/linux-btrace.c (linux_enable_bts): Likewise. (linux_enable_pt): Likewise. * nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise. (linux_xfer_osdata_processgroups): Likewise. * nios2-tdep.c (nios2_gdbarch_init): Likewise. * nto-procfs.c (procfs_meminfo): Likewise. * objc-lang.c (start_msglist): Likewise. (selectors_info): Likewise. (classes_info): Likewise. (find_methods): Likewise. * objfiles.c (allocate_objfile): Likewise. (update_section_map): Likewise. * osabi.c (gdbarch_register_osabi): Likewise. (gdbarch_register_osabi_sniffer): Likewise. * parse.c (start_arglist): Likewise. * ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise. (hwdebug_insert_point): Likewise. * printcmd.c (display_command): Likewise. (ui_printf): Likewise. * procfs.c (create_procinfo): Likewise. (load_syscalls): Likewise. (proc_get_LDT_entry): Likewise. (proc_update_threads): Likewise. * prologue-value.c (make_pv_area): Likewise. (pv_area_store): Likewise. * psymtab.c (extend_psymbol_list): Likewise. (init_psymbol_list): Likewise. (allocate_psymtab): Likewise. * python/py-inferior.c (add_thread_object): Likewise. * python/py-param.c (compute_enum_values): Likewise. * python/py-value.c (valpy_call): Likewise. * python/py-varobj.c (py_varobj_iter_next): Likewise. * python/python.c (ensure_python_env): Likewise. * record-btrace.c (record_btrace_start_replaying): Likewise. * record-full.c (record_full_reg_alloc): Likewise. (record_full_mem_alloc): Likewise. (record_full_end_alloc): Likewise. (record_full_core_xfer_partial): Likewise. * regcache.c (get_thread_arch_aspace_regcache): Likewise. * remote-fileio.c (remote_fileio_init_fd_map): Likewise. * remote-notif.c (remote_notif_state_allocate): Likewise. * remote.c (demand_private_info): Likewise. (remote_notif_stop_alloc_reply): Likewise. (remote_enable_btrace): Likewise. * reverse.c (save_bookmark_command): Likewise. * rl78-tdep.c (rl78_gdbarch_init): Likewise. * rx-tdep.c (rx_gdbarch_init): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. * ser-go32.c (dos_get_tty_state): Likewise. (dos_copy_tty_state): Likewise. * ser-mingw.c (ser_windows_open): Likewise. (ser_console_wait_handle): Likewise. (ser_console_get_tty_state): Likewise. (make_pipe_state): Likewise. (net_windows_open): Likewise. * ser-unix.c (hardwire_get_tty_state): Likewise. (hardwire_copy_tty_state): Likewise. * solib-aix.c (solib_aix_new_lm_info): Likewise. * solib-dsbt.c (dsbt_current_sos): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (frv_current_sos): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_bfd_fopen): Likewise. * solib-svr4.c (lm_info_read): Likewise. (svr4_copy_library_list): Likewise. (svr4_default_sos): Likewise. * source.c (find_source_lines): Likewise. (line_info): Likewise. (add_substitute_path_rule): Likewise. * spu-linux-nat.c (spu_bfd_open): Likewise. * spu-tdep.c (info_spu_dma_cmdlist): Likewise. * stabsread.c (dbx_lookup_type): Likewise. (read_type): Likewise. (read_member_functions): Likewise. (read_struct_fields): Likewise. (read_baseclasses): Likewise. (read_args): Likewise. (_initialize_stabsread): Likewise. * stack.c (func_command): Likewise. * stap-probe.c (handle_stap_probe): Likewise. * symfile.c (addrs_section_sort): Likewise. (addr_info_make_relative): Likewise. (load_section_callback): Likewise. (add_symbol_file_command): Likewise. (init_filename_language_table): Likewise. * symtab.c (create_filename_seen_cache): Likewise. (sort_search_symbols_remove_dups): Likewise. (search_symbols): Likewise. * target.c (make_cleanup_restore_target_terminal): Likewise. * thread.c (new_thread): Likewise. (enable_thread_stack_temporaries): Likewise. (make_cleanup_restore_current_thread): Likewise. (thread_apply_all_command): Likewise. * tic6x-tdep.c (tic6x_gdbarch_init): Likewise. * top.c (gdb_readline_wrapper): Likewise. * tracefile-tfile.c (tfile_trace_file_writer_new): Likewise. * tracepoint.c (trace_find_line_command): Likewise. (all_tracepoint_actions_and_cleanup): Likewise. (make_cleanup_restore_current_traceframe): Likewise. (get_uploaded_tp): Likewise. (get_uploaded_tsv): Likewise. * tui/tui-data.c (tui_alloc_generic_win_info): Likewise. (tui_alloc_win_info): Likewise. (tui_alloc_content): Likewise. (tui_add_content_elements): Likewise. * tui/tui-disasm.c (tui_find_disassembly_address): Likewise. (tui_set_disassem_content): Likewise. * ui-file.c (ui_file_new): Likewise. (stdio_file_new): Likewise. (tee_file_new): Likewise. * utils.c (make_cleanup_restore_integer): Likewise. (add_internal_problem_command): Likewise. * v850-tdep.c (v850_gdbarch_init): Likewise. * valops.c (find_oload_champ): Likewise. * value.c (allocate_value_lazy): Likewise. (record_latest_value): Likewise. (create_internalvar): Likewise. * varobj.c (install_variable): Likewise. (new_variable): Likewise. (new_root_variable): Likewise. (cppush): Likewise. (_initialize_varobj): Likewise. * windows-nat.c (windows_make_so): Likewise. * x86-nat.c (x86_add_process): Likewise. * xcoffread.c (arrange_linetable): Likewise. (allocate_include_entry): Likewise. (process_linenos): Likewise. (SYMBOL_DUP): Likewise. (xcoff_start_psymtab): Likewise. (xcoff_end_psymtab): Likewise. * xml-support.c (gdb_xml_parse_attr_ulongest): Likewise. * xtensa-tdep.c (xtensa_register_type): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Likewise. (compile_bytecodes): Likewise. * dll.c (loaded_dll): Likewise. * event-loop.c (append_callback_event): Likewise. (create_file_handler): Likewise. (create_file_event): Likewise. * hostio.c (handle_open): Likewise. * inferiors.c (add_thread): Likewise. (add_process): Likewise. * linux-aarch64-low.c (aarch64_linux_new_process): Likewise. * linux-arm-low.c (arm_new_process): Likewise. (arm_new_thread): Likewise. * linux-low.c (add_to_pid_list): Likewise. (linux_add_process): Likewise. (handle_extended_wait): Likewise. (add_lwp): Likewise. (enqueue_one_deferred_signal): Likewise. (enqueue_pending_signal): Likewise. (linux_resume_one_lwp_throw): Likewise. (linux_resume_one_thread): Likewise. (linux_read_memory): Likewise. (linux_write_memory): Likewise. * linux-mips-low.c (mips_linux_new_process): Likewise. (mips_linux_new_thread): Likewise. (mips_add_watchpoint): Likewise. * linux-x86-low.c (initialize_low_arch): Likewise. * lynx-low.c (lynx_add_process): Likewise. * mem-break.c (set_raw_breakpoint_at): Likewise. (set_breakpoint): Likewise. (add_condition_to_breakpoint): Likewise. (add_commands_to_breakpoint): Likewise. (clone_agent_expr): Likewise. (clone_one_breakpoint): Likewise. * regcache.c (new_register_cache): Likewise. * remote-utils.c (look_up_one_symbol): Likewise. * server.c (queue_stop_reply): Likewise. (start_inferior): Likewise. (queue_stop_reply_callback): Likewise. (handle_target_event): Likewise. * spu-low.c (fetch_ppc_memory): Likewise. (store_ppc_memory): Likewise. * target.c (set_target_ops): Likewise. * thread-db.c (thread_db_load_search): Likewise. (try_thread_db_load_1): Likewise. * tracepoint.c (add_tracepoint): Likewise. (add_tracepoint_action): Likewise. (create_trace_state_variable): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtro): Likewise. (add_while_stepping_state): Likewise. * win32-low.c (child_add_thread): Likewise. (get_image_name): Likewise.
2015-08-26 23:16:07 +02:00
lp = XNEW (struct lwp_info);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
memset (lp, 0, sizeof (struct lwp_info));
lp->last_resume_kind = resume_continue;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
lp->waitstatus.kind = TARGET_WAITKIND_IGNORE;
lp->ptid = ptid;
Implement core awareness. * bcache.c (compare_ints): Remove (print_percentage): Use compare_positive_ints. * defs.h (compare_positive_ints): Declare. * linux-nat.h (struct lin_lwp): New field core. (linux_nat_core_of_thread_1): Declare. * linux-nat.c (add_lwp): Init the 'core' field. (linux_nat_wait_1): Record the core. (linux_nat_core_of_thread_1, linux_nat_core_of_thread): New. (linux_nat_add_target): Register the above. * linux-thread-db.c (update_thread_core): New. (thread_db_find_new_threads): Update core information for every thread. * remote.c (struct private_thread_info): New. (free_private_thread_info, demand_private_info): New. (PACKET_qXfer_threads, use_osdata_threads): New. (struct thread_item, threads_parsing_context (start_thread, end_thread, thread_attributes) (thread_children, threads_children, threads_elements): New. (remote_threads_info): Try qXfer:threads before anything else. (remote_protocol_packets): Register qXfer:threads. (remote_open_1): Init use_osdata_threads. (struct stop_reply): New field 'core'. (remote_parse_stop_reply): Parse core number. (process_stop_reply): Record core number. (remote_xfer_partial): Handle qXfer:threads. (remote_core_of_thread): New. (init_remote_ops): Register remote_core_of_thread. (_initialize_remote): Register qXfer:read. * target.c (target_core_of_thread): New * target.h (enum target_object): New value TARGET_OBJECT_THREADS. (struct target_ops): New field to_core_of_threads. (target_core_of_thread): Declare. * gdbthread.h (struct thread_info): New field private_dtor. * thread.c (print_thread_info): Report the core. * ui-out.c (MAX_UI_OUT_LEVELS): Increase. * utils.c (compare_positive_ints): New. * features/threads.dtd: New. * mi/mi-interp.c (mi_on_normal_stop): Report the core. * mi/mi-main.c (struct collect_cores_data, collect_cores) (do_nothing, free_vector_of_osdata_items) (splay_tree_int_comparator, free_splay_tree): New. (print_one_inferior_data): Implemented printing of selected inferiors. Collect and print cores. (output_cores): New. (mi_cmd_list_thread_groups): Support --recurse. Permit specifying thread groups together with --available.
2010-01-12 22:40:25 +01:00
lp->core = -1;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Add to sorted-by-reverse-creation-order list. */
lwp_list_add (lp);
/* Add to keyed-by-pid htab. */
lwp_lwpid_htab_add_lwp (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
return lp;
}
/* Add the LWP specified by PID to the list. Return a pointer to the
structure describing the new LWP. The LWP should already be
stopped. */
static struct lwp_info *
add_lwp (ptid_t ptid)
{
struct lwp_info *lp;
lp = add_initial_lwp (ptid);
/* Let the arch specific bits know about this new thread. Current
clients of this callback take the opportunity to install
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
watchpoints in the new thread. We don't do this for the first
thread though. See add_initial_lwp. */
if (linux_nat_new_thread != NULL)
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
linux_nat_new_thread (lp);
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return lp;
}
/* Remove the LWP specified by PID from the list. */
static void
delete_lwp (ptid_t ptid)
{
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
struct lwp_info *lp;
void **slot;
struct lwp_info dummy;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
dummy.ptid = ptid;
slot = htab_find_slot (lwp_lwpid_htab, &dummy, NO_INSERT);
if (slot == NULL)
return;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
lp = *(struct lwp_info **) slot;
gdb_assert (lp != NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
htab_clear_slot (lwp_lwpid_htab, slot);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Remove from sorted-by-creation-order list. */
lwp_list_remove (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
/* Release. */
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
lwp_free (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Return a pointer to the structure describing the LWP corresponding
to PID. If no corresponding LWP could be found, return NULL. */
static struct lwp_info *
find_lwp_pid (ptid_t ptid)
{
struct lwp_info *lp;
int lwp;
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
struct lwp_info dummy;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (ptid_lwp_p (ptid))
lwp = ptid_get_lwp (ptid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
else
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
lwp = ptid_get_pid (ptid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
dummy.ptid = ptid_build (0, lwp, 0);
lp = (struct lwp_info *) htab_find (lwp_lwpid_htab, &dummy);
return lp;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* See nat/linux-nat.h. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
struct lwp_info *
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (ptid_t filter,
iterate_over_lwps_ftype callback,
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
void *data)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
struct lwp_info *lp, *lpnext;
for (lp = lwp_list; lp; lp = lpnext)
{
lpnext = lp->next;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (ptid_match (lp->ptid, filter))
{
if ((*callback) (lp, data) != 0)
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
return lp;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
return NULL;
}
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
/* Update our internal state when changing from one checkpoint to
another indicated by NEW_PTID. We can only switch single-threaded
applications, so we only create one new LWP, and the previous list
is discarded. */
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
void
linux_nat_switch_fork (ptid_t new_ptid)
{
struct lwp_info *lp;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
purge_lwp_list (ptid_get_pid (inferior_ptid));
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
lp = add_lwp (new_ptid);
lp->stopped = 1;
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
/* This changes the thread's ptid while preserving the gdb thread
num. Also changes the inferior pid, while preserving the
inferior num. */
thread_change_ptid (inferior_ptid, new_ptid);
/* We've just told GDB core that the thread changed target id, but,
in fact, it really is a different thread, with different register
contents. */
registers_changed ();
}
/* Handle the exit of a single thread LP. */
static void
exit_lwp (struct lwp_info *lp)
{
struct thread_info *th = find_thread_ptid (lp->ptid);
if (th)
{
2008-03-21 Daniel Jacobowitz <dan@codesourcery.com> * gdbthread.h (add_thread_with_info): New. * linux-thread-db.c: Add some documentation. (GET_LWP, GET_PID, GET_THREAD, is_lwp, is_thread, BUILD_LWP): Delete. (struct private_thread_info): Remove th_valid and ti_valid. Replace ti with tid. (thread_get_info_callback): Do not add TID to the new ptid. Do not cache th or ti. (thread_db_map_id2thr, lwp_from_thread): Delete functions. (thread_from_lwp): Assert that the LWP is set. Do not add TID to the new PTID. (attach_thread): Handle an already-existing thread. Use add_thread_with_info. Cache the th and tid. (detach_thread): Verify that private was set. Remove verbose argument and printing. Update caller. (thread_db_detach): Do not adjust inferior_ptid. (clear_lwpid_callback, thread_db_resume, thread_db_kill): Delete. (check_event, find_new_threads_callback): Do not add TID to the new PTID. (thread_db_wait): Do not use lwp_from_thread. (thread_db_pid_to_str): Use the cached TID. (thread_db_extra_thread_info): Check that private is set. (same_ptid_callback): Delete. (thread_db_get_thread_local_address): Do not use it or check is_thread. Check that private is set. Assume that the thread handle is already cached. (init_thread_db_ops): Remove to_resume and to_kill. * thread.c (add_thread_with_info): New. (add_thread): Use it. * linux-nat.c (find_thread_from_lwp): Delete. (exit_lwp): Do not use it. Check print_thread_events. Print before deleting the thread. (GET_PID, GET_LWP, BUILD_LWP, is_lwp): Move to... * linux-nat.h (GET_PID, GET_LWP, BUILD_LWP, is_lwp): ...here. * inf-ttrace.c (inf_ttrace_wait): Use print_thread_events and printf_unfiltered for thread exits. * procfs.c (procfs_wait): Likewise. 2008-03-21 Pedro Alves <pedro@codesourcery.com> * gdb.threads/fork-child-threads.exp: Test next over fork.
2008-03-21 16:44:53 +01:00
if (print_thread_events)
printf_unfiltered (_("[%s exited]\n"), target_pid_to_str (lp->ptid));
Exited threads. * thread.c (enum thread_state): New. (thread_state main_thread_running): Delete, in favor of... (thread_state main_thread_state): ... this. Update throughout. (clear_thread_inferior_resources): New, split from free_thread. (free_thread): Call clear_thread_inferior_resources. (init_thread_list): Set main thread to stopped state. (add_thread_silent): Take care of PTID reuses. (delete_thread): If deleting inferior_ptid or a thread with refcount > 0, mark it as exited, but still keep it in the list. Only notify of thread exits, if we haven't done so yet. (iterate_over_threads): Make it safe to delete threads while iterating over them. (do_captured_list_thread_ids): Don't account for exited threads. (thread_alive): Check for the THREAD_EXITED state, and don't set ptid to -1 on exited threads. (set_running): Update to account for extra possible states. (is_thread_state): New. (is_stopped, is_exited): New. (is_running): Implement in terms of is_thread_state. (any_running): Update. (print_thread_info): Update. Account for exited threads. Don't warn about missed frame restoring here, its done in the cleanup. (switch_to_thread): Don't read from a thread that has gone. (restore_current_thread): In non-stop mode, do a full context switch. (restore_selected_frame): Add a frame_level argument. Rewrite. (struct current_thread_cleanup): Add selected_frame_level and was_stopped members. (do_restore_current_thread_cleanup): Check if thread was stopped and still is, and if the target has registers, stack and memory before restoring the selected frame. Don't delete the cleanup argument here. (restore_current_thread_cleanup_dtor): New. (make_cleanup_restore_current_thread): Remove all arguments. Rewrite. (thread_apply_all_command): Update. Prune threads. (thread_apply_command): Update. (thread_command): Account for currently selected exited thread. (do_captured_thread_select): Check for a running thread. Prune threads. (_initialize_thread): Make "info threads", "thread", "thread apply", and "thread apply all" appliable without a selected thread. * gdbthread.h (struct thread_info): Replace running_ by state_. Add refcount. (is_exited, is_stopped): Declare. (make_cleanup_restore_current_thread): Remove all arguments. * infrun.c: Include "event-top.h". (fetch_inferior_event): In non-stop mode, restore selected thread and frame after handling the event and running breakpoint commands. Display GDB prompt if needed. (normal_stop): In non-stop mode, don't print thread switching notice. * cli/cli-decode.c (set_cmd_no_selected_thread_ok) (get_cmd_no_selected_thread_ok): New. * cli/cli-decode.h (CMD_NO_SELECTED_THREAD_OK): New. (set_cmd_no_selected_thread_ok, get_cmd_no_selected_thread_ok): Declare. * cli/cli-cmds.c: Set "pwd", "help", "info", "show" as no-selected-thread ok. * top.c (execute_command): Check for non no-selected-thread-ok commands. * linux-nat.c (struct saved_ptids, threads_to_delete) (record_dead_thread, prune_lwps): Delete. (exit_lwp): Unconditionally delete thread. (linux_nat_resume): Remove prune_lwps call. * infcmd.c (proceed_thread_callback): Check if !is_stopped instead of is_running. Adjust to make_cleanup_restore_current_thread interface change. * mi/mi-main.c (mi_cmd_execute): Only allow a few commands if the selected thread has exited. * inf-loop.c (inferior_event_handler): Don't display the prompt here. * varobj.c (c_value_of_root): Update. * defs.h (make_cleanup_dtor): Declare. * utils.c (make_cleanup_dtor): New. * Makefile.in (infrun.o): Depend on $(event_top_h).
2008-07-11 13:07:39 +02:00
delete_thread (lp->ptid);
}
delete_lwp (lp->ptid);
}
/* Wait for the LWP specified by LP, which we have just attached to.
Returns a wait status for that LWP, to cache. */
static int
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
linux_nat_post_attach_wait (ptid_t ptid, int first, int *signalled)
{
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid_t new_pid, pid = ptid_get_lwp (ptid);
int status;
if (linux_proc_pid_is_stopped (pid))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LNPAW: Attaching to a stopped process\n");
/* The process is definitely stopped. It is in a job control
stop, unless the kernel predates the TASK_STOPPED /
TASK_TRACED distinction, in which case it might be in a
ptrace stop. Make sure it is in a ptrace stop; from there we
can kill it, signal it, et cetera.
First make sure there is a pending SIGSTOP. Since we are
already attached, the process can not transition from stopped
to running without a PTRACE_CONT; so we know this signal will
go into the queue. The SIGSTOP generated by PTRACE_ATTACH is
probably already in the queue (unless this kernel is old
enough to use TASK_STOPPED for ptrace stops); but since SIGSTOP
is not an RT signal, it can only be queued once. */
kill_lwp (pid, SIGSTOP);
/* Finally, resume the stopped process. This will deliver the SIGSTOP
(or a higher priority signal, just like normal PTRACE_ATTACH). */
ptrace (PTRACE_CONT, pid, 0, 0);
}
/* Make sure the initial process is stopped. The user-level threads
layer might want to poke around in the inferior, and that won't
work if things haven't stabilized yet. */
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
new_pid = my_waitpid (pid, &status, __WALL);
gdb_assert (pid == new_pid);
if (!WIFSTOPPED (status))
{
/* The pid we tried to attach has apparently just exited. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "LNPAW: Failed to stop %d: %s",
pid, status_to_str (status));
return status;
}
if (WSTOPSIG (status) != SIGSTOP)
{
*signalled = 1;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LNPAW: Received %s after attaching\n",
status_to_str (status));
}
return status;
}
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
static void
Kill pthread_ops_hack * target.h (struct target_ops): Make to_attach, to_detach, to_create_inferior and to_mourn_inferior accept a pointer to struct target_ops. (target_attach, target_create_inferior, target_create_inferior): Convert from macros to function. Find the right target to invoke a method of. (find_default_attach, find_default_create_inferior): New parameter ops. * corefile.c (core_file_command): Pass target to to_detach. * corelow.c (core_detach): Add 'ops' parameter. * fork-child.c (fork_inferior): Return the pid. Allow init_trace_fun to be NULL. * inf-ptrace (ptrace_ops_hack): Remove. (inf_ptrace_him): Remove, moving all logic into.... (inf_ptrace_create_inferior): ... here. Push the target passed as parameter. (inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach): Push/pop target passed as parameter, no ptrace_ops_hack. (inf_ptrace_target): Don't remember result. * inferior.h (fork_inferior): Adjust prototype. * linux-nat.c (linux_nat_create_inferior, linux_nat_attach) (linux_nat_detach, linux_nat_mourn_inferior): New parameter ops. Pass it to linux_ops target. * linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior): New parameter ops. Pass it to the target beneath. * remote.c (remote_mourn, extended_remote_mourn, remote_detach) (extended_remote_create_inferior): New parameter ops. Pass it further. * target.c (debug_to_attach, debug_to_detach) (debug_to_mourn_inferior): New parameter ops. (target_create_inferior): New. (update_current_target): Do not inherit to_attach, to_detach, to_create_inferiour, to_mourn_inferior. Do not default to_detach and to_mourn_inferior. (target_detach): Find the right target to use. (target_mourn_inferior): New. (find_default_attach, find_default_create_inferior): New parameter ops. Pass the found target when calling its method. (init_dummy_target): Provide fallback definition of to_detach. (target_attach): New. (debug_to_attach, debug_to_detach, debug_to_create_inferior) (debug_to_mourn_inferiour): New parameter ops. * aix-thread.c: Adjust. * bsd-uthread.c: Adjust. * gnu-nat.c: Adjust. * go32-nat.c: Adjust. * hpux-thread.c: Adjust. * inf-ttrace.c: Ajust. * monitor.c: Adjust. * nto-procfs.c: Adjust. * procfs.c: Adjust. * remote-m32r-sdi.c: Adjust. * remote-mips.c: Adjust. * remote-sim.c: Adjust. * rs6000-nat.c: Adjust. * sol-thread.c: Adjust. * win32-nat.c: Adjust. * dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
linux_nat_create_inferior (struct target_ops *ops,
C++-fy and prepare for sharing fork_inferior As a preparation for the next patch, which will move fork_inferior from GDB to common/ (and therefore share it with gdbserver), it is interesting to convert a few functions to C++. This patch touches functions related to parsing command-line arguments to the inferior (see gdb/fork-child.c:breakup_args), the way the arguments are stored on fork_inferior (using std::vector instead of char **), and the code responsible for dealing with argv also on gdbserver. I've taken this opportunity and decided to constify a few arguments to fork_inferior/create_inferior as well, in order to make the code cleaner. And now, on gdbserver, we're using xstrdup everywhere and aren't checking for memory allocation failures anymore, as requested by Pedro: <https://sourceware.org/ml/gdb-patches/2017-03/msg00191.html> Message-Id: <025ebdb9-90d9-d54a-c055-57ed2406b812@redhat.com> Pedro Alves wrote: > On the "== NULL" check: IIUC, the old NULL check was there to > handle strdup returning NULL due to out-of-memory. > See NULL checks and comments further above in this function. > Now that you're using a std::vector, that doesn't work or make > sense any longer, since if push_back fails to allocate space for > its internal buffer (with operator new), our operator new replacement > (common/new-op.c) calls malloc_failure, which aborts gdbserver. > > Not sure it makes sense to handle out-of-memory specially in > the gdb/rsp-facing functions nowadays (maybe git blame/log/patch > submission for that code shows some guidelines). Maybe (or, probably) > it's OK to stop caring about it, but then we should consistently remove > left over code, by using xstrdup instead and remove the NULL checks. IMO this refactoring was very good to increase the readability of the code as well, because some parts of the argument handling were unnecessarily confusing before. gdb/ChangeLog: 2017-04-12 Sergio Durigan Junior <sergiodj@redhat.com> * common/common-utils.c (free_vector_argv): New function. * common/common-utils.h: Include <vector>. (free_vector_argv): New prototype. * darwin-nat.c (darwin_create_inferior): Rewrite function prototype in order to constify "exec_file" and accept a "std::string" for "allargs". * fork-child.c: Include <vector>. (breakup_args): Rewrite function, using C++. (fork_inferior): Rewrite function header, constify "exec_file_arg" and accept "std::string" for "allargs". Update the code to calculate "argv" based on "allargs". Update calls to "exec_fun" and "execvp". * gnu-nat.c (gnu_create_inferior): Rewrite function prototype in order to constify "exec_file" and accept a "std::string" for "allargs". * go32-nat.c (go32_create_inferior): Likewise. * inf-ptrace.c (inf_ptrace_create_inferior): Likewise. * infcmd.c (run_command_1): Constify "exec_file". Use "std::string" for inferior arguments. * inferior.h (fork_inferior): Update prototype. * linux-nat.c (linux_nat_create_inferior): Rewrite function prototype in order to constify "exec_file" and accept a "std::string" for "allargs". * nto-procfs.c (procfs_create_inferior): Likewise. * procfs.c (procfs_create_inferior): Likewise. * remote-sim.c (gdbsim_create_inferior): Likewise. * remote.c (extended_remote_run): Update code to accept "std::string" as argument. (extended_remote_create_inferior): Rewrite function prototype in order to constify "exec_file" and accept a "std::string" for "allargs". * rs6000-nat.c (super_create_inferior): Likewise. (rs6000_create_inferior): Likewise. * target.h (struct target_ops) <to_create_inferior>: Likewise. * windows-nat.c (windows_create_inferior): Likewise. gdb/gdbserver/ChangeLog: 2017-04-12 Sergio Durigan Junior <sergiodj@redhat.com> * server.c: Include <vector>. <program_argv, wrapper_argv>: Convert to std::vector. (start_inferior): Rewrite function to use C++. (handle_v_run): Likewise. Update code that calculates the argv based on the vRun packet; use C++. (captured_main): Likewise.
2017-03-23 02:54:49 +01:00
const char *exec_file, const std::string &allargs,
char **env, int from_tty)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
Move code to disable ASR to nat/ This patch moves the shared code present on gdb/linux-nat.c:linux_nat_create_inferior and gdb/gdbserver/linux-low.c:linux_create_inferior to nat/linux-personality.c. This code is responsible for disabling address space randomization based on user setting, and using <sys/personality.h> to do that. I decided to put the prototype of the maybe_disable_address_space_randomization on nat/linux-osdata.h because it seemed the best place to put it. I regression-tested this patch on Fedora 20 x86_64, and found no regressions. gdb/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h. (linux-personality.o): New rule. * common/common-defs.h: Include <stdint.h>. * config/aarch64/linux.mh (NATDEPFILES): Include linux-personality.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/s390/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * defs.h: Remove #include <stdint.h> (moved to common/common-defs.h). * linux-nat.c: Include nat/linux-personality.h. Remove #include <sys/personality.h>; do not define ADDR_NO_RANDOMIZE (moved to nat/linux-personality.c). (linux_nat_create_inferior): Remove code to disable address space randomization (moved to nat/linux-personality.c). Create cleanup to disable address space randomization. * nat/linux-personality.c: New file. * nat/linux-personality.h: Likewise. gdb/gdbserver/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add linux-personality.c. (linux-personality.o): New rule. * configure.srv (srv_linux_obj): Add linux-personality.o to the list of objects to be built. * linux-low.c: Include nat/linux-personality.h. (linux_create_inferior): Remove code to disable address space randomization (moved to ../nat/linux-personality.c). Create cleanup to disable address space randomization.
2015-01-15 21:10:49 +01:00
struct cleanup *restore_personality
= maybe_disable_address_space_randomization (disable_randomization);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* The fork_child mechanism is synchronous and calls target_wait, so
we have to mask the async mode. */
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
/* Make sure we report all signals during startup. */
linux_nat_pass_signals (ops, 0, NULL);
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
Kill pthread_ops_hack * target.h (struct target_ops): Make to_attach, to_detach, to_create_inferior and to_mourn_inferior accept a pointer to struct target_ops. (target_attach, target_create_inferior, target_create_inferior): Convert from macros to function. Find the right target to invoke a method of. (find_default_attach, find_default_create_inferior): New parameter ops. * corefile.c (core_file_command): Pass target to to_detach. * corelow.c (core_detach): Add 'ops' parameter. * fork-child.c (fork_inferior): Return the pid. Allow init_trace_fun to be NULL. * inf-ptrace (ptrace_ops_hack): Remove. (inf_ptrace_him): Remove, moving all logic into.... (inf_ptrace_create_inferior): ... here. Push the target passed as parameter. (inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach): Push/pop target passed as parameter, no ptrace_ops_hack. (inf_ptrace_target): Don't remember result. * inferior.h (fork_inferior): Adjust prototype. * linux-nat.c (linux_nat_create_inferior, linux_nat_attach) (linux_nat_detach, linux_nat_mourn_inferior): New parameter ops. Pass it to linux_ops target. * linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior): New parameter ops. Pass it to the target beneath. * remote.c (remote_mourn, extended_remote_mourn, remote_detach) (extended_remote_create_inferior): New parameter ops. Pass it further. * target.c (debug_to_attach, debug_to_detach) (debug_to_mourn_inferior): New parameter ops. (target_create_inferior): New. (update_current_target): Do not inherit to_attach, to_detach, to_create_inferiour, to_mourn_inferior. Do not default to_detach and to_mourn_inferior. (target_detach): Find the right target to use. (target_mourn_inferior): New. (find_default_attach, find_default_create_inferior): New parameter ops. Pass the found target when calling its method. (init_dummy_target): Provide fallback definition of to_detach. (target_attach): New. (debug_to_attach, debug_to_detach, debug_to_create_inferior) (debug_to_mourn_inferiour): New parameter ops. * aix-thread.c: Adjust. * bsd-uthread.c: Adjust. * gnu-nat.c: Adjust. * go32-nat.c: Adjust. * hpux-thread.c: Adjust. * inf-ttrace.c: Ajust. * monitor.c: Adjust. * nto-procfs.c: Adjust. * procfs.c: Adjust. * remote-m32r-sdi.c: Adjust. * remote-mips.c: Adjust. * remote-sim.c: Adjust. * rs6000-nat.c: Adjust. * sol-thread.c: Adjust. * win32-nat.c: Adjust. * dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
Move code to disable ASR to nat/ This patch moves the shared code present on gdb/linux-nat.c:linux_nat_create_inferior and gdb/gdbserver/linux-low.c:linux_create_inferior to nat/linux-personality.c. This code is responsible for disabling address space randomization based on user setting, and using <sys/personality.h> to do that. I decided to put the prototype of the maybe_disable_address_space_randomization on nat/linux-osdata.h because it seemed the best place to put it. I regression-tested this patch on Fedora 20 x86_64, and found no regressions. gdb/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h. (linux-personality.o): New rule. * common/common-defs.h: Include <stdint.h>. * config/aarch64/linux.mh (NATDEPFILES): Include linux-personality.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Likewise. * config/arm/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/powerpc/spu-linux.mh (NATDEPFILES): Likewise. * config/s390/linux.mh (NATDEPFILES): Likewise. * config/sparc/linux64.mh (NATDEPFILES): Likewise. * config/sparc/linux.mh (NATDEPFILES): Likewise. * config/tilegx/linux.mh (NATDEPFILES): Likewise. * config/xtensa/linux.mh (NATDEPFILES): Likewise. * defs.h: Remove #include <stdint.h> (moved to common/common-defs.h). * linux-nat.c: Include nat/linux-personality.h. Remove #include <sys/personality.h>; do not define ADDR_NO_RANDOMIZE (moved to nat/linux-personality.c). (linux_nat_create_inferior): Remove code to disable address space randomization (moved to nat/linux-personality.c). Create cleanup to disable address space randomization. * nat/linux-personality.c: New file. * nat/linux-personality.h: Likewise. gdb/gdbserver/ChangeLog 2015-01-15 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SFILES): Add linux-personality.c. (linux-personality.o): New rule. * configure.srv (srv_linux_obj): Add linux-personality.o to the list of objects to be built. * linux-low.c: Include nat/linux-personality.h. (linux_create_inferior): Remove code to disable address space randomization (moved to ../nat/linux-personality.c). Create cleanup to disable address space randomization.
2015-01-15 21:10:49 +01:00
do_cleanups (restore_personality);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
/* Callback for linux_proc_attach_tgid_threads. Attach to PTID if not
already attached. Returns true if a new LWP is found, false
otherwise. */
static int
attach_proc_task_lwp_callback (ptid_t ptid)
{
struct lwp_info *lp;
/* Ignore LWPs we're already attached to. */
lp = find_lwp_pid (ptid);
if (lp == NULL)
{
int lwpid = ptid_get_lwp (ptid);
if (ptrace (PTRACE_ATTACH, lwpid, 0, 0) < 0)
{
int err = errno;
/* Be quiet if we simply raced with the thread exiting.
EPERM is returned if the thread's task still exists, and
is marked as exited or zombie, as well as other
conditions, so in that case, confirm the status in
/proc/PID/status. */
if (err == ESRCH
|| (err == EPERM && linux_proc_pid_is_gone (lwpid)))
{
if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"Cannot attach to lwp %d: "
"thread is gone (%d: %s)\n",
lwpid, err, safe_strerror (err));
}
}
else
{
warning (_("Cannot attach to lwp %d: %s"),
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
lwpid,
linux_ptrace_attach_fail_reason_string (ptid,
err));
}
}
else
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"PTRACE_ATTACH %s, 0, 0 (OK)\n",
target_pid_to_str (ptid));
lp = add_lwp (ptid);
/* The next time we wait for this LWP we'll see a SIGSTOP as
PTRACE_ATTACH brings it to a halt. */
lp->signalled = 1;
/* We need to wait for a stop before being able to make the
next ptrace call on this LWP. */
lp->must_set_ptrace_flags = 1;
Fix PR gdb/19828: gdb -p <process from a container>: internal error When GDB attaches to a process, it looks at the /proc/PID/task/ dir for all clone threads of that process, and attaches to each of them. Usually, if there is more than one clone thread, it means the program is multi threaded and linked with pthreads. Thus when GDB soon after attaching finds and loads a libthread_db matching the process, it'll add a thread to the thread list for each of the initially found lower-level LWPs. If, however, GDB fails to find/load a matching libthread_db, nothing is adding the LWPs to the thread list. And because of that, "detach" hits an internal error: (gdb) PASS: gdb.threads/clone-attach-detach.exp: fg attach 1: attach info threads Id Target Id Frame * 1 LWP 6891 "clone-attach-de" 0x00007f87e5fd0790 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:84 (gdb) FAIL: gdb.threads/clone-attach-detach.exp: fg attach 1: info threads shows two LWPs detach .../src/gdb/thread.c:1010: internal-error: is_executing: Assertion `tp' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/clone-attach-detach.exp: fg attach 1: detach (GDB internal error) From here: ... #8 0x00000000007ba7cc in internal_error (file=0x98ea68 ".../src/gdb/thread.c", line=1010, fmt=0x98ea30 "%s: Assertion `%s' failed.") at .../src/gdb/common/errors.c:55 #9 0x000000000064bb83 in is_executing (ptid=...) at .../src/gdb/thread.c:1010 #10 0x00000000004c23bb in get_pending_status (lp=0x12c5cc0, status=0x7fffffffdc0c) at .../src/gdb/linux-nat.c:1235 #11 0x00000000004c2738 in detach_callback (lp=0x12c5cc0, data=0x0) at .../src/gdb/linux-nat.c:1317 #12 0x00000000004c1a2a in iterate_over_lwps (filter=..., callback=0x4c2599 <detach_callback>, data=0x0) at .../src/gdb/linux-nat.c:899 #13 0x00000000004c295c in linux_nat_detach (ops=0xe7bd30, args=0x0, from_tty=1) at .../src/gdb/linux-nat.c:1358 #14 0x000000000068284d in delegate_detach (self=0xe7bd30, arg1=0x0, arg2=1) at .../src/gdb/target-delegates.c:34 #15 0x0000000000694141 in target_detach (args=0x0, from_tty=1) at .../src/gdb/target.c:2241 #16 0x0000000000630582 in detach_command (args=0x0, from_tty=1) at .../src/gdb/infcmd.c:2975 ... Tested on x86-64 Fedora 23. Also confirmed the test passes against gdbserver with "maint set target-non-stop". gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (attach_proc_task_lwp_callback): Mark the lwp resumed, and add the thread to GDB's thread list. testsuite/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * gdb.threads/clone-attach-detach.c: New file. * gdb.threads/clone-attach-detach.exp: New file.
2016-05-24 15:47:57 +02:00
/* So that wait collects the SIGSTOP. */
lp->resumed = 1;
/* Also add the LWP to gdb's thread list, in case a
matching libthread_db is not found (or the process uses
raw clone). */
add_thread (lp->ptid);
set_running (lp->ptid, 1);
set_executing (lp->ptid, 1);
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
}
return 1;
}
return 0;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static void
linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
struct lwp_info *lp;
int status;
ptid_t ptid;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
/* Make sure we report all signals during attach. */
linux_nat_pass_signals (ops, 0, NULL);
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
TRY
{
linux_ops->to_attach (ops, args, from_tty);
}
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
CATCH (ex, RETURN_MASK_ERROR)
{
pid_t pid = parse_pid_to_attach (args);
struct buffer buffer;
char *message, *buffer_s;
message = xstrdup (ex.message);
make_cleanup (xfree, message);
buffer_init (&buffer);
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 20:07:33 +02:00
linux_ptrace_attach_fail_reason (pid, &buffer);
buffer_grow_str0 (&buffer, "");
buffer_s = buffer_finish (&buffer);
make_cleanup (xfree, buffer_s);
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 20:07:33 +02:00
if (*buffer_s != '\0')
throw_error (ex.error, "warning: %s\n%s", buffer_s, message);
else
throw_error (ex.error, "%s", message);
}
Split TRY_CATCH into TRY + CATCH This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
2015-03-07 16:14:14 +01:00
END_CATCH
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* The ptrace base target adds the main thread with (pid,0,0)
format. Decorate it with lwp info. */
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid = ptid_build (ptid_get_pid (inferior_ptid),
ptid_get_pid (inferior_ptid),
0);
thread_change_ptid (inferior_ptid, ptid);
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* Add the initial process as the first LWP to the list. */
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
lp = add_initial_lwp (ptid);
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
status = linux_nat_post_attach_wait (lp->ptid, 1, &lp->signalled);
if (!WIFSTOPPED (status))
{
if (WIFEXITED (status))
{
int exit_code = WEXITSTATUS (status);
target_terminal_ours ();
Consolidate target_mourn_inferior between GDB and gdbserver This patch consolidates the API of target_mourn_inferior between GDB and gdbserver, in my continuing efforts to make sharing the fork_inferior function possible between both. GDB's version of the function did not care about the inferior's ptid being mourned, but gdbserver's needed to know this information. Since it actually makes sense to pass the ptid as an argument, instead of depending on a global value directly (which GDB's version did), I decided to make the generic API to accept it. I then went on and extended all calls being made on GDB to include a ptid argument (which ended up being inferior_ptid most of the times, anyway), and now we have a more sane interface. On GDB's side, after talking to Pedro a bit about it, we decided that just an assertion to make sure that the ptid being passed is equal to inferior_ptid would be enough for now, on the GDB side. We can remove the assertion and perform more operations later if we ever pass anything different than inferior_ptid. Regression tested on our BuildBot, everything OK. I'd appreciate a special look at gdb/windows-nat.c's modification because I wasn't really sure what to do there. It seemed to me that maybe I should build a ptid out of the process information there, but then I am almost sure the assertion on GDB's side would trigger. gdb/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * darwin-nat.c (darwin_kill_inferior): Adjusting call to target_mourn_inferior to include ptid_t argument. * fork-child.c (startup_inferior): Likewise. * gnu-nat.c (gnu_kill_inferior): Likewise. * inf-ptrace.c (inf_ptrace_kill): Likewise. * infrun.c (handle_inferior_event_1): Likewise. * linux-nat.c (linux_nat_attach): Likewise. (linux_nat_kill): Likewise. * nto-procfs.c (interrupt_query): Likewise. (procfs_interrupt): Likewise. (procfs_kill_inferior): Likewise. * procfs.c (procfs_kill_inferior): Likewise. * record.c (record_mourn_inferior): Likewise. * remote-sim.c (gdbsim_kill): Likewise. * remote.c (remote_detach_1): Likewise. (remote_kill): Likewise. * target.c (target_mourn_inferior): Change declaration to accept new ptid_t argument; use gdb_assert on it. * target.h (target_mourn_inferior): Move function prototype from here... * target/target.h (target_mourn_inferior): ... to here. Adjust it to accept new ptid_t argument. * windows-nat.c (get_windows_debug_event): Adjusting call to target_mourn_inferior to include ptid_t argument. gdb/gdbserver/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (start_inferior): Call target_mourn_inferior instead of mourn_inferior; pass ptid_t argument to it. (resume): Likewise. (handle_target_event): Likewise. * target.c (target_mourn_inferior): New function. * target.h (mourn_inferior): Delete macro.
2016-09-12 05:45:31 +02:00
target_mourn_inferior (inferior_ptid);
if (exit_code == 0)
error (_("Unable to attach: program exited normally."));
else
error (_("Unable to attach: program exited with code %d."),
exit_code);
}
else if (WIFSIGNALED (status))
{
enum gdb_signal signo;
target_terminal_ours ();
Consolidate target_mourn_inferior between GDB and gdbserver This patch consolidates the API of target_mourn_inferior between GDB and gdbserver, in my continuing efforts to make sharing the fork_inferior function possible between both. GDB's version of the function did not care about the inferior's ptid being mourned, but gdbserver's needed to know this information. Since it actually makes sense to pass the ptid as an argument, instead of depending on a global value directly (which GDB's version did), I decided to make the generic API to accept it. I then went on and extended all calls being made on GDB to include a ptid argument (which ended up being inferior_ptid most of the times, anyway), and now we have a more sane interface. On GDB's side, after talking to Pedro a bit about it, we decided that just an assertion to make sure that the ptid being passed is equal to inferior_ptid would be enough for now, on the GDB side. We can remove the assertion and perform more operations later if we ever pass anything different than inferior_ptid. Regression tested on our BuildBot, everything OK. I'd appreciate a special look at gdb/windows-nat.c's modification because I wasn't really sure what to do there. It seemed to me that maybe I should build a ptid out of the process information there, but then I am almost sure the assertion on GDB's side would trigger. gdb/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * darwin-nat.c (darwin_kill_inferior): Adjusting call to target_mourn_inferior to include ptid_t argument. * fork-child.c (startup_inferior): Likewise. * gnu-nat.c (gnu_kill_inferior): Likewise. * inf-ptrace.c (inf_ptrace_kill): Likewise. * infrun.c (handle_inferior_event_1): Likewise. * linux-nat.c (linux_nat_attach): Likewise. (linux_nat_kill): Likewise. * nto-procfs.c (interrupt_query): Likewise. (procfs_interrupt): Likewise. (procfs_kill_inferior): Likewise. * procfs.c (procfs_kill_inferior): Likewise. * record.c (record_mourn_inferior): Likewise. * remote-sim.c (gdbsim_kill): Likewise. * remote.c (remote_detach_1): Likewise. (remote_kill): Likewise. * target.c (target_mourn_inferior): Change declaration to accept new ptid_t argument; use gdb_assert on it. * target.h (target_mourn_inferior): Move function prototype from here... * target/target.h (target_mourn_inferior): ... to here. Adjust it to accept new ptid_t argument. * windows-nat.c (get_windows_debug_event): Adjusting call to target_mourn_inferior to include ptid_t argument. gdb/gdbserver/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (start_inferior): Call target_mourn_inferior instead of mourn_inferior; pass ptid_t argument to it. (resume): Likewise. (handle_target_event): Likewise. * target.c (target_mourn_inferior): New function. * target.h (mourn_inferior): Delete macro.
2016-09-12 05:45:31 +02:00
target_mourn_inferior (inferior_ptid);
signo = gdb_signal_from_host (WTERMSIG (status));
error (_("Unable to attach: program terminated with signal "
"%s, %s."),
gdb_signal_to_name (signo),
gdb_signal_to_string (signo));
}
internal_error (__FILE__, __LINE__,
_("unexpected status %d for PID %ld"),
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
status, (long) ptid_get_lwp (ptid));
}
lp->stopped = 1;
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* Save the wait status to report later. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
lp->resumed = 1;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LNA: waitpid %ld, saving status %s\n",
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
(long) ptid_get_pid (lp->ptid), status_to_str (status));
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
lp->status = status;
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
/* We must attach to every LWP. If /proc is mounted, use that to
find them now. The inferior may be using raw clone instead of
using pthreads. But even if it is using pthreads, thread_db
walks structures in the inferior's address space to find the list
of threads/LWPs, and those structures may well be corrupted.
Note that once thread_db is loaded, we'll still use it to list
threads and associate pthread info with each LWP. */
linux_proc_attach_tgid_threads (ptid_get_pid (lp->ptid),
attach_proc_task_lwp_callback);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (target_can_async_p ())
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
target_async (1);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
/* Get pending signal of THREAD as a host signal number, for detaching
purposes. This is the signal the thread last stopped for, which we
need to deliver to the thread when detaching, otherwise, it'd be
suppressed/lost. */
static int
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
get_detach_signal (struct lwp_info *lp)
{
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
enum gdb_signal signo = GDB_SIGNAL_0;
/* If we paused threads momentarily, we may have stored pending
events in lp->status or lp->waitstatus (see stop_wait_callback),
and GDB core hasn't seen any signal for those threads.
Otherwise, the last signal reported to the core is found in the
thread object's stop_signal.
There's a corner case that isn't handled here at present. Only
if the thread stopped with a TARGET_WAITKIND_STOPPED does
stop_signal make sense as a real signal to pass to the inferior.
Some catchpoint related events, like
TARGET_WAITKIND_(V)FORK|EXEC|SYSCALL, have their stop_signal set
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
to GDB_SIGNAL_SIGTRAP when the catchpoint triggers. But,
those traps are debug API (ptrace in our case) related and
induced; the inferior wouldn't see them if it wasn't being
traced. Hence, we should never pass them to the inferior, even
when set to pass state. Since this corner case isn't handled by
infrun.c when proceeding with a signal, for consistency, neither
do we handle it here (or elsewhere in the file we check for
signal pass state). Normally SIGTRAP isn't set to pass state, so
this is really a corner case. */
if (lp->waitstatus.kind != TARGET_WAITKIND_IGNORE)
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
signo = GDB_SIGNAL_0; /* a pending ptrace event, not a real signal. */
else if (lp->status)
signo = gdb_signal_from_host (WSTOPSIG (lp->status));
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
else if (target_is_non_stop_p () && !is_executing (lp->ptid))
{
struct thread_info *tp = find_thread_ptid (lp->ptid);
if (tp->suspend.waitstatus_pending_p)
signo = tp->suspend.waitstatus.value.sig;
else
signo = tp->suspend.stop_signal;
}
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
else if (!target_is_non_stop_p ())
{
struct target_waitstatus last;
ptid_t last_ptid;
get_last_target_status (&last_ptid, &last);
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (ptid_get_lwp (lp->ptid) == ptid_get_lwp (last_ptid))
{
struct thread_info *tp = find_thread_ptid (lp->ptid);
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
signo = tp->suspend.stop_signal;
}
}
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
if (signo == GDB_SIGNAL_0)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"GPT: lwp %s has no pending signal\n",
target_pid_to_str (lp->ptid));
}
else if (!signal_pass_state (signo))
{
if (debug_linux_nat)
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
fprintf_unfiltered (gdb_stdlog,
"GPT: lwp %s had signal %s, "
"but it is in no pass state\n",
target_pid_to_str (lp->ptid),
gdb_signal_to_string (signo));
}
else
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"GPT: lwp %s has pending signal %s\n",
target_pid_to_str (lp->ptid),
gdb_signal_to_string (signo));
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
return gdb_signal_to_host (signo);
}
return 0;
}
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
/* Detach from LP. If SIGNO_P is non-NULL, then it points to the
signal number that should be passed to the LWP when detaching.
Otherwise pass any pending signal the LWP may have, if any. */
static void
detach_one_lwp (struct lwp_info *lp, int *signo_p)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
int lwpid = ptid_get_lwp (lp->ptid);
int signo;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb_assert (lp->status == 0 || WIFSTOPPED (lp->status));
if (debug_linux_nat && lp->status)
fprintf_unfiltered (gdb_stdlog, "DC: Pending %s for %s on detach.\n",
strsignal (WSTOPSIG (lp->status)),
target_pid_to_str (lp->ptid));
/* If there is a pending SIGSTOP, get rid of it. */
if (lp->signalled)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"DC: Sending SIGCONT to %s\n",
target_pid_to_str (lp->ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
kill_lwp (lwpid, SIGCONT);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
lp->signalled = 0;
}
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
if (signo_p == NULL)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
/* Pass on any pending signal for this LWP. */
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
signo = get_detach_signal (lp);
}
else
signo = *signo_p;
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
/* Preparing to resume may try to write registers, and fail if the
lwp is zombie. If that happens, ignore the error. We'll handle
it below, when detach fails with ESRCH. */
TRY
{
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
if (linux_nat_prepare_to_resume != NULL)
linux_nat_prepare_to_resume (lp);
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
}
CATCH (ex, RETURN_MASK_ERROR)
{
if (!check_ptrace_stopped_lwp_gone (lp))
throw_exception (ex);
}
END_CATCH
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
if (ptrace (PTRACE_DETACH, lwpid, 0, signo) < 0)
{
int save_errno = errno;
/* We know the thread exists, so ESRCH must mean the lwp is
zombie. This can happen if one of the already-detached
threads exits the whole thread group. In that case we're
still attached, and must reap the lwp. */
if (save_errno == ESRCH)
{
int ret, status;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
ret = my_waitpid (lwpid, &status, __WALL);
if (ret == -1)
{
warning (_("Couldn't reap LWP %d while detaching: %s"),
lwpid, strerror (errno));
}
else if (!WIFEXITED (status) && !WIFSIGNALED (status))
{
warning (_("Reaping LWP %d while detaching "
"returned unexpected status 0x%x"),
lwpid, status);
}
}
else
{
error (_("Can't detach %s: %s"), target_pid_to_str (lp->ptid),
safe_strerror (save_errno));
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
else if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"PTRACE_DETACH (%s, %s, 0) (OK)\n",
target_pid_to_str (lp->ptid),
strsignal (signo));
}
delete_lwp (lp->ptid);
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
static int
detach_callback (struct lwp_info *lp, void *data)
{
/* We don't actually detach from the thread group leader just yet.
If the thread group exits, we must reap the zombie clone lwps
before we're able to reap the leader. */
if (ptid_get_lwp (lp->ptid) != ptid_get_pid (lp->ptid))
detach_one_lwp (lp, NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
static void
constify to_detach This patch constifies the target_ops method to_detach. This is a small cleanup, but also, I think, a bug-prevention fix, since gdb already acts as if the "args" argument here was const. In particular, top.c:quit_force calls kill_or_detach via iterate_over_inferiors. kill_or_detach calls target_detach, passing the same argument each time. So, if one of these methods was not const-correct, then kill_or_detach would change its behavior in a strange way. I could not build every target I modified in this patch. I've inspected them all by hand, though. Many targets do not use the "args" parameter; a couple pass it to atoi; and a few pass it on to the to_detach method of the target beneath. The only code that required a real change was in linux-nat.c, and that only needed the introduction of a temporary variable for const-correctness. 2013-11-08 Tom Tromey <tromey@redhat.com> * aix-thread.c (aix_thread_detach): Update. * corelow.c (core_detach): Update. * darwin-nat.c (darwin_detach): Update. * dec-thread.c (dec_thread_detach): Update. * gnu-nat.c (gnu_detach): Update. * go32-nat.c (go32_detach): Update. * inf-ptrace.c (inf_ptrace_detach): Update. * inf-ttrace.c (inf_ttrace_detach): Update. * linux-fork.c (linux_fork_detach): Update. * linux-fork.h (linux_fork_detach): Update. * linux-nat.c (linux_nat_detach): Update. Introduce "tem" local for const-correctness. * linux-thread-db.c (thread_db_detach): Update. * monitor.c (monitor_detach): Update. * nto-procfs.c (procfs_detach): Update. * procfs.c (procfs_detach): Update. * record.c (record_detach): Update. * record.h (record_detach): Update. * remote-m32r-sdi.c (m32r_detach): Update. * remote-mips.c (mips_detach): Update. * remote-sim.c (gdbsim_detach): Update. * remote.c (remote_detach_1, remote_detach) (extended_remote_detach): Update. * sol-thread.c (sol_thread_detach): Update. * target.c (target_detach): Make "args" const. (init_dummy_target): Update. * target.h (struct target_ops) <to_detach>: Make argument const. (target_detach): Likewise. * windows-nat.c (windows_detach): Update.
2013-03-19 16:23:17 +01:00
linux_nat_detach (struct target_ops *ops, const char *args, int from_tty)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
int pid;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
struct lwp_info *main_lwp;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_pid (inferior_ptid);
/* Don't unregister from the event loop, as there may be other
inferiors running. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* Stop all threads before detaching. ptrace requires that the
thread is stopped to sucessfully detach. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (pid_to_ptid (pid), stop_callback, NULL);
/* ... and wait until all of them have reported back that
they're no longer running. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (pid_to_ptid (pid), stop_wait_callback, NULL);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (pid_to_ptid (pid), detach_callback, NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Only the initial process should be left right now. */
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
gdb_assert (num_lwps (ptid_get_pid (inferior_ptid)) == 1);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
main_lwp = find_lwp_pid (pid_to_ptid (pid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (forks_exist_p ())
{
/* Multi-fork case. The current inferior_ptid is being detached
from, but there are other viable forks to debug. Detach from
the current fork, and context-switch to the first
available. */
linux_fork_detach (args, from_tty);
}
else
Fix failure to detach if process exits while detaching on Linux This commit fixes detaching on Linux when some thread exits the whole thread group (process) just while we're detaching. On Linux, a ptracer must detach from each LWP individually, with PTRACE_DETACH. Since PTRACE_DETACH sets the thread running free, if one of the already-detached threads causes the whole thread group to exit (e.g., simply calls exit), the kernel force-kills the other threads in the group, making them zombie, just as we're still detaching them. Since PTRACE_DETACH against a zombie thread fails with ESRCH, and gdb/gdbserver are not expecting this, the detach fails with an error like: "Can't detach process: No such process.". This patch detects this detach failure as normal, and instead of erroring out, reaps the now-dead thread. New test included, that exercises several different scenarios that cause GDB/GDBserver to error out when it should not. Tested on x86-64 GNU/Linux with {unix, native-gdbserver, native-extended-gdbserver} Note: without the previous fix, the "single-process + continue" variant of the new test would fail with: (gdb) PASS: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: switch to parent continue Continuing. Warning: Could not insert hardware watchpoint 3. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. Command aborted. (gdb) FAIL: gdb.threads/process-dies-while-detaching.exp: single-process: continue: watchpoint: continue gdb/gdbserver/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * linux-low.c: Change interface to take the target lwp_info pointer directly and return void. Handle detaching from a zombie thread. (linux_detach_lwp_callback): New function. (linux_detach): Detach from the leader thread after detaching from the clone threads. gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * inf-ptrace.c (inf_ptrace_detach_success): New function, factored out from ... (inf_ptrace_detach): ... here. * inf-ptrace.h (inf_ptrace_detach_success): New declaration. * linux-nat.c (get_pending_status): Rename to ... (get_detach_signal): ... this, and return a host signal instead of filling in a wait status. (detach_one_lwp): New function, factored out from detach_callback and adjusted to handle detaching from a zombie thread. (detach_callback): Skip the leader thread. (linux_nat_detach): No longer defer to inf_ptrace_detach to detach the leader thread, nor build a signal string to pass down. Instead, use target_announce_detach, detach_one_lwp and inf_ptrace_detach_success. gdb/testsuite/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> Antoine Tremblay <antoine.tremblay@ericsson.com> * gdb.threads/process-dies-while-detaching.c: New file. * gdb.threads/process-dies-while-detaching.exp: New file.
2016-07-01 12:16:33 +02:00
{
int signo;
target_announce_detach (from_tty);
/* Pass on any pending signal for the last LWP, unless the user
requested detaching with a different signal (most likely 0,
meaning, discard the signal). */
if (args != NULL)
signo = atoi (args);
else
signo = get_detach_signal (main_lwp);
detach_one_lwp (main_lwp, &signo);
inf_ptrace_detach_success (ops);
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Resume execution of the inferior process. If STEP is nonzero,
single-step it. If SIGNAL is nonzero, give it that signal. */
static void
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
linux_resume_one_lwp_throw (struct lwp_info *lp, int step,
enum gdb_signal signo)
{
lp->step = step;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* stop_pc doubles as the PC the LWP had when it was last resumed.
We only presently need that if the LWP is stepped though (to
handle the case of stepping a breakpoint instruction). */
if (step)
{
struct regcache *regcache = get_thread_regcache (lp->ptid);
lp->stop_pc = regcache_read_pc (regcache);
}
else
lp->stop_pc = 0;
if (linux_nat_prepare_to_resume != NULL)
linux_nat_prepare_to_resume (lp);
Linux/ptrace: don't convert ptids when asking inf-ptrace layer to resume LWP Ref: https://sourceware.org/ml/gdb-patches/2015-03/msg00060.html The record-btrace target can hit an assertion here: Breakpoint 1, record_btrace_fetch_registers (ops=0x974bfc0 <record_btrace_ops>, regcache=0x9a0a798, regno=8) at gdb/record-btrace.c:1202 1202 gdb_assert (tp != NULL); (gdb) p regcache->ptid $3 = {pid = 23856, lwp = 0, tid = 0} The problem is that the linux-nat layer converts the ptid to a single-process ptid before passing the request down to the inf-ptrace layer, which loses information, and then record-btrace can't find the corresponding thread in GDB's thread list: (gdb) bt #0 record_btrace_fetch_registers (ops=0x974bfc0 <record_btrace_ops>, regcache=0x9a0a798, regno=8) at gdb/record-btrace.c:1202 #1 0x083f4ee2 in delegate_fetch_registers (self=0x974bfc0 <record_btrace_ops>, arg1=0x9a0a798, arg2=8) at gdb/target-delegates.c:149 #2 0x08406562 in target_fetch_registers (regcache=0x9a0a798, regno=8) at gdb/target.c:3279 #3 0x08355255 in regcache_raw_read (regcache=0x9a0a798, regnum=8, buf=0xbfffe6c0 "¨\003\222\tÀ8kIøæÿ¿HO5\b\035]") at gdb/regcache.c:643 #4 0x083558a7 in regcache_cooked_read (regcache=0x9a0a798, regnum=8, buf=0xbfffe6c0 "¨\003\222\tÀ8kIøæÿ¿HO5\b\035]") at gdb/regcache.c:734 #5 0x08355de3 in regcache_cooked_read_unsigned (regcache=0x9a0a798, regnum=8, val=0xbfffe738) at gdb/regcache.c:838 #6 0x0827a106 in i386_linux_resume (ops=0x9737ca0 <linux_ops_saved>, ptid=..., step=1, signal=GDB_SIGNAL_0) at gdb/i386-linux-nat.c:670 #7 0x08280c12 in linux_resume_one_lwp (lp=0x9a0a5b8, step=1, signo=GDB_SIGNAL_0) at gdb/linux-nat.c:1529 #8 0x08281281 in linux_nat_resume (ops=0x98da608, ptid=..., step=1, signo=GDB_SIGNAL_0) at gdb/linux-nat.c:1708 #9 0x0850738e in record_btrace_resume (ops=0x98da608, ptid=..., step=1, signal=GDB_SIGNAL_0) at gdb/record-btrace.c:1760 ... The fix is just to not lose information, and let the intact ptid reach record-btrace.c. Tested on x86-64 Fedora 20, -m32. gdb/ChangeLog: 2015-03-03 Pedro Alves <palves@redhat.com> * i386-linux-nat.c (i386_linux_resume): Get the ptrace PID out of the lwp field of ptid. Pass the full ptid to get_thread_regcache. * inf-ptrace.c (get_ptrace_pid): New function. (inf_ptrace_resume): Use it. * linux-nat.c (linux_resume_one_lwp): Pass the LWP's ptid ummodified to the lower layer.
2015-03-03 14:33:44 +01:00
linux_ops->to_resume (linux_ops, lp->ptid, step, signo);
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
/* Successfully resumed. Clear state that no longer makes sense,
and mark the LWP as running. Must not do this before resuming
otherwise if that fails other code will be confused. E.g., we'd
later try to stop the LWP and hang forever waiting for a stop
status. Note that we must not throw after this is cleared,
otherwise handle_zombie_lwp_error would get confused. */
lp->stopped = 0;
lp->core = -1;
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
lp->stop_reason = TARGET_STOPPED_BY_NO_REASON;
registers_changed_ptid (lp->ptid);
}
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
/* Called when we try to resume a stopped LWP and that errors out. If
the LWP is no longer in ptrace-stopped state (meaning it's zombie,
or about to become), discard the error, clear any pending status
the LWP may have, and return true (we'll collect the exit status
soon enough). Otherwise, return false. */
static int
check_ptrace_stopped_lwp_gone (struct lwp_info *lp)
{
/* If we get an error after resuming the LWP successfully, we'd
confuse !T state for the LWP being gone. */
gdb_assert (lp->stopped);
/* We can't just check whether the LWP is in 'Z (Zombie)' state,
because even if ptrace failed with ESRCH, the tracee may be "not
yet fully dead", but already refusing ptrace requests. In that
case the tracee has 'R (Running)' state for a little bit
(observed in Linux 3.18). See also the note on ESRCH in the
ptrace(2) man page. Instead, check whether the LWP has any state
other than ptrace-stopped. */
/* Don't assume anything if /proc/PID/status can't be read. */
if (linux_proc_pid_is_trace_stopped_nowarn (ptid_get_lwp (lp->ptid)) == 0)
{
lp->stop_reason = TARGET_STOPPED_BY_NO_REASON;
lp->status = 0;
lp->waitstatus.kind = TARGET_WAITKIND_IGNORE;
return 1;
}
return 0;
}
/* Like linux_resume_one_lwp_throw, but no error is thrown if the LWP
disappears while we try to resume it. */
static void
linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
{
TRY
{
linux_resume_one_lwp_throw (lp, step, signo);
}
CATCH (ex, RETURN_MASK_ERROR)
{
if (!check_ptrace_stopped_lwp_gone (lp))
throw_exception (ex);
}
END_CATCH
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Resume LP. */
static void
resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (lp->stopped)
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
{
struct inferior *inf = find_inferior_ptid (lp->ptid);
if (inf->vfork_child != NULL)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RC: Not resuming %s (vfork parent)\n",
target_pid_to_str (lp->ptid));
}
else if (!lwp_status_pending_p (lp))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RC: Resuming sibling %s, %s, %s\n",
target_pid_to_str (lp->ptid),
(signo != GDB_SIGNAL_0
? strsignal (gdb_signal_to_host (signo))
: "0"),
step ? "step" : "resume");
linux_resume_one_lwp (lp, step, signo);
}
else
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RC: Not resuming sibling %s (has pending)\n",
target_pid_to_str (lp->ptid));
}
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
}
else
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RC: Not resuming sibling %s (not stopped)\n",
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
target_pid_to_str (lp->ptid));
}
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
/* Callback for iterate_over_lwps. If LWP is EXCEPT, do nothing.
Resume LWP with the last stop signal, if it is in pass state. */
static int
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
linux_nat_resume_callback (struct lwp_info *lp, void *except)
{
enum gdb_signal signo = GDB_SIGNAL_0;
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
if (lp == except)
return 0;
if (lp->stopped)
{
struct thread_info *thread;
thread = find_thread_ptid (lp->ptid);
if (thread != NULL)
{
Always pass signals to the right thread Currently, GDB can pass a signal to the wrong thread in several different but related scenarios. E.g., if thread 1 stops for signal SIGFOO, the user switches to thread 2, and then issues "continue", SIGFOO is actually delivered to thread 2, not thread 1. This obviously messes up programs that use pthread_kill to send signals to specific threads. This has been a known issue for a long while. Back in 2008 when I made stop_signal be per-thread (2020b7ab), I kept the behavior -- see code in 'proceed' being removed -- wanting to come back to it later. The time has finally come now. The patch fixes this -- on resumption, intercepted signals are always delivered to the thread that had intercepted them. Another example: if thread 1 stops for a breakpoint, the user switches to thread 2, and then issues "signal SIGFOO", SIGFOO is actually delivered to thread 1, not thread 2, because 'proceed' first switches to thread 1 to step over its breakpoint... If the user deletes the breakpoint before issuing "signal FOO", then the signal is delivered to thread 2 (the current thread). "signal SIGFOO" can be used for two things: inject a signal in the program while the program/thread had stopped for none, bypassing "handle nopass"; or changing/suppressing a signal the program had stopped for. These scenarios are really two faces of the same coin, and GDB can't really guess what the user is trying to do. GDB might have intercepted signals in more than one thread even (see the new signal-command-multiple-signals-pending.exp test). At least in the inject case, it's obviously clear to me that the user means to deliver the signal to the currently selected thread, so best is to make the command's behavior consistent and easy to explain. Then, if the user is trying to suppress/change a signal the program had stopped for instead of injecting a new signal, but, the user had changed threads meanwhile, then she will be surprised that with: (gdb) continue Thread 1 stopped for signal SIGFOO. (gdb) thread 2 (gdb) signal SIGBAR ... GDB actually delivers SIGFOO to thread 1, and SIGBAR to thread 2 (with scheduler-locking off, which is the default, because then "signal" or any other resumption command resumes all threads). So the patch makes GDB detect that, and ask for confirmation: (gdb) thread 1 [Switching to thread 1 (Thread 10979)] (gdb) signal SIGUSR2 Note: Thread 3 previously stopped with signal SIGUSR2, User defined signal 2. Thread 2 previously stopped with signal SIGUSR1, User defined signal 1. Continuing thread 1 (the current thread) with specified signal will still deliver the signals noted above to their respective threads. Continue anyway? (y or n) All these scenarios are covered by the new tests. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ 2014-07-25 Pedro Alves <palves@redhat.com> * NEWS: Mention signal passing and "signal" command changes. * gdbthread.h (struct thread_suspend_state) <stop_signal>: Extend comment. * breakpoint.c (until_break_command): Adjust clear_proceed_status call. * infcall.c (run_inferior_call): Adjust clear_proceed_status call. * infcmd.c (proceed_thread_callback, continue_1, step_once) (jump_command): Adjust clear_proceed_status call. (signal_command): Warn if other thread that are resumed have signals that will be delivered. Adjust clear_proceed_status call. (until_next_command, finish_command) (proceed_after_attach_callback, attach_command_post_wait) (attach_command): Adjust clear_proceed_status call. * infrun.c (proceed_after_vfork_done): Likewise. (proceed_after_attach_callback): Adjust comment. (clear_proceed_status_thread): Clear stop_signal if not in pass state. (clear_proceed_status_callback): Delete. (clear_proceed_status): New 'step' parameter. Only clear the proceed status of threads the command being prepared is about to resume. (proceed): If passed in an explicit signal, override stop_signal with it. Don't pass the last stop signal to the thread we're resuming. (init_wait_for_inferior): Adjust clear_proceed_status call. (switch_back_to_stepped_thread): Clear the signal if it should not be passed. * infrun.h (clear_proceed_status): New 'step' parameter. (user_visible_resume_ptid): Add comment. * linux-nat.c (linux_nat_resume_callback): Don't check whether the signal is in pass state. * remote.c (append_pending_thread_resumptions): Likewise. * mi/mi-main.c (proceed_thread): Adjust clear_proceed_status call. gdb/doc/ 2014-07-25 Pedro Alves <palves@redhat.com> Eli Zaretskii <eliz@gnu.org> * gdb.texinfo (Signaling) <signal command>: Explain what happens with multi-threaded programs. gdb/testsuite/ 2014-07-25 Pedro Alves <palves@redhat.com> * gdb.threads/signal-command-handle-nopass.c: New file. * gdb.threads/signal-command-handle-nopass.exp: New file. * gdb.threads/signal-command-multiple-signals-pending.c: New file. * gdb.threads/signal-command-multiple-signals-pending.exp: New file. * gdb.threads/signal-delivered-right-thread.c: New file. * gdb.threads/signal-delivered-right-thread.exp: New file.
2014-07-25 17:57:31 +02:00
signo = thread->suspend.stop_signal;
thread->suspend.stop_signal = GDB_SIGNAL_0;
}
}
resume_lwp (lp, 0, signo);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
static int
resume_clear_callback (struct lwp_info *lp, void *data)
{
lp->resumed = 0;
lp->last_resume_kind = resume_stop;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
static int
resume_set_callback (struct lwp_info *lp, void *data)
{
lp->resumed = 1;
lp->last_resume_kind = resume_continue;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
static void
* corelow.c (get_core_registers): Adjust. (core_file_thread_alive): Rename to... (core_thread_alive): ... this. (core_pid_to_str): Try gdbarch_core_pid_to_str first. (init_core_ops): Adjust. (coreops_suppress_target): Delete. (_initialize_corelow): Unconditionally add core_ops. * procfs.c: Include "inf-child.h". (procfs_ops): Delete. (init_procfs_ops): Delete. Reimplement as... (procfs_target): ... this, inheriting from inf-child. (procfs_attach, procfs_detach, procfs_fetch_registers): Adjust. (procfs_prepare_to_store): Delete. (procfs_store_registers, procfs_resume): Adjust. (procfs_open): Delete. (procfs_suppress_run): Delete. (procfs_can_run): Delete. (procfs_mourn_inferior): Adjust. (procfs_init_inferior): Add target_ops parameter. Adjust. (procfs_create_inferior): Don't pass procfs_init_inferior to fork_inferior. Instead call it after fork_inferior returns. (procfs_find_new_threads): Adjust. (_initialize_procfs): Adjust to use procfs_target instead of init_procfs_ops. * sol-thread.c (orig_core_ops, sol_core_ops): Delete. (lwp_to_thread): Use target_thread_alive. (sol_thread_open): Delete. (sol_thread_attach): Delete. (sol_thread_detach, sol_thread_resume, sol_thread_wait) (sol_thread_fetch_registers, sol_thread_store_registers): Adjust to use find_target_beneath. (sol_thread_prepare_to_store, sol_thread_xfer_memory): Delete. (sol_thread_xfer_partial): Adjust to use find_target_beneath. (sol_thread_files_info, sol_thread_kill_inferior): Delete. (check_for_thread_db): New. (sol_thread_notice_signals, sol_thread_create_inferior): Delete. (sol_thread_new_objfile): Call check_for_thread_db. (sol_thread_mourn_inferior): Adjust to use find_target_beneath. (sol_thread_can_run): Delete. (sol_thread_alive): Adjust to use find_target_beneath. (sol_thread_stop): Delete. (rw_common): Use target_write_memory or target_read_memory. (ps_lgetregs, ps_lgetfpregs): Use target_fetch_registers. (ps_lsetregs, ps_lsetfpregs): Use target_store_registers. (solaris_pid_to_str): Remove check for libthread_db initialization failing. (sol_find_new_threads): Remove check for libthread_db initialization failing, or for an invalid inferior_ptid. Adjust to use find_target_beneath. (sol_core_open, sol_core_close, sol_core_detach, sol_core_files_info, sol_find_memory_regions, sol_make_note_section, ignore): Delete. (init_sol_thread_ops): Make it a thread_stratum target. Remove unneeded callback settings. (init_sol_core_ops): Delete. (_initialize_sol_thread): No longer call init_sol_core_ops, set procfs_suppress_run, or hack with core_ops. * target.h (struct target_ops): Add a target_ops * parameter to to_resume, to_fetch_registers, to_store_registers, to_thread_alive and to_find_new_threads. (target_fetch_registers, target_store_registers) (target_thread_alive, target_find_new_threads): Redeclare as function. * target.c (update_current_target): Do not inherit or de_fault to_resume, to_fetch_registers, to_store_registers, to_thread_alive, to_find_new_threads. (target_resume): Adjust. (target_thread_alive, target_find_new_threads): New. (debug_to_resume, debug_to_fetch_registers): Delete. (target_fetch_registers): New. (debug_to_store_registers): Delete. (target_store_registers): New. (debug_to_thread_alive, debug_to_find_new_threads): Delete. (setup_target_debug): Adjust. * gdbcore.h (core_ops): Delete declaration. * inf-ptrace.c, linux-nat.c, remote.c, amd64-linux-nat.c, inf-child.c, linux-thread-db.c, bsd-uthread.c, inf-ttrace.c, i386-sol2-tdep.c, darwin-nat.c, gnu-nat.c, go32-nat.c, hpux-thread.c, i386-linux-nat.c, i386fbsd-nat.c, monitor.c, nto-procfs.c, remote-m32r-sdi.c, remote-mips.c, windows-nat.c, alphabsd-nat.c, amd64bsd-nat.c, arm-linux-nat.c, armnbsd-nat.c, bsd-kvm.c, hppa-hpux-nat.c, hppa-linux-nat.c, hppabsd-nat.c, hppanbsd-nat.c, i386-darwin-nat.c, i386bsd-nat.c, ia64-linux-nat.c, m32r-linux-nat.c, m68kbsd-nat.c, m68klinux-nat.c, m88kbsd-nat.c, mips-linux-nat.c, mips64obsd-nat.c, mipsnbsd-nat.c, ppc-linux-nat.c, ppcnbsd-nat.c, ppcobsd-nat.c, remote-sim.c, rs6000-nat.c, s390-nat.c, shnbsd-nat.c, sparc-nat.c, sparc-nat.h, spu-linux-nat.c, vaxbsd-nat.c, xtensa-linux-nat.c: Adjust to target_ops changes. * gdbarch.sh (core_pid_to_str): New gdbarch callback. * gdbarch.h, gdbarch.c: Regenerate. * sol2-tdep.c: Include "inferior.h". (sol2_core_pid_to_str): New. * sol2-tdep.h (sol2_core_pid_to_str): Declare. * amd64-sol2-tdep.c (amd64_sol2_init_abi): Set it. * sparc-sol2-tdep.c (sparc32_sol2_init_abi): Set it. * sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Set it. * i386-sol2-tdep.c (i386_sol2_init_abi): Set it.
2009-02-23 01:03:50 +01:00
linux_nat_resume (struct target_ops *ops,
ptid_t ptid, int step, enum gdb_signal signo)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
struct lwp_info *lp;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
int resume_many;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLR: Preparing to %s %s, %s, inferior_ptid %s\n",
step ? "step" : "resume",
target_pid_to_str (ptid),
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
(signo != GDB_SIGNAL_0
? strsignal (gdb_signal_to_host (signo)) : "0"),
target_pid_to_str (inferior_ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* A specific PTID means `step only this process id'. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
resume_many = (ptid_equal (minus_one_ptid, ptid)
|| ptid_is_pid (ptid));
/* Mark the lwps we're resuming as resumed. */
iterate_over_lwps (ptid, resume_set_callback, NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
/* See if it's the current inferior that should be handled
specially. */
if (resume_many)
lp = find_lwp_pid (inferior_ptid);
else
lp = find_lwp_pid (ptid);
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
gdb_assert (lp != NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* Remember if we're stepping. */
lp->last_resume_kind = step ? resume_step : resume_continue;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* If we have a pending wait status for this thread, there is no
point in resuming the process. But first make sure that
linux_nat_wait won't preemptively handle the event - we
should never take this short-circuit if we are going to
leave LP running, since we have skipped resuming all the
other threads. This bit of code needs to be synchronized
with linux_nat_wait. */
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
if (lp->status && WIFSTOPPED (lp->status))
{
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
if (!lp->step
&& WSTOPSIG (lp->status)
&& sigismember (&pass_mask, WSTOPSIG (lp->status)))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLR: Not short circuiting for ignored "
"status 0x%x\n", lp->status);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* FIXME: What should we do if we are supposed to continue
this thread with a signal? */
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
gdb_assert (signo == GDB_SIGNAL_0);
signo = gdb_signal_from_host (WSTOPSIG (lp->status));
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
lp->status = 0;
}
}
if (lwp_status_pending_p (lp))
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
{
/* FIXME: What should we do if we are supposed to continue
this thread with a signal? */
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
gdb_assert (signo == GDB_SIGNAL_0);
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLR: Short circuiting for status 0x%x\n",
lp->status);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (target_can_async_p ())
{
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
target_async (1);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Tell the event loop we have something to process. */
async_file_mark ();
}
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
return;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (resume_many)
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
iterate_over_lwps (ptid, linux_nat_resume_callback, lp);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLR: %s %s, %s (resume event thread)\n",
step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT",
target_pid_to_str (lp->ptid),
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
(signo != GDB_SIGNAL_0
? strsignal (gdb_signal_to_host (signo)) : "0"));
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
linux_resume_one_lwp (lp, step, signo);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
if (target_can_async_p ())
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
target_async (1);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Send a signal to an LWP. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static int
kill_lwp (int lwpid, int signo)
{
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
int ret;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
errno = 0;
ret = syscall (__NR_tkill, lwpid, signo);
if (errno == ENOSYS)
{
/* If tkill fails, then we are not using nptl threads, a
configuration we no longer support. */
perror_with_name (("tkill"));
}
return ret;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Handle a GNU/Linux syscall trap wait response. If we see a syscall
event, check if the core is interested in it: if not, ignore the
event, and keep waiting; otherwise, we need to toggle the LWP's
syscall entry/exit status, since the ptrace event itself doesn't
indicate it, and report the trap to higher layers. */
static int
linux_handle_syscall_trap (struct lwp_info *lp, int stopping)
{
struct target_waitstatus *ourstatus = &lp->waitstatus;
struct gdbarch *gdbarch = target_thread_architecture (lp->ptid);
int syscall_number = (int) gdbarch_get_syscall_number (gdbarch, lp->ptid);
if (stopping)
{
/* If we're stopping threads, there's a SIGSTOP pending, which
makes it so that the LWP reports an immediate syscall return,
followed by the SIGSTOP. Skip seeing that "return" using
PTRACE_CONT directly, and let stop_wait_callback collect the
SIGSTOP. Later when the thread is resumed, a new syscall
entry event. If we didn't do this (and returned 0), we'd
leave a syscall entry pending, and our caller, by using
PTRACE_CONT to collect the SIGSTOP, skips the syscall return
itself. Later, when the user re-resumes this LWP, we'd see
another syscall entry event and we'd mistake it for a return.
If stop_wait_callback didn't force the SIGSTOP out of the LWP
(leaving immediately with LWP->signalled set, without issuing
a PTRACE_CONT), it would still be problematic to leave this
syscall enter pending, as later when the thread is resumed,
it would then see the same syscall exit mentioned above,
followed by the delayed SIGSTOP, while the syscall didn't
actually get to execute. It seems it would be even more
confusing to the user. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHST: ignoring syscall %d "
"for LWP %ld (stopping threads), "
"resuming with PTRACE_CONT for SIGSTOP\n",
syscall_number,
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
lp->syscall_state = TARGET_WAITKIND_IGNORE;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptrace (PTRACE_CONT, ptid_get_lwp (lp->ptid), 0, 0);
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
lp->stopped = 0;
return 1;
}
gdb: Improve syscall entry/return tracking on Linux The existing logic was simply to flip syscall entry/return state when a syscall trap was seen, and even then only with active 'catch syscall'. That can get out of sync if 'catch syscall' is toggled at odd times. This patch updates the entry/return state for all syscall traps, regardless of catching state, and also updates known syscall state for other kinds of traps. Almost all PTRACE_EVENT stops are delivered from the middle of a syscall, so this can act like an entry. Every other kind of ptrace stop is only delivered outside of syscall event pairs, so marking them ignored ensures the next syscall trap looks like an entry. Three new test scenarios are added to catch-syscall.exp: - Disable 'catch syscall' from an entry to deliberately miss the return event, then re-enable to make sure a new entry is recognized. - Enable 'catch syscall' for the first time from a vfork event, which is a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next syscall event is recognized as the return. - Make sure entry and return are recognized for an ENOSYS syscall. This is to defeat a common x86 hack that uses the pre-filled ENOSYS return value as a sign of being on the entry side. gdb/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * linux-nat.c (linux_handle_syscall_trap): Always update entry/ return state, even when not actively catching syscalls at all. (linux_handle_extended_wait): Mark syscall_state like an entry. (wait_lwp): Set syscall_state ignored for other traps. (linux_nat_filter_event): Likewise. gdb/testsuite/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * gdb.base/catch-syscall.c: Include <sched.h>. (unknown_syscall): New variable. (main): Trigger a vfork and an unknown syscall. * gdb.base/catch-syscall.exp (vfork_syscalls): New variable. (unknown_syscall_number): Likewise. (check_call_to_syscall): Accept an optional syscall pattern. (check_return_from_syscall): Likewise. (check_continue): Likewise. (test_catch_syscall_without_args): Check for vfork and ENOSYS. (test_catch_syscall_skipping_return): New test toggling off 'catch syscall' to step over the syscall return, then toggling back on. (test_catch_syscall_mid_vfork): New test turning on 'catch syscall' during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall. (do_syscall_tests): Call test_catch_syscall_without_args and test_catch_syscall_mid_vfork. (test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS. (fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
/* Always update the entry/return state, even if this particular
syscall isn't interesting to the core now. In async mode,
the user could install a new catchpoint for this syscall
between syscall enter/return, and we'll need to know to
report a syscall return if that happens. */
lp->syscall_state = (lp->syscall_state == TARGET_WAITKIND_SYSCALL_ENTRY
? TARGET_WAITKIND_SYSCALL_RETURN
: TARGET_WAITKIND_SYSCALL_ENTRY);
if (catch_syscall_enabled ())
{
if (catching_syscall_number (syscall_number))
{
/* Alright, an event to report. */
ourstatus->kind = lp->syscall_state;
ourstatus->value.syscall_number = syscall_number;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHST: stopping for %s of syscall %d"
" for LWP %ld\n",
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
lp->syscall_state
== TARGET_WAITKIND_SYSCALL_ENTRY
? "entry" : "return",
syscall_number,
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
return 0;
}
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHST: ignoring %s of syscall %d "
"for LWP %ld\n",
lp->syscall_state == TARGET_WAITKIND_SYSCALL_ENTRY
? "entry" : "return",
syscall_number,
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
}
else
{
/* If we had been syscall tracing, and hence used PT_SYSCALL
before on this LWP, it could happen that the user removes all
syscall catchpoints before we get to process this event.
There are two noteworthy issues here:
- When stopped at a syscall entry event, resuming with
PT_STEP still resumes executing the syscall and reports a
syscall return.
- Only PT_SYSCALL catches syscall enters. If we last
single-stepped this thread, then this event can't be a
syscall enter. If we last single-stepped this thread, this
has to be a syscall exit.
The points above mean that the next resume, be it PT_STEP or
PT_CONTINUE, can not trigger a syscall trace event. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
"LHST: caught syscall event "
"with no syscall catchpoints."
" %d for LWP %ld, ignoring\n",
syscall_number,
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
lp->syscall_state = TARGET_WAITKIND_IGNORE;
}
/* The core isn't interested in this event. For efficiency, avoid
stopping all threads only to have the core resume them all again.
Since we're not stopping threads, if we're still syscall tracing
and not stepping, we can't use PTRACE_CONT here, as we'd miss any
subsequent syscall. Simply resume using the inf-ptrace layer,
which knows when to use PT_SYSCALL or PT_CONTINUE. */
linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
return 1;
}
/* Handle a GNU/Linux extended wait response. If we see a clone
event, we need to add the new LWP to our list (and not report the
trap to higher layers). This function returns non-zero if the
event should be ignored and we should wait again. If STOPPING is
true, the new LWP remains stopped, otherwise it is continued. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static int
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
linux_handle_extended_wait (struct lwp_info *lp, int status)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
int pid = ptid_get_lwp (lp->ptid);
struct target_waitstatus *ourstatus = &lp->waitstatus;
int event = linux_ptrace_get_extended_event (status);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb: Improve syscall entry/return tracking on Linux The existing logic was simply to flip syscall entry/return state when a syscall trap was seen, and even then only with active 'catch syscall'. That can get out of sync if 'catch syscall' is toggled at odd times. This patch updates the entry/return state for all syscall traps, regardless of catching state, and also updates known syscall state for other kinds of traps. Almost all PTRACE_EVENT stops are delivered from the middle of a syscall, so this can act like an entry. Every other kind of ptrace stop is only delivered outside of syscall event pairs, so marking them ignored ensures the next syscall trap looks like an entry. Three new test scenarios are added to catch-syscall.exp: - Disable 'catch syscall' from an entry to deliberately miss the return event, then re-enable to make sure a new entry is recognized. - Enable 'catch syscall' for the first time from a vfork event, which is a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next syscall event is recognized as the return. - Make sure entry and return are recognized for an ENOSYS syscall. This is to defeat a common x86 hack that uses the pre-filled ENOSYS return value as a sign of being on the entry side. gdb/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * linux-nat.c (linux_handle_syscall_trap): Always update entry/ return state, even when not actively catching syscalls at all. (linux_handle_extended_wait): Mark syscall_state like an entry. (wait_lwp): Set syscall_state ignored for other traps. (linux_nat_filter_event): Likewise. gdb/testsuite/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * gdb.base/catch-syscall.c: Include <sched.h>. (unknown_syscall): New variable. (main): Trigger a vfork and an unknown syscall. * gdb.base/catch-syscall.exp (vfork_syscalls): New variable. (unknown_syscall_number): Likewise. (check_call_to_syscall): Accept an optional syscall pattern. (check_return_from_syscall): Likewise. (check_continue): Likewise. (test_catch_syscall_without_args): Check for vfork and ENOSYS. (test_catch_syscall_skipping_return): New test toggling off 'catch syscall' to step over the syscall return, then toggling back on. (test_catch_syscall_mid_vfork): New test turning on 'catch syscall' during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall. (do_syscall_tests): Call test_catch_syscall_without_args and test_catch_syscall_mid_vfork. (test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS. (fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
/* All extended events we currently use are mid-syscall. Only
PTRACE_EVENT_STOP is delivered more like a signal-stop, but
you have to be using PTRACE_SEIZE to get that. */
lp->syscall_state = TARGET_WAITKIND_SYSCALL_ENTRY;
if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK
|| event == PTRACE_EVENT_CLONE)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
unsigned long new_pid;
int ret;
ptrace (PTRACE_GETEVENTMSG, pid, 0, &new_pid);
/* If we haven't already seen the new PID stop, wait for it now. */
if (! pull_pid_from_list (&stopped_pids, new_pid, &status))
{
/* The new child has a pending SIGSTOP. We can't affect it until it
hits the SIGSTOP, but we're already attached. */
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
ret = my_waitpid (new_pid, &status, __WALL);
if (ret == -1)
perror_with_name (_("waiting for new child"));
else if (ret != new_pid)
internal_error (__FILE__, __LINE__,
_("wait returned unexpected PID %d"), ret);
else if (!WIFSTOPPED (status))
internal_error (__FILE__, __LINE__,
_("wait returned unexpected status 0x%x"), status);
}
ourstatus->value.related_pid = ptid_build (new_pid, new_pid, 0);
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
if (event == PTRACE_EVENT_FORK || event == PTRACE_EVENT_VFORK)
{
/* The arch-specific native code may need to know about new
forks even if those end up never mapped to an
inferior. */
if (linux_nat_new_fork != NULL)
linux_nat_new_fork (lp, new_pid);
}
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
if (event == PTRACE_EVENT_FORK
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
&& linux_fork_checkpointing_p (ptid_get_pid (lp->ptid)))
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
{
/* Handle checkpointing by linux-fork.c here as a special
case. We don't want the follow-fork-mode or 'catch fork'
to interfere with this. */
/* This won't actually modify the breakpoint list, but will
physically remove the breakpoints from the child. */
Change detach_breakpoints to take a ptid instead of a pid Before this change, detach_breakpoints would take a pid, and then set inferior_ptid to a ptid that it constructs using pid_to_ptid (pid). Unfortunately, this ptid is not necessarily valid. Consider for instance the case of ia64-hpux, where ttrace refuses a register-read operation if the LWP is not provided. This problems shows up when GDB is trying to handle fork events. Assuming GDB is configured to follow the parent, GDB will try to detach from the child. But before doing so, it needs to remove all breakpoints inside that child. On ia64, this involves reading inferior (the child's) memory. And on ia64-hpux, reading memory requires us to read the bsp and bspstore registers, in order to determine where that memory is relative to the value of those registers, and thus to determine which ttrace operation to use in order to fetch that memory (see ia64_hpux_xfer_memory). This patch therefore changes detach_breakpoints to take a ptid instead of a pid, and then updates all callers. One of the consequences of this patch is that it trips an assert on GNU/Linux targets. But this assert appears to have not actual purpose, and is thus removed. gdb/ChangeLog: * breakpoint.h (detach_breakpoints): pid parameter is now a ptid. * breakpoint.c (detach_breakpoints): Change pid parameter into a ptid. Adjust code accordingly. * infrun.c (handle_inferior_event): Delete variable child_pid. Update call to detach_breakpoints to pass the child ptid for fork events. * linux-nat.c (linux_nat_iterate_watchpoint_lwps): Remove assert that inferior_ptid's lwp is zero. (linux_handle_extended_wait): Update call to detach_breakpoints. * inf-ttrace.c (inf_ttrace_follow_fork): Update call to detach_breakpoints.
2012-08-17 01:54:50 +02:00
detach_breakpoints (ptid_build (new_pid, new_pid, 0));
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
/* Retain child fork in ptrace (stopped) state. */
if (!find_fork_pid (new_pid))
add_fork (new_pid);
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
/* Report as spurious, so that infrun doesn't want to follow
this fork. We're actually doing an infcall in
linux-fork.c. */
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
/* Report the stop to the core. */
return 0;
}
if (event == PTRACE_EVENT_FORK)
ourstatus->kind = TARGET_WAITKIND_FORKED;
else if (event == PTRACE_EVENT_VFORK)
ourstatus->kind = TARGET_WAITKIND_VFORKED;
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
else if (event == PTRACE_EVENT_CLONE)
{
struct lwp_info *new_lp;
ourstatus->kind = TARGET_WAITKIND_IGNORE;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHEW: Got clone event "
"from LWP %d, new child is LWP %ld\n",
pid, new_pid);
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
new_lp = add_lwp (ptid_build (ptid_get_pid (lp->ptid), new_pid, 0));
new_lp->stopped = 1;
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
new_lp->resumed = 1;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
GNU/Linux: Stop using libthread_db/td_ta_thr_iter TL;DR - GDB can hang if something refreshes the thread list out of the target while the target is running. GDB hangs inside td_ta_thr_iter. The fix is to not use that libthread_db function anymore. Long version: Running the testsuite against my all-stop-on-top-of-non-stop series is still exposing latent non-stop bugs. I was originally seeing this with the multi-create.exp test, back when we were still using libthread_db thread event breakpoints. The all-stop-on-top-of-non-stop series forces a thread list refresh each time GDB needs to start stepping over a breakpoint (to pause all threads). That test hits the thread event breakpoint often, resulting in a bunch of step-over operations, thus a bunch of thread list refreshes while some threads in the target are running. The commit adds a real non-stop mode test that triggers the issue, based on multi-create.exp, that does an explicit "info threads" when a breakpoint is hit. IOW, it does the same things the as-ns series was doing when testing multi-create.exp. The bug is a race, so it unfortunately takes several runs for the test to trigger it. In fact, even when setting the test running in a loop, it sometimes takes several minutes for it to trigger for me. The race is related to libthread_db's td_ta_thr_iter. This is libthread_db's entry point for walking the thread list of the inferior. Sometimes, when GDB refreshes the thread list from the target, libthread_db's td_ta_thr_iter can somehow see glibc's thread list as a cycle, and get stuck in an infinite loop. The issue is that when a thread exits, its thread control structure in glibc is moved from a "used" list to a "cache" list. These lists are simply circular linked lists where the "next/prev" pointers are embedded in the thread control structure itself. The "next" pointer of the last element of the list points back to the list's sentinel "head". There's only one set of "next/prev" pointers for both lists; thus a thread can only be in one of the lists at a time, not in both simultaneously. So when thread C exits, simplifying, the following happens. A-C are threads. stack_used and stack_cache are the list's heads. Before: stack_used -> A -> B -> C -> (&stack_used) stack_cache -> (&stack_cache) After: stack_used -> A -> B -> (&stack_used) stack_cache -> C -> (&stack_cache) td_ta_thr_iter starts by iterating at the list's head's next, and iterates until it sees a thread whose next pointer points to the list's head again. Thus in the before case above, C's next points to stack_used, indicating end of list. In the same case, the stack_cache list is empty. For each thread being iterated, td_ta_thr_iter reads the whole thread object out of the inferior. This includes the thread's "next" pointer. In the scenario above, it may happen that td_ta_thr_iter is iterating thread B and has already read B's thread structure just before thread C exits and its control structure moves to the cached list. Now, recall that td_ta_thr_iter is running in the context of GDB, and there's no locking between GDB and the inferior. From it's local copy of B, td_ta_thr_iter believes that the next thread after B is thread C, so it happilly continues iterating to C, a thread that has already exited, and is now in the stack cache list. After iterating C, td_ta_thr_iter finds the stack_cache head, which because it is not stack_used, td_ta_thr_iter assumes it's just another thread. After this, unless the reverse race triggers, GDB gets stuck in td_ta_thr_iter forever walking the stack_cache list, as no thread in thatlist has a next pointer that points back to stack_used (the terminating condition). Before fully understanding the issue, I tried adding cycle detection to GDB's td_ta_thr_iter callback. However, td_ta_thr_iter skips calling the callback in some cases, which means that it's possible that the callback isn't called at all, making it impossible for GDB to break the loop. I did manage to get GDB stuck in that state more than once. Fortunately, we can avoid the issue altogether. We don't really need td_ta_thr_iter for live debugging nowadays, given PTRACE_EVENT_CLONE. We already know how to map and lwp id to a thread id without iterating (thread_from_lwp), so use that more. gdb/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_handle_extended_wait): Call thread_db_notice_clone whenever a new clone LWP is detected. (linux_stop_and_wait_all_lwps, linux_unstop_all_lwps): New functions. * linux-nat.h (thread_db_attach_lwp): Delete declaration. (thread_db_notice_clone, linux_stop_and_wait_all_lwps) (linux_unstop_all_lwps): Declare. * linux-thread-db.c (struct thread_get_info_inout): Delete. (thread_get_info_callback): Delete. (thread_from_lwp): Use td_thr_get_info and record_thread. (thread_db_attach_lwp): Delete. (thread_db_notice_clone): New function. (try_thread_db_load_1): If /proc is mounted and shows the process'es task list, walk over all LWPs and call thread_from_lwp instead of relying on td_ta_thr_iter. (attach_thread): Don't call check_thread_signals here. Split the tail part of the function (which adds the thread to the core GDB thread list) to ... (record_thread): ... this function. Call check_thread_signals here. (thread_db_wait): Don't call thread_db_find_new_threads_1. Always call thread_from_lwp. (thread_db_update_thread_list): Rename to ... (thread_db_update_thread_list_org): ... this. (thread_db_update_thread_list): New function. (thread_db_find_thread_from_tid): Delete. (thread_db_get_ada_task_ptid): Simplify. * nat/linux-procfs.c: Include <sys/stat.h>. (linux_proc_task_list_dir_exists): New function. * nat/linux-procfs.h (linux_proc_task_list_dir_exists): Declare. gdb/gdbserver/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * thread-db.c: Include "nat/linux-procfs.h". (thread_db_init): Skip listing new threads if the kernel supports PTRACE_EVENT_CLONE and /proc/PID/task/ is accessible. gdb/testsuite/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * gdb.threads/multi-create-ns-info-thr.exp: New file.
2015-02-20 21:21:59 +01:00
/* If the thread_db layer is active, let it record the user
level thread id and status, and add the thread to GDB's
list. */
if (!thread_db_notice_clone (lp->ptid, new_lp->ptid))
{
GNU/Linux: Stop using libthread_db/td_ta_thr_iter TL;DR - GDB can hang if something refreshes the thread list out of the target while the target is running. GDB hangs inside td_ta_thr_iter. The fix is to not use that libthread_db function anymore. Long version: Running the testsuite against my all-stop-on-top-of-non-stop series is still exposing latent non-stop bugs. I was originally seeing this with the multi-create.exp test, back when we were still using libthread_db thread event breakpoints. The all-stop-on-top-of-non-stop series forces a thread list refresh each time GDB needs to start stepping over a breakpoint (to pause all threads). That test hits the thread event breakpoint often, resulting in a bunch of step-over operations, thus a bunch of thread list refreshes while some threads in the target are running. The commit adds a real non-stop mode test that triggers the issue, based on multi-create.exp, that does an explicit "info threads" when a breakpoint is hit. IOW, it does the same things the as-ns series was doing when testing multi-create.exp. The bug is a race, so it unfortunately takes several runs for the test to trigger it. In fact, even when setting the test running in a loop, it sometimes takes several minutes for it to trigger for me. The race is related to libthread_db's td_ta_thr_iter. This is libthread_db's entry point for walking the thread list of the inferior. Sometimes, when GDB refreshes the thread list from the target, libthread_db's td_ta_thr_iter can somehow see glibc's thread list as a cycle, and get stuck in an infinite loop. The issue is that when a thread exits, its thread control structure in glibc is moved from a "used" list to a "cache" list. These lists are simply circular linked lists where the "next/prev" pointers are embedded in the thread control structure itself. The "next" pointer of the last element of the list points back to the list's sentinel "head". There's only one set of "next/prev" pointers for both lists; thus a thread can only be in one of the lists at a time, not in both simultaneously. So when thread C exits, simplifying, the following happens. A-C are threads. stack_used and stack_cache are the list's heads. Before: stack_used -> A -> B -> C -> (&stack_used) stack_cache -> (&stack_cache) After: stack_used -> A -> B -> (&stack_used) stack_cache -> C -> (&stack_cache) td_ta_thr_iter starts by iterating at the list's head's next, and iterates until it sees a thread whose next pointer points to the list's head again. Thus in the before case above, C's next points to stack_used, indicating end of list. In the same case, the stack_cache list is empty. For each thread being iterated, td_ta_thr_iter reads the whole thread object out of the inferior. This includes the thread's "next" pointer. In the scenario above, it may happen that td_ta_thr_iter is iterating thread B and has already read B's thread structure just before thread C exits and its control structure moves to the cached list. Now, recall that td_ta_thr_iter is running in the context of GDB, and there's no locking between GDB and the inferior. From it's local copy of B, td_ta_thr_iter believes that the next thread after B is thread C, so it happilly continues iterating to C, a thread that has already exited, and is now in the stack cache list. After iterating C, td_ta_thr_iter finds the stack_cache head, which because it is not stack_used, td_ta_thr_iter assumes it's just another thread. After this, unless the reverse race triggers, GDB gets stuck in td_ta_thr_iter forever walking the stack_cache list, as no thread in thatlist has a next pointer that points back to stack_used (the terminating condition). Before fully understanding the issue, I tried adding cycle detection to GDB's td_ta_thr_iter callback. However, td_ta_thr_iter skips calling the callback in some cases, which means that it's possible that the callback isn't called at all, making it impossible for GDB to break the loop. I did manage to get GDB stuck in that state more than once. Fortunately, we can avoid the issue altogether. We don't really need td_ta_thr_iter for live debugging nowadays, given PTRACE_EVENT_CLONE. We already know how to map and lwp id to a thread id without iterating (thread_from_lwp), so use that more. gdb/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_handle_extended_wait): Call thread_db_notice_clone whenever a new clone LWP is detected. (linux_stop_and_wait_all_lwps, linux_unstop_all_lwps): New functions. * linux-nat.h (thread_db_attach_lwp): Delete declaration. (thread_db_notice_clone, linux_stop_and_wait_all_lwps) (linux_unstop_all_lwps): Declare. * linux-thread-db.c (struct thread_get_info_inout): Delete. (thread_get_info_callback): Delete. (thread_from_lwp): Use td_thr_get_info and record_thread. (thread_db_attach_lwp): Delete. (thread_db_notice_clone): New function. (try_thread_db_load_1): If /proc is mounted and shows the process'es task list, walk over all LWPs and call thread_from_lwp instead of relying on td_ta_thr_iter. (attach_thread): Don't call check_thread_signals here. Split the tail part of the function (which adds the thread to the core GDB thread list) to ... (record_thread): ... this function. Call check_thread_signals here. (thread_db_wait): Don't call thread_db_find_new_threads_1. Always call thread_from_lwp. (thread_db_update_thread_list): Rename to ... (thread_db_update_thread_list_org): ... this. (thread_db_update_thread_list): New function. (thread_db_find_thread_from_tid): Delete. (thread_db_get_ada_task_ptid): Simplify. * nat/linux-procfs.c: Include <sys/stat.h>. (linux_proc_task_list_dir_exists): New function. * nat/linux-procfs.h (linux_proc_task_list_dir_exists): Declare. gdb/gdbserver/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * thread-db.c: Include "nat/linux-procfs.h". (thread_db_init): Skip listing new threads if the kernel supports PTRACE_EVENT_CLONE and /proc/PID/task/ is accessible. gdb/testsuite/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * gdb.threads/multi-create-ns-info-thr.exp: New file.
2015-02-20 21:21:59 +01:00
/* The process is not using thread_db. Add the LWP to
GDB's list. */
target_post_attach (ptid_get_lwp (new_lp->ptid));
add_thread (new_lp->ptid);
}
/* Even if we're stopping the thread for some reason
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
internal to this module, from the perspective of infrun
and the user/frontend, this new thread is running until
it next reports a stop. */
set_running (new_lp->ptid, 1);
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
set_executing (new_lp->ptid, 1);
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
if (WSTOPSIG (status) != SIGSTOP)
{
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
/* This can happen if someone starts sending signals to
the new thread before it gets a chance to run, which
have a lower number than SIGSTOP (e.g. SIGUSR1).
This is an unlikely case, and harder to handle for
fork / vfork than for clone, so we do not try - but
we handle it for clone events here. */
new_lp->signalled = 1;
/* We created NEW_LP so it cannot yet contain STATUS. */
gdb_assert (new_lp->status == 0);
/* Save the wait status to report later. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHEW: waitpid of new LWP %ld, "
"saving status %s\n",
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
(long) ptid_get_lwp (new_lp->ptid),
status_to_str (status));
new_lp->status = status;
}
else if (report_thread_events)
{
new_lp->waitstatus.kind = TARGET_WAITKIND_THREAD_CREATED;
new_lp->status = status;
}
return 1;
}
return 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
if (event == PTRACE_EVENT_EXEC)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHEW: Got exec event from LWP %ld\n",
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
ourstatus->kind = TARGET_WAITKIND_EXECD;
ourstatus->value.execd_pathname
= xstrdup (linux_child_pid_to_exec_file (NULL, pid));
/* The thread that execed must have been resumed, but, when a
thread execs, it changes its tid to the tgid, and the old
tgid thread might have not been resumed. */
lp->resumed = 1;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
return 0;
}
if (event == PTRACE_EVENT_VFORK_DONE)
{
if (current_inferior ()->waiting_for_vfork_done)
{
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
if (debug_linux_nat)
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
fprintf_unfiltered (gdb_stdlog,
"LHEW: Got expected PTRACE_EVENT_"
"VFORK_DONE from LWP %ld: stopping\n",
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
ourstatus->kind = TARGET_WAITKIND_VFORK_DONE;
return 0;
}
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
if (debug_linux_nat)
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
fprintf_unfiltered (gdb_stdlog,
"LHEW: Got PTRACE_EVENT_VFORK_DONE "
Linux: don't resume new LWPs until we've pulled all events out of the kernel Since the starvation avoidance series (https://sourceware.org/ml/gdb-patches/2014-12/msg00631.html), both GDB and GDBserver pull all events out of ptrace before deciding which event to process. There's one problem with that though. Because we resume new threads immediately when we see a PTRACE_EVENT_CLONE event, if the program constantly spawns threads fast enough, new threads can spawn threads faster we can pull events out of the kernel, and thus we'd get stuck in an infinite loop, never returning any event to the core to process. I occasionally see this happen with the attach-many-short-lived-threads.exp test against gdbserver. The fix is to delay resuming new threads until we've pulled out all events out of the kernel. On native, we already have the resume_stopped_resumed_lwps function that knows to resume LWPs that are stopped with no event to report to the core. So the patch just adds another use. GDBserver didn't have the equivalent yet, so the patch adds one. Tested on x86_64 Fedora 20, native and gdbserver (remote and extended-remote). gdb/gdbserver/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-low.c (handle_extended_wait): Don't resume LWPs here. (resume_stopped_resumed_lwps): New function. (linux_wait_for_event_filtered): Use it. gdb/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-nat.c (handle_extended_wait): Don't resume LWPs here. (wait_lwp): Don't call wait_lwp if linux_handle_extended_wait returns true. (resume_stopped_resumed_lwps): Don't check whether the thread is marked as executing. (linux_nat_wait_1): Use resume_stopped_resumed_lwps.
2015-02-04 19:13:28 +01:00
"from LWP %ld: ignoring\n",
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_get_lwp (lp->ptid));
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
return 1;
}
internal_error (__FILE__, __LINE__,
_("unknown ptrace event %d"), event);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Wait for LP to stop. Returns the wait status, or 0 if the LWP has
exited. */
static int
wait_lwp (struct lwp_info *lp)
{
pid_t pid;
int status = 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
int thread_dead = 0;
sigset_t prev_mask;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb_assert (!lp->stopped);
gdb_assert (lp->status == 0);
/* Make sure SIGCHLD is blocked for sigsuspend avoiding a race below. */
block_child_signals (&prev_mask);
for (;;)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
pid = my_waitpid (ptid_get_lwp (lp->ptid), &status, __WALL | WNOHANG);
if (pid == -1 && errno == ECHILD)
{
/* The thread has previously exited. We need to delete it
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
now because if this was a non-leader thread execing, we
won't get an exit event. See comments on exec events at
the top of the file. */
thread_dead = 1;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "WL: %s vanished.\n",
target_pid_to_str (lp->ptid));
}
if (pid != 0)
break;
/* Bugs 10970, 12702.
Thread group leader may have exited in which case we'll lock up in
waitpid if there are other threads, even if they are all zombies too.
Basically, we're not supposed to use waitpid this way.
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
tkill(pid,0) cannot be used here as it gets ESRCH for both
for zombie and running processes.
As a workaround, check if we're waiting for the thread group leader and
if it's a zombie, and avoid calling waitpid if it is.
This is racy, what if the tgl becomes a zombie right after we check?
Therefore always use WNOHANG with sigsuspend - it is equivalent to
waiting waitpid but linux_proc_pid_is_zombie is safe this way. */
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (ptid_get_pid (lp->ptid) == ptid_get_lwp (lp->ptid)
&& linux_proc_pid_is_zombie (ptid_get_lwp (lp->ptid)))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
thread_dead = 1;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"WL: Thread group leader %s vanished.\n",
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
target_pid_to_str (lp->ptid));
break;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Wait for next SIGCHLD and try again. This may let SIGCHLD handlers
get invoked despite our caller had them intentionally blocked by
block_child_signals. This is sensitive only to the loop of
linux_nat_wait_1 and there if we get called my_waitpid gets called
again before it gets to sigsuspend so we can safely let the handlers
get executed here. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "WL: about to sigsuspend\n");
sigsuspend (&suspend_mask);
}
restore_child_signals_mask (&prev_mask);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (!thread_dead)
{
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
gdb_assert (pid == ptid_get_lwp (lp->ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"WL: waitpid %s received %s\n",
target_pid_to_str (lp->ptid),
status_to_str (status));
}
/* Check if the thread has exited. */
if (WIFEXITED (status) || WIFSIGNALED (status))
{
if (report_thread_events
|| ptid_get_pid (lp->ptid) == ptid_get_lwp (lp->ptid))
PR threads/18600: Inferiors left around after fork+thread spawn The new gdb.threads/fork-plus-threads.exp test exposes one more problem. When one types "info inferiors" after running the program, one see's a couple inferior left still, while there should only be inferior #1 left. E.g.: (gdb) info inferiors Num Description Executable 4 process 8393 /home/pedro/bugs/src/test 2 process 8388 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) info threads Calling prune_inferiors() manually at this point (from a top gdb) does not remove them, because they still have inf->pid != 0 (while they shouldn't). This suggests that we never mourned those inferiors. Enabling logs (master + previous patch) we see: ... WL: waitpid Thread 0x7ffff7fc2740 (LWP 9513) received Trace/breakpoint trap (stopped) WL: Handling extended status 0x03057f LHEW: Got clone event from LWP 9513, new child is LWP 9579 [New Thread 0x7ffff37b8700 (LWP 9579)] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9508) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9508) exited. ^^^^^^^^ [Thread 0x7ffff7fc2740 (LWP 9508) exited] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9499) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9499) exited. [Thread 0x7ffff7fc2740 (LWP 9499) exited] RSRL: resuming stopped-resumed LWP Thread 0x7ffff37b8700 (LWP 9579) at 0x3615ef4ce1: step=0 ... (gdb) info inferiors Num Description Executable 5 process 9508 /home/pedro/bugs/src/test ^^^^ 4 process 9503 /home/pedro/bugs/src/test 3 process 9500 /home/pedro/bugs/src/test 2 process 9499 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) ... Note the "Thread 0x7ffff7fc2740 (LWP 9508) exited." line. That's this in wait_lwp: /* Check if the thread has exited. */ if (WIFEXITED (status) || WIFSIGNALED (status)) { thread_dead = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n", target_pid_to_str (lp->ptid)); } } That was the leader thread reporting an exit, meaning the whole process is gone. So the problem is that this code doesn't understand that an WIFEXITED status of the leader LWP should be reported to infrun as process exit. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * linux-nat.c (wait_lwp): Report to the core when thread group leader exits. gdb/testsuite/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.exp: Test that "info inferiors" only shows inferior 1.
2015-07-22 19:01:46 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "WL: LWP %d exited.\n",
PR threads/18600: Inferiors left around after fork+thread spawn The new gdb.threads/fork-plus-threads.exp test exposes one more problem. When one types "info inferiors" after running the program, one see's a couple inferior left still, while there should only be inferior #1 left. E.g.: (gdb) info inferiors Num Description Executable 4 process 8393 /home/pedro/bugs/src/test 2 process 8388 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) info threads Calling prune_inferiors() manually at this point (from a top gdb) does not remove them, because they still have inf->pid != 0 (while they shouldn't). This suggests that we never mourned those inferiors. Enabling logs (master + previous patch) we see: ... WL: waitpid Thread 0x7ffff7fc2740 (LWP 9513) received Trace/breakpoint trap (stopped) WL: Handling extended status 0x03057f LHEW: Got clone event from LWP 9513, new child is LWP 9579 [New Thread 0x7ffff37b8700 (LWP 9579)] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9508) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9508) exited. ^^^^^^^^ [Thread 0x7ffff7fc2740 (LWP 9508) exited] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9499) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9499) exited. [Thread 0x7ffff7fc2740 (LWP 9499) exited] RSRL: resuming stopped-resumed LWP Thread 0x7ffff37b8700 (LWP 9579) at 0x3615ef4ce1: step=0 ... (gdb) info inferiors Num Description Executable 5 process 9508 /home/pedro/bugs/src/test ^^^^ 4 process 9503 /home/pedro/bugs/src/test 3 process 9500 /home/pedro/bugs/src/test 2 process 9499 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) ... Note the "Thread 0x7ffff7fc2740 (LWP 9508) exited." line. That's this in wait_lwp: /* Check if the thread has exited. */ if (WIFEXITED (status) || WIFSIGNALED (status)) { thread_dead = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n", target_pid_to_str (lp->ptid)); } } That was the leader thread reporting an exit, meaning the whole process is gone. So the problem is that this code doesn't understand that an WIFEXITED status of the leader LWP should be reported to infrun as process exit. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * linux-nat.c (wait_lwp): Report to the core when thread group leader exits. gdb/testsuite/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.exp: Test that "info inferiors" only shows inferior 1.
2015-07-22 19:01:46 +02:00
ptid_get_pid (lp->ptid));
/* If this is the leader exiting, it means the whole
PR threads/18600: Inferiors left around after fork+thread spawn The new gdb.threads/fork-plus-threads.exp test exposes one more problem. When one types "info inferiors" after running the program, one see's a couple inferior left still, while there should only be inferior #1 left. E.g.: (gdb) info inferiors Num Description Executable 4 process 8393 /home/pedro/bugs/src/test 2 process 8388 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) info threads Calling prune_inferiors() manually at this point (from a top gdb) does not remove them, because they still have inf->pid != 0 (while they shouldn't). This suggests that we never mourned those inferiors. Enabling logs (master + previous patch) we see: ... WL: waitpid Thread 0x7ffff7fc2740 (LWP 9513) received Trace/breakpoint trap (stopped) WL: Handling extended status 0x03057f LHEW: Got clone event from LWP 9513, new child is LWP 9579 [New Thread 0x7ffff37b8700 (LWP 9579)] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9508) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9508) exited. ^^^^^^^^ [Thread 0x7ffff7fc2740 (LWP 9508) exited] WL: waitpid Thread 0x7ffff7fc2740 (LWP 9499) received 0 (exited) WL: Thread 0x7ffff7fc2740 (LWP 9499) exited. [Thread 0x7ffff7fc2740 (LWP 9499) exited] RSRL: resuming stopped-resumed LWP Thread 0x7ffff37b8700 (LWP 9579) at 0x3615ef4ce1: step=0 ... (gdb) info inferiors Num Description Executable 5 process 9508 /home/pedro/bugs/src/test ^^^^ 4 process 9503 /home/pedro/bugs/src/test 3 process 9500 /home/pedro/bugs/src/test 2 process 9499 /home/pedro/bugs/src/test * 1 <null> /home/pedro/bugs/src/test (gdb) ... Note the "Thread 0x7ffff7fc2740 (LWP 9508) exited." line. That's this in wait_lwp: /* Check if the thread has exited. */ if (WIFEXITED (status) || WIFSIGNALED (status)) { thread_dead = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n", target_pid_to_str (lp->ptid)); } } That was the leader thread reporting an exit, meaning the whole process is gone. So the problem is that this code doesn't understand that an WIFEXITED status of the leader LWP should be reported to infrun as process exit. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * linux-nat.c (wait_lwp): Report to the core when thread group leader exits. gdb/testsuite/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.exp: Test that "info inferiors" only shows inferior 1.
2015-07-22 19:01:46 +02:00
process is gone. Store the status to report to the
core. Store it in lp->waitstatus, because lp->status
would be ambiguous (W_EXITCODE(0,0) == 0). */
store_waitstatus (&lp->waitstatus, status);
return 0;
}
thread_dead = 1;
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n",
target_pid_to_str (lp->ptid));
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
if (thread_dead)
{
exit_lwp (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
gdb_assert (WIFSTOPPED (status));
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
lp->stopped = 1;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
if (lp->must_set_ptrace_flags)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid));
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
int options = linux_nat_ptrace_options (inf->attach_flag);
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
linux_enable_event_reporting (ptid_get_lwp (lp->ptid), options);
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
lp->must_set_ptrace_flags = 0;
}
/* Handle GNU/Linux's syscall SIGTRAPs. */
if (WIFSTOPPED (status) && WSTOPSIG (status) == SYSCALL_SIGTRAP)
{
/* No longer need the sysgood bit. The ptrace event ends up
recorded in lp->waitstatus if we care for it. We can carry
on handling the event like a regular SIGTRAP from here
on. */
status = W_STOPCODE (SIGTRAP);
if (linux_handle_syscall_trap (lp, 1))
return wait_lwp (lp);
}
gdb: Improve syscall entry/return tracking on Linux The existing logic was simply to flip syscall entry/return state when a syscall trap was seen, and even then only with active 'catch syscall'. That can get out of sync if 'catch syscall' is toggled at odd times. This patch updates the entry/return state for all syscall traps, regardless of catching state, and also updates known syscall state for other kinds of traps. Almost all PTRACE_EVENT stops are delivered from the middle of a syscall, so this can act like an entry. Every other kind of ptrace stop is only delivered outside of syscall event pairs, so marking them ignored ensures the next syscall trap looks like an entry. Three new test scenarios are added to catch-syscall.exp: - Disable 'catch syscall' from an entry to deliberately miss the return event, then re-enable to make sure a new entry is recognized. - Enable 'catch syscall' for the first time from a vfork event, which is a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next syscall event is recognized as the return. - Make sure entry and return are recognized for an ENOSYS syscall. This is to defeat a common x86 hack that uses the pre-filled ENOSYS return value as a sign of being on the entry side. gdb/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * linux-nat.c (linux_handle_syscall_trap): Always update entry/ return state, even when not actively catching syscalls at all. (linux_handle_extended_wait): Mark syscall_state like an entry. (wait_lwp): Set syscall_state ignored for other traps. (linux_nat_filter_event): Likewise. gdb/testsuite/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * gdb.base/catch-syscall.c: Include <sched.h>. (unknown_syscall): New variable. (main): Trigger a vfork and an unknown syscall. * gdb.base/catch-syscall.exp (vfork_syscalls): New variable. (unknown_syscall_number): Likewise. (check_call_to_syscall): Accept an optional syscall pattern. (check_return_from_syscall): Likewise. (check_continue): Likewise. (test_catch_syscall_without_args): Check for vfork and ENOSYS. (test_catch_syscall_skipping_return): New test toggling off 'catch syscall' to step over the syscall return, then toggling back on. (test_catch_syscall_mid_vfork): New test turning on 'catch syscall' during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall. (do_syscall_tests): Call test_catch_syscall_without_args and test_catch_syscall_mid_vfork. (test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS. (fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
else
{
/* Almost all other ptrace-stops are known to be outside of system
calls, with further exceptions in linux_handle_extended_wait. */
lp->syscall_state = TARGET_WAITKIND_IGNORE;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Handle GNU/Linux's extended waitstatus for trace events. */
if (WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP
&& linux_is_extended_waitstatus (status))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"WL: Handling extended status 0x%06x\n",
status);
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
linux_handle_extended_wait (lp, status);
Linux: don't resume new LWPs until we've pulled all events out of the kernel Since the starvation avoidance series (https://sourceware.org/ml/gdb-patches/2014-12/msg00631.html), both GDB and GDBserver pull all events out of ptrace before deciding which event to process. There's one problem with that though. Because we resume new threads immediately when we see a PTRACE_EVENT_CLONE event, if the program constantly spawns threads fast enough, new threads can spawn threads faster we can pull events out of the kernel, and thus we'd get stuck in an infinite loop, never returning any event to the core to process. I occasionally see this happen with the attach-many-short-lived-threads.exp test against gdbserver. The fix is to delay resuming new threads until we've pulled out all events out of the kernel. On native, we already have the resume_stopped_resumed_lwps function that knows to resume LWPs that are stopped with no event to report to the core. So the patch just adds another use. GDBserver didn't have the equivalent yet, so the patch adds one. Tested on x86_64 Fedora 20, native and gdbserver (remote and extended-remote). gdb/gdbserver/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-low.c (handle_extended_wait): Don't resume LWPs here. (resume_stopped_resumed_lwps): New function. (linux_wait_for_event_filtered): Use it. gdb/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-nat.c (handle_extended_wait): Don't resume LWPs here. (wait_lwp): Don't call wait_lwp if linux_handle_extended_wait returns true. (resume_stopped_resumed_lwps): Don't check whether the thread is marked as executing. (linux_nat_wait_1): Use resume_stopped_resumed_lwps.
2015-02-04 19:13:28 +01:00
return 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
return status;
}
/* Send a SIGSTOP to LP. */
static int
stop_callback (struct lwp_info *lp, void *data)
{
if (!lp->stopped && !lp->signalled)
{
int ret;
if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"SC: kill %s **<SIGSTOP>**\n",
target_pid_to_str (lp->ptid));
}
errno = 0;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ret = kill_lwp (ptid_get_lwp (lp->ptid), SIGSTOP);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"SC: lwp kill %d %s\n",
ret,
errno ? safe_strerror (errno) : "ERRNO-OK");
}
lp->signalled = 1;
gdb_assert (lp->status == 0);
}
return 0;
}
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
/* Request a stop on LWP. */
void
linux_stop_lwp (struct lwp_info *lwp)
{
stop_callback (lwp, NULL);
}
GNU/Linux: Stop using libthread_db/td_ta_thr_iter TL;DR - GDB can hang if something refreshes the thread list out of the target while the target is running. GDB hangs inside td_ta_thr_iter. The fix is to not use that libthread_db function anymore. Long version: Running the testsuite against my all-stop-on-top-of-non-stop series is still exposing latent non-stop bugs. I was originally seeing this with the multi-create.exp test, back when we were still using libthread_db thread event breakpoints. The all-stop-on-top-of-non-stop series forces a thread list refresh each time GDB needs to start stepping over a breakpoint (to pause all threads). That test hits the thread event breakpoint often, resulting in a bunch of step-over operations, thus a bunch of thread list refreshes while some threads in the target are running. The commit adds a real non-stop mode test that triggers the issue, based on multi-create.exp, that does an explicit "info threads" when a breakpoint is hit. IOW, it does the same things the as-ns series was doing when testing multi-create.exp. The bug is a race, so it unfortunately takes several runs for the test to trigger it. In fact, even when setting the test running in a loop, it sometimes takes several minutes for it to trigger for me. The race is related to libthread_db's td_ta_thr_iter. This is libthread_db's entry point for walking the thread list of the inferior. Sometimes, when GDB refreshes the thread list from the target, libthread_db's td_ta_thr_iter can somehow see glibc's thread list as a cycle, and get stuck in an infinite loop. The issue is that when a thread exits, its thread control structure in glibc is moved from a "used" list to a "cache" list. These lists are simply circular linked lists where the "next/prev" pointers are embedded in the thread control structure itself. The "next" pointer of the last element of the list points back to the list's sentinel "head". There's only one set of "next/prev" pointers for both lists; thus a thread can only be in one of the lists at a time, not in both simultaneously. So when thread C exits, simplifying, the following happens. A-C are threads. stack_used and stack_cache are the list's heads. Before: stack_used -> A -> B -> C -> (&stack_used) stack_cache -> (&stack_cache) After: stack_used -> A -> B -> (&stack_used) stack_cache -> C -> (&stack_cache) td_ta_thr_iter starts by iterating at the list's head's next, and iterates until it sees a thread whose next pointer points to the list's head again. Thus in the before case above, C's next points to stack_used, indicating end of list. In the same case, the stack_cache list is empty. For each thread being iterated, td_ta_thr_iter reads the whole thread object out of the inferior. This includes the thread's "next" pointer. In the scenario above, it may happen that td_ta_thr_iter is iterating thread B and has already read B's thread structure just before thread C exits and its control structure moves to the cached list. Now, recall that td_ta_thr_iter is running in the context of GDB, and there's no locking between GDB and the inferior. From it's local copy of B, td_ta_thr_iter believes that the next thread after B is thread C, so it happilly continues iterating to C, a thread that has already exited, and is now in the stack cache list. After iterating C, td_ta_thr_iter finds the stack_cache head, which because it is not stack_used, td_ta_thr_iter assumes it's just another thread. After this, unless the reverse race triggers, GDB gets stuck in td_ta_thr_iter forever walking the stack_cache list, as no thread in thatlist has a next pointer that points back to stack_used (the terminating condition). Before fully understanding the issue, I tried adding cycle detection to GDB's td_ta_thr_iter callback. However, td_ta_thr_iter skips calling the callback in some cases, which means that it's possible that the callback isn't called at all, making it impossible for GDB to break the loop. I did manage to get GDB stuck in that state more than once. Fortunately, we can avoid the issue altogether. We don't really need td_ta_thr_iter for live debugging nowadays, given PTRACE_EVENT_CLONE. We already know how to map and lwp id to a thread id without iterating (thread_from_lwp), so use that more. gdb/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_handle_extended_wait): Call thread_db_notice_clone whenever a new clone LWP is detected. (linux_stop_and_wait_all_lwps, linux_unstop_all_lwps): New functions. * linux-nat.h (thread_db_attach_lwp): Delete declaration. (thread_db_notice_clone, linux_stop_and_wait_all_lwps) (linux_unstop_all_lwps): Declare. * linux-thread-db.c (struct thread_get_info_inout): Delete. (thread_get_info_callback): Delete. (thread_from_lwp): Use td_thr_get_info and record_thread. (thread_db_attach_lwp): Delete. (thread_db_notice_clone): New function. (try_thread_db_load_1): If /proc is mounted and shows the process'es task list, walk over all LWPs and call thread_from_lwp instead of relying on td_ta_thr_iter. (attach_thread): Don't call check_thread_signals here. Split the tail part of the function (which adds the thread to the core GDB thread list) to ... (record_thread): ... this function. Call check_thread_signals here. (thread_db_wait): Don't call thread_db_find_new_threads_1. Always call thread_from_lwp. (thread_db_update_thread_list): Rename to ... (thread_db_update_thread_list_org): ... this. (thread_db_update_thread_list): New function. (thread_db_find_thread_from_tid): Delete. (thread_db_get_ada_task_ptid): Simplify. * nat/linux-procfs.c: Include <sys/stat.h>. (linux_proc_task_list_dir_exists): New function. * nat/linux-procfs.h (linux_proc_task_list_dir_exists): Declare. gdb/gdbserver/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * thread-db.c: Include "nat/linux-procfs.h". (thread_db_init): Skip listing new threads if the kernel supports PTRACE_EVENT_CLONE and /proc/PID/task/ is accessible. gdb/testsuite/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * gdb.threads/multi-create-ns-info-thr.exp: New file.
2015-02-20 21:21:59 +01:00
/* See linux-nat.h */
void
linux_stop_and_wait_all_lwps (void)
{
/* Stop all LWP's ... */
iterate_over_lwps (minus_one_ptid, stop_callback, NULL);
/* ... and wait until all of them have reported back that
they're no longer running. */
iterate_over_lwps (minus_one_ptid, stop_wait_callback, NULL);
}
/* See linux-nat.h */
void
linux_unstop_all_lwps (void)
{
iterate_over_lwps (minus_one_ptid,
resume_stopped_resumed_lwps, &minus_one_ptid);
}
/* Return non-zero if LWP PID has a pending SIGINT. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static int
linux_nat_has_pending_sigint (int pid)
{
sigset_t pending, blocked, ignored;
linux_proc_pending_signals (pid, &pending, &blocked, &ignored);
if (sigismember (&pending, SIGINT)
&& !sigismember (&ignored, SIGINT))
return 1;
return 0;
}
/* Set a flag in LP indicating that we should ignore its next SIGINT. */
static int
set_ignore_sigint (struct lwp_info *lp, void *data)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
/* If a thread has a pending SIGINT, consume it; otherwise, set a
flag to consume the next one. */
if (lp->stopped && lp->status != 0 && WIFSTOPPED (lp->status)
&& WSTOPSIG (lp->status) == SIGINT)
lp->status = 0;
else
lp->ignore_sigint = 1;
return 0;
}
/* If LP does not have a SIGINT pending, then clear the ignore_sigint flag.
This function is called after we know the LWP has stopped; if the LWP
stopped before the expected SIGINT was delivered, then it will never have
arrived. Also, if the signal was delivered to a shared queue and consumed
by a different thread, it will never be delivered to this LWP. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static void
maybe_clear_ignore_sigint (struct lwp_info *lp)
{
if (!lp->ignore_sigint)
return;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (!linux_nat_has_pending_sigint (ptid_get_lwp (lp->ptid)))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"MCIS: Clearing bogus flag for %s\n",
target_pid_to_str (lp->ptid));
lp->ignore_sigint = 0;
}
}
/* Fetch the possible triggered data watchpoint info and store it in
LP.
On some archs, like x86, that use debug registers to set
watchpoints, it's possible that the way to know which watched
address trapped, is to check the register that is used to select
which address to watch. Problem is, between setting the watchpoint
and reading back which data address trapped, the user may change
the set of watchpoints, and, as a consequence, GDB changes the
debug registers in the inferior. To avoid reading back a stale
stopped-data-address when that happens, we cache in LP the fact
that a watchpoint trapped, and the corresponding data address, as
soon as we see LP stop with a SIGTRAP. If GDB changes the debug
registers meanwhile, we have the cached data we can rely on. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
static int
check_stopped_by_watchpoint (struct lwp_info *lp)
{
struct cleanup *old_chain;
if (linux_ops->to_stopped_by_watchpoint == NULL)
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
return 0;
old_chain = save_inferior_ptid ();
inferior_ptid = lp->ptid;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (linux_ops->to_stopped_by_watchpoint (linux_ops))
{
lp->stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (linux_ops->to_stopped_data_address != NULL)
lp->stopped_data_address_p =
linux_ops->to_stopped_data_address (&current_target,
&lp->stopped_data_address);
else
lp->stopped_data_address_p = 0;
}
do_cleanups (old_chain);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
return lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
}
/* Returns true if the LWP had stopped for a watchpoint. */
static int
add "this" pointers to more target APIs A subsequent pass introduces delegation helper functions to the target API. This delegation is much cleaner if the target_ops pointer is directly available at delegation time. This patch adds the "this" pointer to various to_* methods for this purpose. This updates a number of ports which I am unable to test. Please give them a look-over. Any possible problem here is trivial, though, as all that is required is adding an argument to a function. 2014-02-19 Tom Tromey <tromey@redhat.com> * aarch64-linux-nat.c (aarch64_linux_stopped_by_watchpoint): Add 'ops' argument. * arm-linux-nat.c (arm_linux_stopped_by_watchpoint): Add 'ops' argument. * i386-nat.c (i386_stopped_by_watchpoint): Add 'ops' argument. * ia64-linux-nat.c (ia64_linux_stopped_by_watchpoint): Add 'ops' argument. * inf-ttrace.c (inf_ttrace_stopped_by_watchpoint): Add 'ops' argument. * linux-nat.c (save_sigtrap): Update. (linux_nat_stopped_by_watchpoint, linux_nat_is_async_p) (linux_nat_can_async_p, linux_nat_async): Add 'ops' argument. (linux_nat_close): Update. * mips-linux-nat.c (mips_linux_stopped_by_watchpoint): Add 'ops' argument. * ppc-linux-nat.c (ppc_linux_stopped_by_watchpoint): Add 'ops' argument. * procfs.c (procfs_stopped_by_watchpoint): Add 'ops' argument. * record-full.c (record_full_beneath_to_stopped_by_watchpoint) (record_full_beneath_to_async, tmp_to_stopped_by_watchpoint) (tmp_to_async): Add 'ops' argument. (record_full_stopped_by_watchpoint, record_full_async) (record_full_can_async_p, record_full_is_async_p): Add 'ops' argument. * remote-m32r-sdi.c (m32r_insert_breakpoint, m32r_remove_breakpoint) (m32r_stopped_by_watchpoint): Add 'ops' argument. * remote-mips.c (mips_stopped_by_watchpoint): Add 'ops' argument. * remote.c (remote_stopped_by_watchpoint_p, remote_can_async_p) (remote_is_async_p, remote_async): Add 'ops' argument. (remote_stopped_data_address): Update. * s390-nat.c (s390_stopped_by_watchpoint): Add 'ops' argument. * target.c (update_current_target) (find_default_can_async_p, find_default_is_async_p): Update. (init_dummy_target): Update. (debug_to_stopped_by_watchpoint): Add 'ops' argument. * target.h (struct target_ops) <to_stopped_by_watchpoint, to_can_async_p, to_is_async_p, to_async>: Add 'ops' argument. (target_can_async_p, target_is_async_p, target_async) (target_stopped_by_watchpoint): Update.
2013-07-30 18:36:07 +02:00
linux_nat_stopped_by_watchpoint (struct target_ops *ops)
{
struct lwp_info *lp = find_lwp_pid (inferior_ptid);
gdb_assert (lp != NULL);
return lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
}
static int
linux_nat_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
{
struct lwp_info *lp = find_lwp_pid (inferior_ptid);
gdb_assert (lp != NULL);
*addr_p = lp->stopped_data_address;
return lp->stopped_data_address_p;
}
/* Commonly any breakpoint / watchpoint generate only SIGTRAP. */
static int
sigtrap_is_event (int status)
{
return WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP;
}
/* Set alternative SIGTRAP-like events recognizer. If
breakpoint_inserted_here_p there then gdbarch_decr_pc_after_break will be
applied. */
void
linux_nat_set_status_is_event (struct target_ops *t,
int (*status_is_event) (int status))
{
linux_nat_status_is_event = status_is_event;
}
/* Wait until LP is stopped. */
static int
stop_wait_callback (struct lwp_info *lp, void *data)
{
struct inferior *inf = find_inferior_ptid (lp->ptid);
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> 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 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* If this is a vfork parent, bail out, it is not going to report
any SIGSTOP until the vfork is done with. */
if (inf->vfork_child != NULL)
return 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (!lp->stopped)
{
int status;
status = wait_lwp (lp);
if (status == 0)
return 0;
if (lp->ignore_sigint && WIFSTOPPED (status)
&& WSTOPSIG (status) == SIGINT)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
lp->ignore_sigint = 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
errno = 0;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptrace (PTRACE_CONT, ptid_get_lwp (lp->ptid), 0, 0);
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
lp->stopped = 0;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
"PTRACE_CONT %s, 0, 0 (%s) "
"(discarding SIGINT)\n",
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
target_pid_to_str (lp->ptid),
errno ? safe_strerror (errno) : "OK");
return stop_wait_callback (lp, NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
maybe_clear_ignore_sigint (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (WSTOPSIG (status) != SIGSTOP)
{
/* The thread was stopped with a signal other than SIGSTOP. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SWC: Pending event %s in %s\n",
status_to_str ((int) status),
target_pid_to_str (lp->ptid));
/* Save the sigtrap event. */
lp->status = status;
gdb_assert (lp->signalled);
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
save_stop_reason (lp);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
else
{
/* We caught the SIGSTOP that we intended to catch, so
there's no SIGSTOP pending. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SWC: Expected SIGSTOP caught for %s.\n",
target_pid_to_str (lp->ptid));
/* Reset SIGNALLED only after the stop_wait_callback call
above as it does gdb_assert on SIGNALLED. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
lp->signalled = 0;
}
}
return 0;
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Return non-zero if LP has a wait status pending. Discard the
pending event and resume the LWP if the event that originally
caused the stop became uninteresting. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static int
status_callback (struct lwp_info *lp, void *data)
{
/* Only report a pending wait status if we pretend that this has
indeed been resumed. */
if (!lp->resumed)
return 0;
if (!lwp_status_pending_p (lp))
return 0;
if (lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT
|| lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
struct regcache *regcache = get_thread_regcache (lp->ptid);
CORE_ADDR pc;
int discard = 0;
pc = regcache_read_pc (regcache);
if (pc != lp->stop_pc)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SC: PC of %s changed. was=%s, now=%s\n",
target_pid_to_str (lp->ptid),
paddress (target_gdbarch (), lp->stop_pc),
paddress (target_gdbarch (), pc));
discard = 1;
}
#if !USE_SIGTRAP_SIGINFO
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
else if (!breakpoint_inserted_here_p (get_regcache_aspace (regcache), pc))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SC: previous breakpoint of %s, at %s gone\n",
target_pid_to_str (lp->ptid),
paddress (target_gdbarch (), lp->stop_pc));
discard = 1;
}
#endif
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (discard)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SC: pending event of %s cancelled.\n",
target_pid_to_str (lp->ptid));
lp->status = 0;
linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
return 0;
}
}
return 1;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Count the LWP's that have had events. */
static int
count_events_callback (struct lwp_info *lp, void *data)
{
Add some more casts (1/2) Note: I needed to split this patch in two, otherwise it's too big for the mailing list. This patch adds explicit casts to situations where a void pointer is assigned to a pointer to the "real" type. Building in C++ mode requires those assignments to use an explicit cast. This includes, for example: - callback arguments (cleanups, comparison functions, ...) - data attached to some object (objfile, program space, etc) in the form of a void pointer - "user data" passed to some function This patch comes from the commit "(mostly) auto-generated patch to insert casts needed for C++", taken from Pedro's C++ branch. Only files built on x86 with --enable-targets=all are modified, so the native files for other arches will need to be dealt with separately. I built-tested this with --enable-targets=all and reg-tested. To my surprise, a test case (selftest.exp) had to be adjusted. Here's the ChangeLog entry. Again, this was relatively quick to make despite the length, thanks to David Malcom's script, although I don't believe it's very useful information in that particular case... gdb/ChangeLog: * aarch64-tdep.c (aarch64_make_prologue_cache): Add cast(s). (aarch64_make_stub_cache): Likewise. (value_of_aarch64_user_reg): Likewise. * ada-lang.c (ada_inferior_data_cleanup): Likewise. (get_ada_inferior_data): Likewise. (get_ada_pspace_data): Likewise. (ada_pspace_data_cleanup): Likewise. (ada_complete_symbol_matcher): Likewise. (ada_exc_search_name_matches): Likewise. * ada-tasks.c (get_ada_tasks_pspace_data): Likewise. (get_ada_tasks_inferior_data): Likewise. * addrmap.c (addrmap_mutable_foreach_worker): Likewise. (splay_obstack_alloc): Likewise. (splay_obstack_free): Likewise. * alpha-linux-tdep.c (alpha_linux_supply_gregset): Likewise. (alpha_linux_collect_gregset): Likewise. (alpha_linux_supply_fpregset): Likewise. (alpha_linux_collect_fpregset): Likewise. * alpha-mdebug-tdep.c (alpha_mdebug_frame_unwind_cache): Likewise. * alpha-tdep.c (alpha_lds): Likewise. (alpha_sts): Likewise. (alpha_sigtramp_frame_unwind_cache): Likewise. (alpha_heuristic_frame_unwind_cache): Likewise. (alpha_supply_int_regs): Likewise. (alpha_fill_int_regs): Likewise. (alpha_supply_fp_regs): Likewise. (alpha_fill_fp_regs): Likewise. * alphanbsd-tdep.c (alphanbsd_supply_fpregset): Likewise. (alphanbsd_aout_supply_gregset): Likewise. (alphanbsd_supply_gregset): Likewise. * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise. (amd64_x32_linux_init_abi): Likewise. * amd64-nat.c (amd64_supply_native_gregset): Likewise. (amd64_collect_native_gregset): Likewise. * amd64-tdep.c (amd64_frame_cache): Likewise. (amd64_sigtramp_frame_cache): Likewise. (amd64_epilogue_frame_cache): Likewise. (amd64_supply_fxsave): Likewise. (amd64_supply_xsave): Likewise. (amd64_collect_fxsave): Likewise. (amd64_collect_xsave): Likewise. * amd64-windows-tdep.c (amd64_windows_frame_cache): Likewise. * amd64obsd-tdep.c (amd64obsd_trapframe_cache): Likewise. * arm-linux-tdep.c (arm_linux_supply_gregset): Likewise. (arm_linux_collect_gregset): Likewise. (arm_linux_supply_nwfpe): Likewise. (arm_linux_collect_nwfpe): Likewise. (arm_linux_supply_vfp): Likewise. (arm_linux_collect_vfp): Likewise. * arm-tdep.c (arm_find_mapping_symbol): Likewise. (arm_prologue_unwind_stop_reason): Likewise. (arm_prologue_this_id): Likewise. (arm_prologue_prev_register): Likewise. (arm_exidx_data_free): Likewise. (arm_find_exidx_entry): Likewise. (arm_stub_this_id): Likewise. (arm_m_exception_this_id): Likewise. (arm_m_exception_prev_register): Likewise. (arm_normal_frame_base): Likewise. (gdb_print_insn_arm): Likewise. (arm_objfile_data_free): Likewise. (arm_record_special_symbol): Likewise. (value_of_arm_user_reg): Likewise. * armbsd-tdep.c (armbsd_supply_fpregset): Likewise. (armbsd_supply_gregset): Likewise. * auto-load.c (auto_load_pspace_data_cleanup): Likewise. (get_auto_load_pspace_data): Likewise. (hash_loaded_script_entry): Likewise. (eq_loaded_script_entry): Likewise. (clear_section_scripts): Likewise. (collect_matching_scripts): Likewise. * auxv.c (auxv_inferior_data_cleanup): Likewise. (get_auxv_inferior_data): Likewise. * avr-tdep.c (avr_frame_unwind_cache): Likewise. * ax-general.c (do_free_agent_expr_cleanup): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. (target_bfd_xclose): Likewise. (target_bfd_get_section_table): Likewise. * bfin-tdep.c (bfin_frame_cache): Likewise. * block.c (find_block_in_blockvector): Likewise. (call_site_for_pc): Likewise. (block_find_non_opaque_type_preferred): Likewise. * break-catch-sig.c (signal_catchpoint_insert_location): Likewise. (signal_catchpoint_remove_location): Likewise. (signal_catchpoint_breakpoint_hit): Likewise. (signal_catchpoint_print_one): Likewise. (signal_catchpoint_print_mention): Likewise. (signal_catchpoint_print_recreate): Likewise. * break-catch-syscall.c (get_catch_syscall_inferior_data): Likewise. * breakpoint.c (do_cleanup_counted_command_line): Likewise. (bp_location_compare_addrs): Likewise. (get_first_locp_gte_addr): Likewise. (check_tracepoint_command): Likewise. (do_map_commands_command): Likewise. (get_breakpoint_objfile_data): Likewise. (free_breakpoint_probes): Likewise. (do_captured_breakpoint_query): Likewise. (compare_breakpoints): Likewise. (bp_location_compare): Likewise. (bpstat_remove_breakpoint_callback): Likewise. (do_delete_breakpoint_cleanup): Likewise. * bsd-uthread.c (bsd_uthread_set_supply_uthread): Likewise. (bsd_uthread_set_collect_uthread): Likewise. (bsd_uthread_activate): Likewise. (bsd_uthread_fetch_registers): Likewise. (bsd_uthread_store_registers): Likewise. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt_raw): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. (do_btrace_data_cleanup): Likewise. * c-typeprint.c (find_typedef_for_canonicalize): Likewise. * charset.c (cleanup_iconv): Likewise. (do_cleanup_iterator): Likewise. * cli-out.c (cli_uiout_dtor): Likewise. (cli_table_begin): Likewise. (cli_table_body): Likewise. (cli_table_end): Likewise. (cli_table_header): Likewise. (cli_begin): Likewise. (cli_end): Likewise. (cli_field_int): Likewise. (cli_field_skip): Likewise. (cli_field_string): Likewise. (cli_field_fmt): Likewise. (cli_spaces): Likewise. (cli_text): Likewise. (cli_message): Likewise. (cli_wrap_hint): Likewise. (cli_flush): Likewise. (cli_redirect): Likewise. (out_field_fmt): Likewise. (field_separator): Likewise. (cli_out_set_stream): Likewise. * cli/cli-cmds.c (compare_symtabs): Likewise. * cli/cli-dump.c (call_dump_func): Likewise. (restore_section_callback): Likewise. * cli/cli-script.c (clear_hook_in_cleanup): Likewise. (do_restore_user_call_depth): Likewise. (do_free_command_lines_cleanup): Likewise. * coff-pe-read.c (get_section_vmas): Likewise. (pe_as16): Likewise. (pe_as32): Likewise. * coffread.c (coff_symfile_read): Likewise. * common/agent.c (agent_look_up_symbols): Likewise. * common/filestuff.c (do_close_cleanup): Likewise. * common/format.c (free_format_pieces_cleanup): Likewise. * common/vec.c (vec_o_reserve): Likewise. * compile/compile-c-support.c (print_one_macro): Likewise. * compile/compile-c-symbols.c (hash_symbol_error): Likewise. (eq_symbol_error): Likewise. (del_symbol_error): Likewise. (error_symbol_once): Likewise. (gcc_convert_symbol): Likewise. (gcc_symbol_address): Likewise. (hash_symname): Likewise. (eq_symname): Likewise. * compile/compile-c-types.c (hash_type_map_instance): Likewise. (eq_type_map_instance): Likewise. (insert_type): Likewise. (convert_type): Likewise. * compile/compile-object-load.c (munmap_listp_free_cleanup): Likewise. (setup_sections): Likewise. (link_hash_table_free): Likewise. (copy_sections): Likewise. * compile/compile-object-run.c (do_module_cleanup): Likewise. * compile/compile.c (compile_print_value): Likewise. (do_rmdir): Likewise. (cleanup_compile_instance): Likewise. (cleanup_unlink_file): Likewise. * completer.c (free_completion_tracker): Likewise. * corelow.c (add_to_spuid_list): Likewise. * cp-namespace.c (reset_directive_searched): Likewise. * cp-support.c (reset_directive_searched): Likewise. * cris-tdep.c (cris_sigtramp_frame_unwind_cache): Likewise. (cris_frame_unwind_cache): Likewise. * d-lang.c (builtin_d_type): Likewise. * d-namespace.c (reset_directive_searched): Likewise. * dbxread.c (dbx_free_symfile_info): Likewise. (do_free_bincl_list_cleanup): Likewise. * disasm.c (hash_dis_line_entry): Likewise. (eq_dis_line_entry): Likewise. (dis_asm_print_address): Likewise. (fprintf_disasm): Likewise. (do_ui_file_delete): Likewise. * doublest.c (convert_floatformat_to_doublest): Likewise. * dummy-frame.c (pop_dummy_frame_bpt): Likewise. (dummy_frame_prev_register): Likewise. (dummy_frame_this_id): Likewise. * dwarf2-frame-tailcall.c (cache_hash): Likewise. (cache_eq): Likewise. (cache_find): Likewise. (tailcall_frame_this_id): Likewise. (dwarf2_tailcall_prev_register_first): Likewise. (tailcall_frame_prev_register): Likewise. (tailcall_frame_dealloc_cache): Likewise. (tailcall_frame_prev_arch): Likewise. * dwarf2-frame.c (dwarf2_frame_state_free): Likewise. (dwarf2_frame_set_init_reg): Likewise. (dwarf2_frame_init_reg): Likewise. (dwarf2_frame_set_signal_frame_p): Likewise. (dwarf2_frame_signal_frame_p): Likewise. (dwarf2_frame_set_adjust_regnum): Likewise. (dwarf2_frame_adjust_regnum): Likewise. (clear_pointer_cleanup): Likewise. (dwarf2_frame_cache): Likewise. (find_cie): Likewise. (dwarf2_frame_find_fde): Likewise. * dwarf2expr.c (dwarf_expr_address_type): Likewise. (free_dwarf_expr_context_cleanup): Likewise. * dwarf2loc.c (locexpr_find_frame_base_location): Likewise. (locexpr_get_frame_base): Likewise. (loclist_find_frame_base_location): Likewise. (loclist_get_frame_base): Likewise. (dwarf_expr_dwarf_call): Likewise. (dwarf_expr_get_base_type): Likewise. (dwarf_expr_push_dwarf_reg_entry_value): Likewise. (dwarf_expr_get_obj_addr): Likewise. (entry_data_value_coerce_ref): Likewise. (entry_data_value_copy_closure): Likewise. (entry_data_value_free_closure): Likewise. (get_frame_address_in_block_wrapper): Likewise. (dwarf2_evaluate_property): Likewise. (dwarf2_compile_property_to_c): Likewise. (needs_frame_read_addr_from_reg): Likewise. (needs_frame_get_reg_value): Likewise. (needs_frame_frame_base): Likewise. (needs_frame_frame_cfa): Likewise. (needs_frame_tls_address): Likewise. (needs_frame_dwarf_call): Likewise. (needs_dwarf_reg_entry_value): Likewise. (get_ax_pc): Likewise. (locexpr_read_variable): Likewise. (locexpr_read_variable_at_entry): Likewise. (locexpr_read_needs_frame): Likewise. (locexpr_describe_location): Likewise. (locexpr_tracepoint_var_ref): Likewise. (locexpr_generate_c_location): Likewise. (loclist_read_variable): Likewise. (loclist_read_variable_at_entry): Likewise. (loclist_describe_location): Likewise. (loclist_tracepoint_var_ref): Likewise. (loclist_generate_c_location): Likewise. * dwarf2read.c (line_header_hash_voidp): Likewise. (line_header_eq_voidp): Likewise. (dwarf2_has_info): Likewise. (dwarf2_get_section_info): Likewise. (locate_dwz_sections): Likewise. (hash_file_name_entry): Likewise. (eq_file_name_entry): Likewise. (delete_file_name_entry): Likewise. (dw2_setup): Likewise. (dw2_get_file_names_reader): Likewise. (dw2_find_pc_sect_compunit_symtab): Likewise. (hash_signatured_type): Likewise. (eq_signatured_type): Likewise. (add_signatured_type_cu_to_table): Likewise. (create_debug_types_hash_table): Likewise. (lookup_dwo_signatured_type): Likewise. (lookup_dwp_signatured_type): Likewise. (lookup_signatured_type): Likewise. (hash_type_unit_group): Likewise. (eq_type_unit_group): Likewise. (get_type_unit_group): Likewise. (process_psymtab_comp_unit_reader): Likewise. (sort_tu_by_abbrev_offset): Likewise. (process_skeletonless_type_unit): Likewise. (psymtabs_addrmap_cleanup): Likewise. (dwarf2_read_symtab): Likewise. (psymtab_to_symtab_1): Likewise. (die_hash): Likewise. (die_eq): Likewise. (load_full_comp_unit_reader): Likewise. (reset_die_in_process): Likewise. (free_cu_line_header): Likewise. (handle_DW_AT_stmt_list): Likewise. (hash_dwo_file): Likewise. (eq_dwo_file): Likewise. (hash_dwo_unit): Likewise. (eq_dwo_unit): Likewise. (create_dwo_cu_reader): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (lookup_dwo_unit_in_dwp): Likewise. (dwarf2_locate_dwo_sections): Likewise. (dwarf2_locate_common_dwp_sections): Likewise. (dwarf2_locate_v2_dwp_sections): Likewise. (hash_dwp_loaded_cutus): Likewise. (eq_dwp_loaded_cutus): Likewise. (lookup_dwo_cutu): Likewise. (abbrev_table_free_cleanup): Likewise. (dwarf2_free_abbrev_table): Likewise. (find_partial_die_in_comp_unit): Likewise. (free_line_header_voidp): Likewise. (follow_die_offset): Likewise. (follow_die_sig_1): Likewise. (free_heap_comp_unit): Likewise. (free_stack_comp_unit): Likewise. (dwarf2_free_objfile): Likewise. (per_cu_offset_and_type_hash): Likewise. (per_cu_offset_and_type_eq): Likewise. (get_die_type_at_offset): Likewise. (partial_die_hash): Likewise. (partial_die_eq): Likewise. (dwarf2_per_objfile_free): Likewise. (hash_strtab_entry): Likewise. (eq_strtab_entry): Likewise. (add_string): Likewise. (hash_symtab_entry): Likewise. (eq_symtab_entry): Likewise. (delete_symtab_entry): Likewise. (cleanup_mapped_symtab): Likewise. (add_indices_to_cpool): Likewise. (hash_psymtab_cu_index): Likewise. (eq_psymtab_cu_index): Likewise. (add_address_entry_worker): Likewise. (unlink_if_set): Likewise. (write_one_signatured_type): Likewise. (save_gdb_index_command): Likewise. * elfread.c (elf_symtab_read): Likewise. (elf_gnu_ifunc_cache_hash): Likewise. (elf_gnu_ifunc_cache_eq): Likewise. (elf_gnu_ifunc_record_cache): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_get_probes): Likewise. (probe_key_free): Likewise. * f-lang.c (builtin_f_type): Likewise. * frame-base.c (frame_base_append_sniffer): Likewise. (frame_base_set_default): Likewise. (frame_base_find_by_frame): Likewise. * frame-unwind.c (frame_unwind_prepend_unwinder): Likewise. (frame_unwind_append_unwinder): Likewise. (frame_unwind_find_by_frame): Likewise. * frame.c (frame_addr_hash): Likewise. (frame_addr_hash_eq): Likewise. (frame_stash_find): Likewise. (do_frame_register_read): Likewise. (unwind_to_current_frame): Likewise. (frame_cleanup_after_sniffer): Likewise. * frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise. * frv-tdep.c (frv_frame_unwind_cache): Likewise. * ft32-tdep.c (ft32_frame_cache): Likewise. * gcore.c (do_bfd_delete_cleanup): Likewise. (gcore_create_callback): Likewise. * gdb_bfd.c (hash_bfd): Likewise. (eq_bfd): Likewise. (gdb_bfd_open): Likewise. (free_one_bfd_section): Likewise. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (get_section_descriptor): Likewise. (gdb_bfd_map_section): Likewise. (gdb_bfd_crc): Likewise. (gdb_bfd_mark_parent): Likewise. (gdb_bfd_record_inclusion): Likewise. (gdb_bfd_requires_relocations): Likewise. (print_one_bfd): Likewise. * gdbtypes.c (type_pair_hash): Likewise. (type_pair_eq): Likewise. (builtin_type): Likewise. (objfile_type): Likewise. * gnu-v3-abi.c (vtable_ptrdiff_type): Likewise. (vtable_address_point_offset): Likewise. (gnuv3_get_vtable): Likewise. (hash_value_and_voffset): Likewise. (eq_value_and_voffset): Likewise. (compare_value_and_voffset): Likewise. (compute_vtable_size): Likewise. (gnuv3_get_typeid_type): Likewise. * go-lang.c (builtin_go_type): Likewise. * guile/scm-block.c (bkscm_hash_block_smob): Likewise. (bkscm_eq_block_smob): Likewise. (bkscm_objfile_block_map): Likewise. (bkscm_del_objfile_blocks): Likewise. * guile/scm-breakpoint.c (bpscm_build_bp_list): Likewise. * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): Likewise. (gdbscm_disasm_print_address): Likewise. * guile/scm-frame.c (frscm_hash_frame_smob): Likewise. (frscm_eq_frame_smob): Likewise. (frscm_inferior_frame_map): Likewise. (frscm_del_inferior_frames): Likewise. * guile/scm-gsmob.c (gdbscm_add_objfile_ref): Likewise. * guile/scm-objfile.c (ofscm_handle_objfile_deleted): Likewise. (ofscm_objfile_smob_from_objfile): Likewise. * guile/scm-ports.c (ioscm_write): Likewise. (ioscm_file_port_delete): Likewise. (ioscm_file_port_rewind): Likewise. (ioscm_file_port_put): Likewise. (ioscm_file_port_write): Likewise. * guile/scm-progspace.c (psscm_handle_pspace_deleted): Likewise. (psscm_pspace_smob_from_pspace): Likewise. * guile/scm-safe-call.c (scscm_recording_pre_unwind_handler): Likewise. (scscm_recording_unwind_handler): Likewise. (gdbscm_with_catch): Likewise. (scscm_call_0_body): Likewise. (scscm_call_1_body): Likewise. (scscm_call_2_body): Likewise. (scscm_call_3_body): Likewise. (scscm_call_4_body): Likewise. (scscm_apply_1_body): Likewise. (scscm_eval_scheme_string): Likewise. (gdbscm_safe_eval_string): Likewise. (scscm_source_scheme_script): Likewise. (gdbscm_safe_source_script): Likewise. * guile/scm-string.c (gdbscm_call_scm_to_stringn): Likewise. (gdbscm_call_scm_from_stringn): Likewise. * guile/scm-symbol.c (syscm_hash_symbol_smob): Likewise. (syscm_eq_symbol_smob): Likewise. (syscm_get_symbol_map): Likewise. (syscm_del_objfile_symbols): Likewise. * guile/scm-symtab.c (stscm_hash_symtab_smob): Likewise. (stscm_eq_symtab_smob): Likewise. (stscm_objfile_symtab_map): Likewise. (stscm_del_objfile_symtabs): Likewise. * guile/scm-type.c (tyscm_hash_type_smob): Likewise. (tyscm_eq_type_smob): Likewise. (tyscm_type_map): Likewise. (tyscm_copy_type_recursive): Likewise. (save_objfile_types): Likewise. * guile/scm-utils.c (extract_arg): Likewise. * h8300-tdep.c (h8300_frame_cache): Likewise. * hppa-linux-tdep.c (hppa_linux_sigtramp_frame_unwind_cache): Likewise. * hppa-tdep.c (compare_unwind_entries): Likewise. (find_unwind_entry): Likewise. (hppa_frame_cache): Likewise. (hppa_stub_frame_unwind_cache): Likewise. * hppanbsd-tdep.c (hppanbsd_supply_gregset): Likewise. * hppaobsd-tdep.c (hppaobsd_supply_gregset): Likewise. (hppaobsd_supply_fpregset): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * i386-tdep.c (i386_frame_cache): Likewise. (i386_epilogue_frame_cache): Likewise. (i386_sigtramp_frame_cache): Likewise. (i386_supply_gregset): Likewise. (i386_collect_gregset): Likewise. (i386_gdbarch_init): Likewise. * i386obsd-tdep.c (i386obsd_aout_supply_regset): Likewise. (i386obsd_trapframe_cache): Likewise. * i387-tdep.c (i387_supply_fsave): Likewise. (i387_collect_fsave): Likewise. (i387_supply_fxsave): Likewise. (i387_collect_fxsave): Likewise. (i387_supply_xsave): Likewise. (i387_collect_xsave): Likewise. * ia64-tdep.c (ia64_frame_cache): Likewise. (ia64_sigtramp_frame_cache): Likewise. * infcmd.c (attach_command_continuation): Likewise. (attach_command_continuation_free_args): Likewise. * inferior.c (restore_inferior): Likewise. (delete_thread_of_inferior): Likewise. * inflow.c (inflow_inferior_data_cleanup): Likewise. (get_inflow_inferior_data): Likewise. (inflow_inferior_exit): Likewise. * infrun.c (displaced_step_clear_cleanup): Likewise. (restore_current_uiout_cleanup): Likewise. (release_stop_context_cleanup): Likewise. (do_restore_infcall_suspend_state_cleanup): Likewise. (do_restore_infcall_control_state_cleanup): Likewise. (restore_inferior_ptid): Likewise. * inline-frame.c (block_starting_point_at): Likewise. * iq2000-tdep.c (iq2000_frame_cache): Likewise. * jit.c (get_jit_objfile_data): Likewise. (get_jit_program_space_data): Likewise. (jit_object_close_impl): Likewise. (jit_find_objf_with_entry_addr): Likewise. (jit_breakpoint_deleted): Likewise. (jit_unwind_reg_set_impl): Likewise. (jit_unwind_reg_get_impl): Likewise. (jit_dealloc_cache): Likewise. (jit_frame_sniffer): Likewise. (jit_frame_prev_register): Likewise. (jit_prepend_unwinder): Likewise. (jit_inferior_exit_hook): Likewise. (free_objfile_data): Likewise. * jv-lang.c (jv_per_objfile_free): Likewise. (get_dynamics_objfile): Likewise. (get_java_class_symtab): Likewise. (builtin_java_type): Likewise. * language.c (language_string_char_type): Likewise. (language_bool_type): Likewise. (language_lookup_primitive_type): Likewise. (language_lookup_primitive_type_as_symbol): Likewise. * linespec.c (hash_address_entry): Likewise. (eq_address_entry): Likewise. (iterate_inline_only): Likewise. (iterate_name_matcher): Likewise. (decode_line_2_compare_items): Likewise. (collect_one_symbol): Likewise. (compare_symbols): Likewise. (compare_msymbols): Likewise. (add_symtabs_to_list): Likewise. (collect_symbols): Likewise. (compare_msyms): Likewise. (add_minsym): Likewise. (cleanup_linespec_result): Likewise. * linux-fork.c (inferior_call_waitpid_cleanup): Likewise. * linux-nat.c (delete_lwp_cleanup): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (resume_stopped_resumed_lwps): Likewise. * linux-tdep.c (get_linux_gdbarch_data): Likewise. (invalidate_linux_cache_inf): Likewise. (get_linux_inferior_data): Likewise. (linux_find_memory_regions_thunk): Likewise. (linux_make_mappings_callback): Likewise. (linux_corefile_thread_callback): Likewise. (find_mapping_size): Likewise. * linux-thread-db.c (find_new_threads_callback): Likewise. * lm32-tdep.c (lm32_frame_cache): Likewise. * m2-lang.c (builtin_m2_type): Likewise. * m32c-tdep.c (m32c_analyze_frame_prologue): Likewise. * m32r-linux-tdep.c (m32r_linux_sigtramp_frame_cache): Likewise. (m32r_linux_supply_gregset): Likewise. (m32r_linux_collect_gregset): Likewise. * m32r-tdep.c (m32r_frame_unwind_cache): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * m68k-tdep.c (m68k_frame_cache): Likewise. * m68kbsd-tdep.c (m68kbsd_supply_fpregset): Likewise. (m68kbsd_supply_gregset): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise. * m88k-tdep.c (m88k_frame_cache): Likewise. (m88k_supply_gregset): Likewise. gdb/gdbserver/ChangeLog: * dll.c (match_dll): Add cast(s). (unloaded_dll): Likewise. * linux-low.c (second_thread_of_pid_p): Likewise. (delete_lwp_callback): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (linux_set_resume_request): Likewise. * server.c (accumulate_file_name_length): Likewise. (emit_dll_description): Likewise. (handle_qxfer_threads_worker): Likewise. (visit_actioned_threads): Likewise. * thread-db.c (any_thread_of): Likewise. * tracepoint.c (same_process_p): Likewise. (match_blocktype): Likewise. (build_traceframe_info_xml): Likewise. gdb/testsuite/ChangeLog: * gdb.gdb/selftest.exp (do_steps_and_nexts): Adjust expected source line.
2015-09-25 20:08:07 +02:00
int *count = (int *) data;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb_assert (count != NULL);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Select only resumed LWPs that have an event pending. */
if (lp->resumed && lwp_status_pending_p (lp))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
(*count)++;
return 0;
}
/* Select the LWP (if any) that is currently being single-stepped. */
static int
select_singlestep_lwp_callback (struct lwp_info *lp, void *data)
{
if (lp->last_resume_kind == resume_step
&& lp->status != 0)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 1;
else
return 0;
}
/* Returns true if LP has a status pending. */
static int
lwp_status_pending_p (struct lwp_info *lp)
{
/* We check for lp->waitstatus in addition to lp->status, because we
can have pending process exits recorded in lp->status and
W_EXITCODE(0,0) happens to be 0. */
return lp->status != 0 || lp->waitstatus.kind != TARGET_WAITKIND_IGNORE;
}
/* Select the Nth LWP that has had an event. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static int
select_event_lwp_callback (struct lwp_info *lp, void *data)
{
Add some more casts (1/2) Note: I needed to split this patch in two, otherwise it's too big for the mailing list. This patch adds explicit casts to situations where a void pointer is assigned to a pointer to the "real" type. Building in C++ mode requires those assignments to use an explicit cast. This includes, for example: - callback arguments (cleanups, comparison functions, ...) - data attached to some object (objfile, program space, etc) in the form of a void pointer - "user data" passed to some function This patch comes from the commit "(mostly) auto-generated patch to insert casts needed for C++", taken from Pedro's C++ branch. Only files built on x86 with --enable-targets=all are modified, so the native files for other arches will need to be dealt with separately. I built-tested this with --enable-targets=all and reg-tested. To my surprise, a test case (selftest.exp) had to be adjusted. Here's the ChangeLog entry. Again, this was relatively quick to make despite the length, thanks to David Malcom's script, although I don't believe it's very useful information in that particular case... gdb/ChangeLog: * aarch64-tdep.c (aarch64_make_prologue_cache): Add cast(s). (aarch64_make_stub_cache): Likewise. (value_of_aarch64_user_reg): Likewise. * ada-lang.c (ada_inferior_data_cleanup): Likewise. (get_ada_inferior_data): Likewise. (get_ada_pspace_data): Likewise. (ada_pspace_data_cleanup): Likewise. (ada_complete_symbol_matcher): Likewise. (ada_exc_search_name_matches): Likewise. * ada-tasks.c (get_ada_tasks_pspace_data): Likewise. (get_ada_tasks_inferior_data): Likewise. * addrmap.c (addrmap_mutable_foreach_worker): Likewise. (splay_obstack_alloc): Likewise. (splay_obstack_free): Likewise. * alpha-linux-tdep.c (alpha_linux_supply_gregset): Likewise. (alpha_linux_collect_gregset): Likewise. (alpha_linux_supply_fpregset): Likewise. (alpha_linux_collect_fpregset): Likewise. * alpha-mdebug-tdep.c (alpha_mdebug_frame_unwind_cache): Likewise. * alpha-tdep.c (alpha_lds): Likewise. (alpha_sts): Likewise. (alpha_sigtramp_frame_unwind_cache): Likewise. (alpha_heuristic_frame_unwind_cache): Likewise. (alpha_supply_int_regs): Likewise. (alpha_fill_int_regs): Likewise. (alpha_supply_fp_regs): Likewise. (alpha_fill_fp_regs): Likewise. * alphanbsd-tdep.c (alphanbsd_supply_fpregset): Likewise. (alphanbsd_aout_supply_gregset): Likewise. (alphanbsd_supply_gregset): Likewise. * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise. (amd64_x32_linux_init_abi): Likewise. * amd64-nat.c (amd64_supply_native_gregset): Likewise. (amd64_collect_native_gregset): Likewise. * amd64-tdep.c (amd64_frame_cache): Likewise. (amd64_sigtramp_frame_cache): Likewise. (amd64_epilogue_frame_cache): Likewise. (amd64_supply_fxsave): Likewise. (amd64_supply_xsave): Likewise. (amd64_collect_fxsave): Likewise. (amd64_collect_xsave): Likewise. * amd64-windows-tdep.c (amd64_windows_frame_cache): Likewise. * amd64obsd-tdep.c (amd64obsd_trapframe_cache): Likewise. * arm-linux-tdep.c (arm_linux_supply_gregset): Likewise. (arm_linux_collect_gregset): Likewise. (arm_linux_supply_nwfpe): Likewise. (arm_linux_collect_nwfpe): Likewise. (arm_linux_supply_vfp): Likewise. (arm_linux_collect_vfp): Likewise. * arm-tdep.c (arm_find_mapping_symbol): Likewise. (arm_prologue_unwind_stop_reason): Likewise. (arm_prologue_this_id): Likewise. (arm_prologue_prev_register): Likewise. (arm_exidx_data_free): Likewise. (arm_find_exidx_entry): Likewise. (arm_stub_this_id): Likewise. (arm_m_exception_this_id): Likewise. (arm_m_exception_prev_register): Likewise. (arm_normal_frame_base): Likewise. (gdb_print_insn_arm): Likewise. (arm_objfile_data_free): Likewise. (arm_record_special_symbol): Likewise. (value_of_arm_user_reg): Likewise. * armbsd-tdep.c (armbsd_supply_fpregset): Likewise. (armbsd_supply_gregset): Likewise. * auto-load.c (auto_load_pspace_data_cleanup): Likewise. (get_auto_load_pspace_data): Likewise. (hash_loaded_script_entry): Likewise. (eq_loaded_script_entry): Likewise. (clear_section_scripts): Likewise. (collect_matching_scripts): Likewise. * auxv.c (auxv_inferior_data_cleanup): Likewise. (get_auxv_inferior_data): Likewise. * avr-tdep.c (avr_frame_unwind_cache): Likewise. * ax-general.c (do_free_agent_expr_cleanup): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. (target_bfd_xclose): Likewise. (target_bfd_get_section_table): Likewise. * bfin-tdep.c (bfin_frame_cache): Likewise. * block.c (find_block_in_blockvector): Likewise. (call_site_for_pc): Likewise. (block_find_non_opaque_type_preferred): Likewise. * break-catch-sig.c (signal_catchpoint_insert_location): Likewise. (signal_catchpoint_remove_location): Likewise. (signal_catchpoint_breakpoint_hit): Likewise. (signal_catchpoint_print_one): Likewise. (signal_catchpoint_print_mention): Likewise. (signal_catchpoint_print_recreate): Likewise. * break-catch-syscall.c (get_catch_syscall_inferior_data): Likewise. * breakpoint.c (do_cleanup_counted_command_line): Likewise. (bp_location_compare_addrs): Likewise. (get_first_locp_gte_addr): Likewise. (check_tracepoint_command): Likewise. (do_map_commands_command): Likewise. (get_breakpoint_objfile_data): Likewise. (free_breakpoint_probes): Likewise. (do_captured_breakpoint_query): Likewise. (compare_breakpoints): Likewise. (bp_location_compare): Likewise. (bpstat_remove_breakpoint_callback): Likewise. (do_delete_breakpoint_cleanup): Likewise. * bsd-uthread.c (bsd_uthread_set_supply_uthread): Likewise. (bsd_uthread_set_collect_uthread): Likewise. (bsd_uthread_activate): Likewise. (bsd_uthread_fetch_registers): Likewise. (bsd_uthread_store_registers): Likewise. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt_raw): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. (do_btrace_data_cleanup): Likewise. * c-typeprint.c (find_typedef_for_canonicalize): Likewise. * charset.c (cleanup_iconv): Likewise. (do_cleanup_iterator): Likewise. * cli-out.c (cli_uiout_dtor): Likewise. (cli_table_begin): Likewise. (cli_table_body): Likewise. (cli_table_end): Likewise. (cli_table_header): Likewise. (cli_begin): Likewise. (cli_end): Likewise. (cli_field_int): Likewise. (cli_field_skip): Likewise. (cli_field_string): Likewise. (cli_field_fmt): Likewise. (cli_spaces): Likewise. (cli_text): Likewise. (cli_message): Likewise. (cli_wrap_hint): Likewise. (cli_flush): Likewise. (cli_redirect): Likewise. (out_field_fmt): Likewise. (field_separator): Likewise. (cli_out_set_stream): Likewise. * cli/cli-cmds.c (compare_symtabs): Likewise. * cli/cli-dump.c (call_dump_func): Likewise. (restore_section_callback): Likewise. * cli/cli-script.c (clear_hook_in_cleanup): Likewise. (do_restore_user_call_depth): Likewise. (do_free_command_lines_cleanup): Likewise. * coff-pe-read.c (get_section_vmas): Likewise. (pe_as16): Likewise. (pe_as32): Likewise. * coffread.c (coff_symfile_read): Likewise. * common/agent.c (agent_look_up_symbols): Likewise. * common/filestuff.c (do_close_cleanup): Likewise. * common/format.c (free_format_pieces_cleanup): Likewise. * common/vec.c (vec_o_reserve): Likewise. * compile/compile-c-support.c (print_one_macro): Likewise. * compile/compile-c-symbols.c (hash_symbol_error): Likewise. (eq_symbol_error): Likewise. (del_symbol_error): Likewise. (error_symbol_once): Likewise. (gcc_convert_symbol): Likewise. (gcc_symbol_address): Likewise. (hash_symname): Likewise. (eq_symname): Likewise. * compile/compile-c-types.c (hash_type_map_instance): Likewise. (eq_type_map_instance): Likewise. (insert_type): Likewise. (convert_type): Likewise. * compile/compile-object-load.c (munmap_listp_free_cleanup): Likewise. (setup_sections): Likewise. (link_hash_table_free): Likewise. (copy_sections): Likewise. * compile/compile-object-run.c (do_module_cleanup): Likewise. * compile/compile.c (compile_print_value): Likewise. (do_rmdir): Likewise. (cleanup_compile_instance): Likewise. (cleanup_unlink_file): Likewise. * completer.c (free_completion_tracker): Likewise. * corelow.c (add_to_spuid_list): Likewise. * cp-namespace.c (reset_directive_searched): Likewise. * cp-support.c (reset_directive_searched): Likewise. * cris-tdep.c (cris_sigtramp_frame_unwind_cache): Likewise. (cris_frame_unwind_cache): Likewise. * d-lang.c (builtin_d_type): Likewise. * d-namespace.c (reset_directive_searched): Likewise. * dbxread.c (dbx_free_symfile_info): Likewise. (do_free_bincl_list_cleanup): Likewise. * disasm.c (hash_dis_line_entry): Likewise. (eq_dis_line_entry): Likewise. (dis_asm_print_address): Likewise. (fprintf_disasm): Likewise. (do_ui_file_delete): Likewise. * doublest.c (convert_floatformat_to_doublest): Likewise. * dummy-frame.c (pop_dummy_frame_bpt): Likewise. (dummy_frame_prev_register): Likewise. (dummy_frame_this_id): Likewise. * dwarf2-frame-tailcall.c (cache_hash): Likewise. (cache_eq): Likewise. (cache_find): Likewise. (tailcall_frame_this_id): Likewise. (dwarf2_tailcall_prev_register_first): Likewise. (tailcall_frame_prev_register): Likewise. (tailcall_frame_dealloc_cache): Likewise. (tailcall_frame_prev_arch): Likewise. * dwarf2-frame.c (dwarf2_frame_state_free): Likewise. (dwarf2_frame_set_init_reg): Likewise. (dwarf2_frame_init_reg): Likewise. (dwarf2_frame_set_signal_frame_p): Likewise. (dwarf2_frame_signal_frame_p): Likewise. (dwarf2_frame_set_adjust_regnum): Likewise. (dwarf2_frame_adjust_regnum): Likewise. (clear_pointer_cleanup): Likewise. (dwarf2_frame_cache): Likewise. (find_cie): Likewise. (dwarf2_frame_find_fde): Likewise. * dwarf2expr.c (dwarf_expr_address_type): Likewise. (free_dwarf_expr_context_cleanup): Likewise. * dwarf2loc.c (locexpr_find_frame_base_location): Likewise. (locexpr_get_frame_base): Likewise. (loclist_find_frame_base_location): Likewise. (loclist_get_frame_base): Likewise. (dwarf_expr_dwarf_call): Likewise. (dwarf_expr_get_base_type): Likewise. (dwarf_expr_push_dwarf_reg_entry_value): Likewise. (dwarf_expr_get_obj_addr): Likewise. (entry_data_value_coerce_ref): Likewise. (entry_data_value_copy_closure): Likewise. (entry_data_value_free_closure): Likewise. (get_frame_address_in_block_wrapper): Likewise. (dwarf2_evaluate_property): Likewise. (dwarf2_compile_property_to_c): Likewise. (needs_frame_read_addr_from_reg): Likewise. (needs_frame_get_reg_value): Likewise. (needs_frame_frame_base): Likewise. (needs_frame_frame_cfa): Likewise. (needs_frame_tls_address): Likewise. (needs_frame_dwarf_call): Likewise. (needs_dwarf_reg_entry_value): Likewise. (get_ax_pc): Likewise. (locexpr_read_variable): Likewise. (locexpr_read_variable_at_entry): Likewise. (locexpr_read_needs_frame): Likewise. (locexpr_describe_location): Likewise. (locexpr_tracepoint_var_ref): Likewise. (locexpr_generate_c_location): Likewise. (loclist_read_variable): Likewise. (loclist_read_variable_at_entry): Likewise. (loclist_describe_location): Likewise. (loclist_tracepoint_var_ref): Likewise. (loclist_generate_c_location): Likewise. * dwarf2read.c (line_header_hash_voidp): Likewise. (line_header_eq_voidp): Likewise. (dwarf2_has_info): Likewise. (dwarf2_get_section_info): Likewise. (locate_dwz_sections): Likewise. (hash_file_name_entry): Likewise. (eq_file_name_entry): Likewise. (delete_file_name_entry): Likewise. (dw2_setup): Likewise. (dw2_get_file_names_reader): Likewise. (dw2_find_pc_sect_compunit_symtab): Likewise. (hash_signatured_type): Likewise. (eq_signatured_type): Likewise. (add_signatured_type_cu_to_table): Likewise. (create_debug_types_hash_table): Likewise. (lookup_dwo_signatured_type): Likewise. (lookup_dwp_signatured_type): Likewise. (lookup_signatured_type): Likewise. (hash_type_unit_group): Likewise. (eq_type_unit_group): Likewise. (get_type_unit_group): Likewise. (process_psymtab_comp_unit_reader): Likewise. (sort_tu_by_abbrev_offset): Likewise. (process_skeletonless_type_unit): Likewise. (psymtabs_addrmap_cleanup): Likewise. (dwarf2_read_symtab): Likewise. (psymtab_to_symtab_1): Likewise. (die_hash): Likewise. (die_eq): Likewise. (load_full_comp_unit_reader): Likewise. (reset_die_in_process): Likewise. (free_cu_line_header): Likewise. (handle_DW_AT_stmt_list): Likewise. (hash_dwo_file): Likewise. (eq_dwo_file): Likewise. (hash_dwo_unit): Likewise. (eq_dwo_unit): Likewise. (create_dwo_cu_reader): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (lookup_dwo_unit_in_dwp): Likewise. (dwarf2_locate_dwo_sections): Likewise. (dwarf2_locate_common_dwp_sections): Likewise. (dwarf2_locate_v2_dwp_sections): Likewise. (hash_dwp_loaded_cutus): Likewise. (eq_dwp_loaded_cutus): Likewise. (lookup_dwo_cutu): Likewise. (abbrev_table_free_cleanup): Likewise. (dwarf2_free_abbrev_table): Likewise. (find_partial_die_in_comp_unit): Likewise. (free_line_header_voidp): Likewise. (follow_die_offset): Likewise. (follow_die_sig_1): Likewise. (free_heap_comp_unit): Likewise. (free_stack_comp_unit): Likewise. (dwarf2_free_objfile): Likewise. (per_cu_offset_and_type_hash): Likewise. (per_cu_offset_and_type_eq): Likewise. (get_die_type_at_offset): Likewise. (partial_die_hash): Likewise. (partial_die_eq): Likewise. (dwarf2_per_objfile_free): Likewise. (hash_strtab_entry): Likewise. (eq_strtab_entry): Likewise. (add_string): Likewise. (hash_symtab_entry): Likewise. (eq_symtab_entry): Likewise. (delete_symtab_entry): Likewise. (cleanup_mapped_symtab): Likewise. (add_indices_to_cpool): Likewise. (hash_psymtab_cu_index): Likewise. (eq_psymtab_cu_index): Likewise. (add_address_entry_worker): Likewise. (unlink_if_set): Likewise. (write_one_signatured_type): Likewise. (save_gdb_index_command): Likewise. * elfread.c (elf_symtab_read): Likewise. (elf_gnu_ifunc_cache_hash): Likewise. (elf_gnu_ifunc_cache_eq): Likewise. (elf_gnu_ifunc_record_cache): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_get_probes): Likewise. (probe_key_free): Likewise. * f-lang.c (builtin_f_type): Likewise. * frame-base.c (frame_base_append_sniffer): Likewise. (frame_base_set_default): Likewise. (frame_base_find_by_frame): Likewise. * frame-unwind.c (frame_unwind_prepend_unwinder): Likewise. (frame_unwind_append_unwinder): Likewise. (frame_unwind_find_by_frame): Likewise. * frame.c (frame_addr_hash): Likewise. (frame_addr_hash_eq): Likewise. (frame_stash_find): Likewise. (do_frame_register_read): Likewise. (unwind_to_current_frame): Likewise. (frame_cleanup_after_sniffer): Likewise. * frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise. * frv-tdep.c (frv_frame_unwind_cache): Likewise. * ft32-tdep.c (ft32_frame_cache): Likewise. * gcore.c (do_bfd_delete_cleanup): Likewise. (gcore_create_callback): Likewise. * gdb_bfd.c (hash_bfd): Likewise. (eq_bfd): Likewise. (gdb_bfd_open): Likewise. (free_one_bfd_section): Likewise. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (get_section_descriptor): Likewise. (gdb_bfd_map_section): Likewise. (gdb_bfd_crc): Likewise. (gdb_bfd_mark_parent): Likewise. (gdb_bfd_record_inclusion): Likewise. (gdb_bfd_requires_relocations): Likewise. (print_one_bfd): Likewise. * gdbtypes.c (type_pair_hash): Likewise. (type_pair_eq): Likewise. (builtin_type): Likewise. (objfile_type): Likewise. * gnu-v3-abi.c (vtable_ptrdiff_type): Likewise. (vtable_address_point_offset): Likewise. (gnuv3_get_vtable): Likewise. (hash_value_and_voffset): Likewise. (eq_value_and_voffset): Likewise. (compare_value_and_voffset): Likewise. (compute_vtable_size): Likewise. (gnuv3_get_typeid_type): Likewise. * go-lang.c (builtin_go_type): Likewise. * guile/scm-block.c (bkscm_hash_block_smob): Likewise. (bkscm_eq_block_smob): Likewise. (bkscm_objfile_block_map): Likewise. (bkscm_del_objfile_blocks): Likewise. * guile/scm-breakpoint.c (bpscm_build_bp_list): Likewise. * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): Likewise. (gdbscm_disasm_print_address): Likewise. * guile/scm-frame.c (frscm_hash_frame_smob): Likewise. (frscm_eq_frame_smob): Likewise. (frscm_inferior_frame_map): Likewise. (frscm_del_inferior_frames): Likewise. * guile/scm-gsmob.c (gdbscm_add_objfile_ref): Likewise. * guile/scm-objfile.c (ofscm_handle_objfile_deleted): Likewise. (ofscm_objfile_smob_from_objfile): Likewise. * guile/scm-ports.c (ioscm_write): Likewise. (ioscm_file_port_delete): Likewise. (ioscm_file_port_rewind): Likewise. (ioscm_file_port_put): Likewise. (ioscm_file_port_write): Likewise. * guile/scm-progspace.c (psscm_handle_pspace_deleted): Likewise. (psscm_pspace_smob_from_pspace): Likewise. * guile/scm-safe-call.c (scscm_recording_pre_unwind_handler): Likewise. (scscm_recording_unwind_handler): Likewise. (gdbscm_with_catch): Likewise. (scscm_call_0_body): Likewise. (scscm_call_1_body): Likewise. (scscm_call_2_body): Likewise. (scscm_call_3_body): Likewise. (scscm_call_4_body): Likewise. (scscm_apply_1_body): Likewise. (scscm_eval_scheme_string): Likewise. (gdbscm_safe_eval_string): Likewise. (scscm_source_scheme_script): Likewise. (gdbscm_safe_source_script): Likewise. * guile/scm-string.c (gdbscm_call_scm_to_stringn): Likewise. (gdbscm_call_scm_from_stringn): Likewise. * guile/scm-symbol.c (syscm_hash_symbol_smob): Likewise. (syscm_eq_symbol_smob): Likewise. (syscm_get_symbol_map): Likewise. (syscm_del_objfile_symbols): Likewise. * guile/scm-symtab.c (stscm_hash_symtab_smob): Likewise. (stscm_eq_symtab_smob): Likewise. (stscm_objfile_symtab_map): Likewise. (stscm_del_objfile_symtabs): Likewise. * guile/scm-type.c (tyscm_hash_type_smob): Likewise. (tyscm_eq_type_smob): Likewise. (tyscm_type_map): Likewise. (tyscm_copy_type_recursive): Likewise. (save_objfile_types): Likewise. * guile/scm-utils.c (extract_arg): Likewise. * h8300-tdep.c (h8300_frame_cache): Likewise. * hppa-linux-tdep.c (hppa_linux_sigtramp_frame_unwind_cache): Likewise. * hppa-tdep.c (compare_unwind_entries): Likewise. (find_unwind_entry): Likewise. (hppa_frame_cache): Likewise. (hppa_stub_frame_unwind_cache): Likewise. * hppanbsd-tdep.c (hppanbsd_supply_gregset): Likewise. * hppaobsd-tdep.c (hppaobsd_supply_gregset): Likewise. (hppaobsd_supply_fpregset): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * i386-tdep.c (i386_frame_cache): Likewise. (i386_epilogue_frame_cache): Likewise. (i386_sigtramp_frame_cache): Likewise. (i386_supply_gregset): Likewise. (i386_collect_gregset): Likewise. (i386_gdbarch_init): Likewise. * i386obsd-tdep.c (i386obsd_aout_supply_regset): Likewise. (i386obsd_trapframe_cache): Likewise. * i387-tdep.c (i387_supply_fsave): Likewise. (i387_collect_fsave): Likewise. (i387_supply_fxsave): Likewise. (i387_collect_fxsave): Likewise. (i387_supply_xsave): Likewise. (i387_collect_xsave): Likewise. * ia64-tdep.c (ia64_frame_cache): Likewise. (ia64_sigtramp_frame_cache): Likewise. * infcmd.c (attach_command_continuation): Likewise. (attach_command_continuation_free_args): Likewise. * inferior.c (restore_inferior): Likewise. (delete_thread_of_inferior): Likewise. * inflow.c (inflow_inferior_data_cleanup): Likewise. (get_inflow_inferior_data): Likewise. (inflow_inferior_exit): Likewise. * infrun.c (displaced_step_clear_cleanup): Likewise. (restore_current_uiout_cleanup): Likewise. (release_stop_context_cleanup): Likewise. (do_restore_infcall_suspend_state_cleanup): Likewise. (do_restore_infcall_control_state_cleanup): Likewise. (restore_inferior_ptid): Likewise. * inline-frame.c (block_starting_point_at): Likewise. * iq2000-tdep.c (iq2000_frame_cache): Likewise. * jit.c (get_jit_objfile_data): Likewise. (get_jit_program_space_data): Likewise. (jit_object_close_impl): Likewise. (jit_find_objf_with_entry_addr): Likewise. (jit_breakpoint_deleted): Likewise. (jit_unwind_reg_set_impl): Likewise. (jit_unwind_reg_get_impl): Likewise. (jit_dealloc_cache): Likewise. (jit_frame_sniffer): Likewise. (jit_frame_prev_register): Likewise. (jit_prepend_unwinder): Likewise. (jit_inferior_exit_hook): Likewise. (free_objfile_data): Likewise. * jv-lang.c (jv_per_objfile_free): Likewise. (get_dynamics_objfile): Likewise. (get_java_class_symtab): Likewise. (builtin_java_type): Likewise. * language.c (language_string_char_type): Likewise. (language_bool_type): Likewise. (language_lookup_primitive_type): Likewise. (language_lookup_primitive_type_as_symbol): Likewise. * linespec.c (hash_address_entry): Likewise. (eq_address_entry): Likewise. (iterate_inline_only): Likewise. (iterate_name_matcher): Likewise. (decode_line_2_compare_items): Likewise. (collect_one_symbol): Likewise. (compare_symbols): Likewise. (compare_msymbols): Likewise. (add_symtabs_to_list): Likewise. (collect_symbols): Likewise. (compare_msyms): Likewise. (add_minsym): Likewise. (cleanup_linespec_result): Likewise. * linux-fork.c (inferior_call_waitpid_cleanup): Likewise. * linux-nat.c (delete_lwp_cleanup): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (resume_stopped_resumed_lwps): Likewise. * linux-tdep.c (get_linux_gdbarch_data): Likewise. (invalidate_linux_cache_inf): Likewise. (get_linux_inferior_data): Likewise. (linux_find_memory_regions_thunk): Likewise. (linux_make_mappings_callback): Likewise. (linux_corefile_thread_callback): Likewise. (find_mapping_size): Likewise. * linux-thread-db.c (find_new_threads_callback): Likewise. * lm32-tdep.c (lm32_frame_cache): Likewise. * m2-lang.c (builtin_m2_type): Likewise. * m32c-tdep.c (m32c_analyze_frame_prologue): Likewise. * m32r-linux-tdep.c (m32r_linux_sigtramp_frame_cache): Likewise. (m32r_linux_supply_gregset): Likewise. (m32r_linux_collect_gregset): Likewise. * m32r-tdep.c (m32r_frame_unwind_cache): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * m68k-tdep.c (m68k_frame_cache): Likewise. * m68kbsd-tdep.c (m68kbsd_supply_fpregset): Likewise. (m68kbsd_supply_gregset): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise. * m88k-tdep.c (m88k_frame_cache): Likewise. (m88k_supply_gregset): Likewise. gdb/gdbserver/ChangeLog: * dll.c (match_dll): Add cast(s). (unloaded_dll): Likewise. * linux-low.c (second_thread_of_pid_p): Likewise. (delete_lwp_callback): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (linux_set_resume_request): Likewise. * server.c (accumulate_file_name_length): Likewise. (emit_dll_description): Likewise. (handle_qxfer_threads_worker): Likewise. (visit_actioned_threads): Likewise. * thread-db.c (any_thread_of): Likewise. * tracepoint.c (same_process_p): Likewise. (match_blocktype): Likewise. (build_traceframe_info_xml): Likewise. gdb/testsuite/ChangeLog: * gdb.gdb/selftest.exp (do_steps_and_nexts): Adjust expected source line.
2015-09-25 20:08:07 +02:00
int *selector = (int *) data;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
gdb_assert (selector != NULL);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Select only resumed LWPs that have an event pending. */
if (lp->resumed && lwp_status_pending_p (lp))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if ((*selector)-- == 0)
return 1;
return 0;
}
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
/* Called when the LWP stopped for a signal/trap. If it stopped for a
trap check what caused it (breakpoint, watchpoint, trace, etc.),
and save the result in the LWP's stop_reason field. If it stopped
for a breakpoint, decrement the PC if necessary on the lwp's
architecture. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
static void
save_stop_reason (struct lwp_info *lp)
{
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
struct regcache *regcache;
struct gdbarch *gdbarch;
CORE_ADDR pc;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
CORE_ADDR sw_bp_pc;
#if USE_SIGTRAP_SIGINFO
siginfo_t siginfo;
#endif
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
gdb_assert (lp->status != 0);
if (!linux_nat_status_is_event (lp->status))
return;
regcache = get_thread_regcache (lp->ptid);
gdbarch = get_regcache_arch (regcache);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
pc = regcache_read_pc (regcache);
sw_bp_pc = pc - gdbarch_decr_pc_after_break (gdbarch);
#if USE_SIGTRAP_SIGINFO
if (linux_nat_get_siginfo (lp->ptid, &siginfo))
{
if (siginfo.si_signo == SIGTRAP)
{
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)
&& GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
{
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
/* The si_code is ambiguous on this arch -- check debug
registers. */
if (!check_stopped_by_watchpoint (lp))
lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
}
else if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
{
/* If we determine the LWP stopped for a SW breakpoint,
trust it. Particularly don't check watchpoint
registers, because at least on s390, we'd find
stopped-by-watchpoint as long as there's a watchpoint
set. */
lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
}
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
else if (GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
{
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
/* This can indicate either a hardware breakpoint or
hardware watchpoint. Check debug registers. */
if (!check_stopped_by_watchpoint (lp))
lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
}
else if (siginfo.si_code == TRAP_TRACE)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"CSBB: %s stopped by trace\n",
target_pid_to_str (lp->ptid));
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
/* We may have single stepped an instruction that
triggered a watchpoint. In that case, on some
architectures (such as x86), instead of TRAP_HWBKPT,
si_code indicates TRAP_TRACE, and we need to check
the debug registers separately. */
check_stopped_by_watchpoint (lp);
}
}
}
#else
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if ((!lp->step || lp->stop_pc == sw_bp_pc)
&& software_breakpoint_inserted_here_p (get_regcache_aspace (regcache),
sw_bp_pc))
{
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* The LWP was either continued, or stepped a software
breakpoint instruction. */
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
}
if (hardware_breakpoint_inserted_here_p (get_regcache_aspace (regcache), pc))
lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
if (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON)
check_stopped_by_watchpoint (lp);
#endif
if (lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"CSBB: %s stopped by software breakpoint\n",
target_pid_to_str (lp->ptid));
/* Back up the PC if necessary. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (pc != sw_bp_pc)
regcache_write_pc (regcache, sw_bp_pc);
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
/* Update this so we record the correct stop PC below. */
pc = sw_bp_pc;
}
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
else if (lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
"CSBB: %s stopped by hardware breakpoint\n",
target_pid_to_str (lp->ptid));
}
else if (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"CSBB: %s stopped by hardware watchpoint\n",
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
target_pid_to_str (lp->ptid));
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
lp->stop_pc = pc;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Returns true if the LWP had stopped for a software breakpoint. */
static int
linux_nat_stopped_by_sw_breakpoint (struct target_ops *ops)
{
struct lwp_info *lp = find_lwp_pid (inferior_ptid);
gdb_assert (lp != NULL);
return lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
}
/* Implement the supports_stopped_by_sw_breakpoint method. */
static int
linux_nat_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
{
return USE_SIGTRAP_SIGINFO;
}
/* Returns true if the LWP had stopped for a hardware
breakpoint/watchpoint. */
static int
linux_nat_stopped_by_hw_breakpoint (struct target_ops *ops)
{
struct lwp_info *lp = find_lwp_pid (inferior_ptid);
gdb_assert (lp != NULL);
return lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
}
/* Implement the supports_stopped_by_hw_breakpoint method. */
static int
linux_nat_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
{
return USE_SIGTRAP_SIGINFO;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Select one LWP out of those that have events pending. */
static void
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
int num_events = 0;
int random_selector;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
struct lwp_info *event_lp = NULL;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Record the wait status for the original LWP. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
(*orig_lp)->status = *status;
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* In all-stop, give preference to the LWP that is being
single-stepped. There will be at most one, and it will be the
LWP that the core is most interested in. If we didn't do this,
then we'd have to handle pending step SIGTRAPs somehow in case
the core later continues the previously-stepped thread, as
otherwise we'd report the pending SIGTRAP then, and the core, not
having stepped the thread, wouldn't understand what the trap was
for, and therefore would report it to the user as a random
signal. */
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
if (!target_is_non_stop_p ())
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
event_lp = iterate_over_lwps (filter,
select_singlestep_lwp_callback, NULL);
if (event_lp != NULL)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"SEL: Select single-step %s\n",
target_pid_to_str (event_lp->ptid));
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (event_lp == NULL)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Pick one at random, out of those which have had events. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* First see how many events we have. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (filter, count_events_callback, &num_events);
gdbserver/Linux: unbreak thread event randomization Wanting to make sure the new continue-pending-status.exp test tests both cases of threads 2 and 3 reporting an event, I added counters to the test, to make it FAIL if events for both threads aren't seen. Assuming a well behaved backend, and given a reasonable number of iterations, it should PASS. However, running that against GNU/Linux gdbserver, I found that surprisingly, that FAILed. GDBserver always reported the breakpoint hit for the same thread. Turns out that I broke gdbserver's thread event randomization recently, with git commit 582511be ([gdbserver] linux-low.c: better starvation avoidance, handle non-stop mode too). In that commit I missed that the thread structure also has a status_pending_p field... The end result was that count_events_callback always returns 0, and then if no thread is stepping, select_event_lwp always returns the event thread. IOW, no randomization is happening at all. Quite curious how all the other changes in that patch were sufficient to fix non-stop-fair-events.exp anyway even with that broken. Tested on x86_64 Fedora 20, native and gdbserver. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (count_events_callback, select_event_lwp_callback): Use the lwp's status_pending_p field, not the thread's. gdb/testsuite/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * gdb.threads/continue-pending-status.exp (saw_thread_2) (saw_thread_3): New globals. (top level): Increment them when an event for the corresponding thread is seen. (no thread starvation): New test.
2015-03-15 20:35:26 +01:00
gdb_assert (num_events > 0);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Now randomly pick a LWP out of those that have had
events. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
random_selector = (int)
((num_events * (double) rand ()) / (RAND_MAX + 1.0));
if (debug_linux_nat && num_events > 1)
fprintf_unfiltered (gdb_stdlog,
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
"SEL: Found %d events, selecting #%d\n",
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
num_events, random_selector);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
event_lp = iterate_over_lwps (filter,
select_event_lwp_callback,
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
&random_selector);
}
if (event_lp != NULL)
{
/* Switch the event LWP. */
*orig_lp = event_lp;
*status = event_lp->status;
}
/* Flush the wait status for the event LWP. */
(*orig_lp)->status = 0;
}
/* Return non-zero if LP has been resumed. */
static int
resumed_callback (struct lwp_info *lp, void *data)
{
return lp->resumed;
}
/* Check if we should go on and pass this event to common code.
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
Return the affected lwp if we are, or NULL otherwise. */
static struct lwp_info *
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
linux_nat_filter_event (int lwpid, int status)
{
struct lwp_info *lp;
int event = linux_ptrace_get_extended_event (status);
lp = find_lwp_pid (pid_to_ptid (lwpid));
/* Check for stop events reported by a process we didn't already
know about - anything not already in our LWP list.
If we're expecting to receive stopped processes after
fork, vfork, and clone events, then we'll just add the
new one to our list and go back to waiting for the event
to be reported - the stopped process might be returned
from waitpid before or after the event is.
But note the case of a non-leader thread exec'ing after the
leader having exited, and gone from our lists. The non-leader
thread changes its tid to the tgid. */
if (WIFSTOPPED (status) && lp == NULL
&& (WSTOPSIG (status) == SIGTRAP && event == PTRACE_EVENT_EXEC))
{
/* A multi-thread exec after we had seen the leader exiting. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: Re-adding thread group leader LWP %d.\n",
lwpid);
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
lp = add_lwp (ptid_build (lwpid, lwpid, 0));
lp->stopped = 1;
lp->resumed = 1;
add_thread (lp->ptid);
}
if (WIFSTOPPED (status) && !lp)
{
linux-nat.c: fix a few lin_lwp_attach_lwp issues This function has a few latent bugs that are triggered by a non-stop mode test that will be added in a subsequent patch. First, as described in the function's intro comment, the function is supposed to return 1 if we're already auto attached to the thread, but haven't processed the PTRACE_EVENT_CLONE event of its parent thread yet. Then, we may find that we're trying to attach to a clone child that hasn't yet stopped for its initial stop, and therefore 'waitpid(..., WNOHANG)' returns 0. In that case, we're currently adding the LWP to the stopped_pids list, which results in linux_handle_extended_wait skipping the waitpid call on the child, and thus confusing things later on when the child eventually reports the stop. Then, the tail end of lin_lwp_attach_lwp always sets the last_resume_kind of the LWP to resume_stop, which is wrong given that the user may be doing "info threads" while some threads are running. And then, the else branch of lin_lwp_attach_lwp always sets the stopped flag of the LWP. This branch is reached if the LWP is the main LWP, which may well be running at this point (to it's wrong to set its 'stopped' flag). AFAICS, there's no reason anymore for special-casing the main/leader LWP here: - For the "attach" case, linux_nat_attach already adds the main LWP to the lwp list, and sets its 'stopped' flag. - For the "run" case, after linux_nat_create_inferior, end up in linux_nat_wait_1 here: /* The first time we get here after starting a new inferior, we may not have added it to the LWP list yet - this is the earliest moment at which we know its PID. */ if (ptid_is_pid (inferior_ptid)) { /* Upgrade the main thread's ptid. */ thread_change_ptid (inferior_ptid, ptid_build (ptid_get_pid (inferior_ptid), ptid_get_pid (inferior_ptid), 0)); lp = add_initial_lwp (inferior_ptid); lp->resumed = 1; } ... which adds the LWP to the LWP list already, before lin_lwp_attach_lwp can ever be reached. gdb/ChangeLog: 2015-02-20 Pedro Alves <palves@redhat.com> * linux-nat.c (lin_lwp_attach_lwp): No longer special case the main LWP. Handle the case of waitpid returning 0 if we're already attached to the LWP. Don't set the LWP's last_resume_kind to resume_stop if we already knew about the LWP. (linux_nat_filter_event): Add debug logs.
2015-02-20 21:21:59 +01:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LHEW: saving LWP %ld status %s in stopped_pids list\n",
(long) lwpid, status_to_str (status));
add_to_pid_list (&stopped_pids, lwpid, status);
return NULL;
}
/* Make sure we don't report an event for the exit of an LWP not in
our list, i.e. not part of the current process. This can happen
if we detach from a program we originally forked and then it
exits. */
if (!WIFSTOPPED (status) && !lp)
return NULL;
PR gdb/15713 - errors from i386_linux_resume lead to lock-up linux_nat_resume is not considering that linux_ops->to_resume may throw: /* Mark LWP as not stopped to prevent it from being continued by linux_nat_resume_callback. */ lp->stopped = 0; if (resume_many) iterate_over_lwps (ptid, linux_nat_resume_callback, NULL); If something within linux_nat_resume_callback throws, GDB leaves the lwp_info as if the inferior was resumed, while it actually wasn't. A couple examples, there are possibly others: - i386_linux_resume calls target_read which calls QUIT. - if the actual ptrace resumption fails in inf_ptrace_resume, perror_with_name is called. If the user tries to kill the inferior at this point (or quit, which offers to kill), GDB locks up trying to stop the lwp -- if it is already stopped no new waitpid event gets generated for it. Fix this by setting the stopped flag earlier, as soon as we collect a stop event with waitpid, and clearing it always only after resuming the lwp successfully. Tested on x86_64 Fedora 20. Confirmed the lock-up disappears using a local hack that forces an error in inf_ptrace_resume. Also fixes a little "set debug lin-lwp" annoyance. Currently we always see: Continuing. LLR: Preparing to resume process 6802, 0, inferior_ptid Thread 0x7ffff7fc7740 (LWP 6802) ^^^^^^^^ RC: Resuming sibling Thread 0x7ffff77c5700 (LWP 6807), 0, resume RC: Resuming sibling Thread 0x7ffff7fc6700 (LWP 6806), 0, resume RC: Not resuming sibling Thread 0x7ffff7fc7740 (LWP 6802) (not stopped) ^^^^^^^^^^^^^^^^^^^^^^^ LLR: PTRACE_CONT process 6802, 0 (resume event thread) This patch gets rid of the "Not resuming sibling" line. 2014-05-29 Pedro Alves <palves@redhat.com> PR gdb/15713 * linux-nat.c (linux_nat_resume_callback): Rename the second parameter to 'except'. Skip LP if it points to EXCEPT. (linux_nat_resume): Don't mark the event lwp as not stopped before resuming sibling lwps. Instead ask linux_nat_resume_callback to skip the event lwp. Mark it as not stopped after actually resuming it. (linux_handle_syscall_trap): Mark the lwp as not stopped after resuming it. (wait_lwp): Mark the lwp as stopped here. (stop_wait_callback): Mark the lwp as not stopped right after resuming it. Don't mark lwps as stopped here. (linux_nat_filter_event): Mark the lwp as stopped earlier. (linux_nat_wait_1): Don't mark dead lwps as stopped here.
2014-05-29 13:50:48 +02:00
/* This LWP is stopped now. (And if dead, this prevents it from
ever being continued.) */
lp->stopped = 1;
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
if (WIFSTOPPED (status) && lp->must_set_ptrace_flags)
{
struct inferior *inf = find_inferior_pid (ptid_get_pid (lp->ptid));
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
int options = linux_nat_ptrace_options (inf->attach_flag);
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
Extended-remote Linux follow fork This patch implements basic support for follow-fork and detach-on-fork on extended-remote Linux targets. Only 'fork' is supported in this patch; 'vfork' support is added n a subsequent patch. This patch depends on the previous patches in the patch series. Sufficient extended-remote functionality has been implemented here to pass gdb.base/multi-forks.exp, as well as gdb.base/foll-fork.exp with the catchpoint tests commented out. Some other fork tests fail with this patch because it doesn't provide the architecture support needed for watchpoint inheritance or fork catchpoints. The implementation follows the same general structure as for the native implementation as much as possible. This implementation includes: * enabling fork events in linux-low.c in initialize_low and linux_enable_extended_features * handling fork events in gdbserver/linux-low.c:handle_extended_wait - when a fork event occurs in gdbserver, we must do the full creation of the new process, thread, lwp, and breakpoint lists. This is required whether or not the new child is destined to be detached-on-fork, because GDB will make target calls that require all the structures. In particular we need the breakpoint lists in order to remove the breakpoints from a detaching child. If we are not detaching the child we will need all these structures anyway. - as part of this event handling we store the target_waitstatus in a new member of the parent lwp_info structure, 'waitstatus'. This is used to store extended event information for reporting to GDB. - handle_extended_wait is given a return value, denoting whether the handled event should be reported to GDB. Previously it had only handled clone events, which were never reported. * using a new predicate in gdbserver to control handling of the fork event (and eventually all extended events) in linux_wait_1. The predicate, extended_event_reported, checks a target_waitstatus.kind for an extended ptrace event. * implementing a new RSP 'T' Stop Reply Packet stop reason: "fork", in gdbserver/remote-utils.c and remote.c. * implementing new target and RSP support for target_follow_fork with target extended-remote. (The RSP components were actually defined in patch 1, but they see their first use here). - remote target routine remote_follow_fork, which just sends the 'D;pid' detach packet to detach the new fork child cleanly. We can't just call target_detach because the data structures for the forked child have not been allocated on the host side. Tested on x64 Ubuntu Lucid, native, remote, extended-remote. gdb/gdbserver/ChangeLog: * linux-low.c (handle_extended_wait): Implement return value, rename argument 'event_child' to 'event_lwp', handle PTRACE_EVENT_FORK, call internal_error for unrecognized event. (linux_low_ptrace_options): New function. (linux_low_filter_event): Call linux_low_ptrace_options, use different argument fo linux_enable_event_reporting, use return value from handle_extended_wait. (extended_event_reported): New function. (linux_wait_1): Call extended_event_reported and set status to report fork events. (linux_write_memory): Add pid to debug message. (reset_lwp_ptrace_options_callback): New function. (linux_handle_new_gdb_connection): New function. (linux_target_ops): Initialize new structure member. * linux-low.h (struct lwp_info) <waitstatus>: New member. * lynx-low.c: Initialize new structure member. * remote-utils.c (prepare_resume_reply): Implement stop reason "fork" for "T" stop message. * server.c (handle_query): Call handle_new_gdb_connection. * server.h (report_fork_events): Declare global flag. * target.h (struct target_ops) <handle_new_gdb_connection>: New member. (target_handle_new_gdb_connection): New macro. * win32-low.c: Initialize new structure member. gdb/ChangeLog: * linux-nat.c (linux_nat_ptrace_options): New function. (linux_init_ptrace, wait_lwp, linux_nat_filter_event): Call linux_nat_ptrace_options and use different argument to linux_enable_event_reporting. (_initialize_linux_nat): Delete call to linux_ptrace_set_additional_flags. * nat/linux-ptrace.c (current_ptrace_options): Rename to supported_ptrace_options. (additional_flags): Delete variable. (linux_check_ptrace_features): Use supported_ptrace_options. (linux_test_for_tracesysgood, linux_test_for_tracefork): Likewise, and remove additional_flags check. (linux_enable_event_reporting): Change 'attached' argument to 'options'. Use supported_ptrace_options. (ptrace_supports_feature): Change comment. Use supported_ptrace_options. (linux_ptrace_set_additional_flags): Delete function. * nat/linux-ptrace.h (linux_ptrace_set_additional_flags): Delete function prototype. * remote.c (remote_fork_event_p): New function. (remote_detach_pid): New function. (remote_detach_1): Call remote_detach_pid, don't mourn inferior if doing detach-on-fork. (remote_follow_fork): New function. (remote_parse_stop_reply): Handle new "T" stop reason "fork". (remote_pid_to_str): Print "process" strings for pid/0/0 ptids. (init_extended_remote_ops): Initialize to_follow_fork.
2015-05-12 18:52:43 +02:00
linux_enable_event_reporting (ptid_get_lwp (lp->ptid), options);
Linux: on attach, attach to lwps listed under /proc/$pid/task/ ... instead of relying on libthread_db. I wrote a test that attaches to a program that constantly spawns short-lived threads, which exposed several issues. This is one of them. On Linux, we need to attach to all threads of a process (thread group) individually. We currently rely on libthread_db to list the threads, but that is problematic, because libthread_db relies on reading data structures out of the inferior (which may well be corrupted). If threads are being created or exiting just while we try to attach, we may trip on inconsistencies in the inferior's thread list. To work around that, when we see a seemingly corrupt list, we currently retry a few times: static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new) { ... if (until_no_new) { /* Require 4 successive iterations which do not find any new threads. The 4 is a heuristic: there is an inherent race here, and I have seen that 2 iterations in a row are not always sufficient to "capture" all threads. */ ... That heuristic may well fail, and when it does, we end up with threads in the program that aren't under GDB's control. That's obviously bad and results in quite mistifying failures, like e.g., the process dying for seeminly no reason when a thread that wasn't attached trips on a breakpoint. There's really no reason to rely on libthread_db for this nowadays when we have /proc mounted. In that case, which is the usual case, we can list the LWPs from /proc/PID/task/. In fact, GDBserver is already doing this. The patch factors out that code that knows to walk the task/ directory out of GDBserver, and makes GDB use it too. Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for them to stop immediately. Instead, we just tag the LWP as having an expected stop. Because we can only set the ptrace options when the thread stops, we need a new flag in the lwp structure to keep track of whether we've already set the ptrace options, just like in GDBserver. Note that nothing issues any ptrace command to the threads between the PTRACE_ATTACH and the stop, so this is safe (unlike one scenario described in gdbserver's linux-low.c). When we attach to a program that has threads exiting while we attach, it's easy to race with a thread just exiting as we try to attach to it, like: #1 - get current list of threads #2 - attach to each listed thread #3 - ooops, attach failed, thread is already gone As this is pretty normal, we shouldn't be issuing a scary warning in step #3. When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes we'll see EPERM as well. That happens when the kernel still has the thread in its task list, but the thread is marked as dead. Unfortunately, EPERM is ambiguous and we'll get it also on other scenarios where the thread isn't dead, and in those cases, it's useful to get a warning. To distiguish the cases, when we get an EPERM failure, we open /proc/PID/status, and check the thread's state -- if the /proc file no longer exists, or the state is "Z (Zombie)" or "X (Dead)", we ignore the EPERM error silently; otherwise, we'll warn. Unfortunately, there seems to be a kernel race here. Sometimes I get EPERM, and then the /proc state still indicates "R (Running)"... If we wait a bit and retry, we do end up seeing X or Z state, or get an ESRCH. I thought of making GDB retry the attach a few times, but even with a 500ms wait and 4 retries, I still see the warning sometimes. I haven't been able to identify the kernel path that causes this yet, but in any case, it looks like a kernel bug to me. As this just results failure to suppress a warning that we've been printing since about forever anyway, I'm just making the test cope with it, and issue an XFAIL. gdb/gdbserver/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-low.c (linux_attach_fail_reason_string): Move to nat/linux-ptrace.c, and rename. (linux_attach_lwp): Update comment. (attach_proc_task_lwp_callback): New function. (linux_attach): Adjust to rename and use linux_proc_attach_tgid_threads. (linux_attach_fail_reason_string): Delete declaration. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * linux-nat.c (attach_proc_task_lwp_callback): New function. (linux_nat_attach): Use linux_proc_attach_tgid_threads. (wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's ptrace option flags. * linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New field. * nat/linux-procfs.c: Include <dirent.h>. (linux_proc_get_int): New parameter "warn". Handle it. (linux_proc_get_tgid): Adjust. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this. (linux_proc_pid_get_state): New function, factored out from (linux_proc_pid_has_state): ... this. Add new parameter "warn" and handle it. (linux_proc_pid_is_gone): New function. (linux_proc_pid_is_stopped): Adjust. (linux_proc_pid_is_zombie_maybe_warn) (linux_proc_pid_is_zombie_nowarn): New functions. (linux_proc_pid_is_zombie): Use linux_proc_pid_is_zombie_maybe_warn. (linux_proc_attach_tgid_threads): New function. * nat/linux-procfs.h (linux_proc_get_tgid): Update comment. (linux_proc_get_tracerpid): Rename to ... (linux_proc_get_tracerpid_nowarn): ... this, and update comment. (linux_proc_pid_is_gone): New declaration. (linux_proc_pid_is_zombie): Update comment. (linux_proc_pid_is_zombie_nowarn): New declaration. (linux_proc_attach_lwp_func): New typedef. (linux_proc_attach_tgid_threads): New declaration. * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to use nowarn functions. (linux_ptrace_attach_fail_reason_string): Move here from gdbserver/linux-low.c and rename. (ptrace_supports_feature): If the current ptrace options are not known yet, check them now, instead of asserting. * nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string): Declare.
2014-12-16 17:12:24 +01:00
lp->must_set_ptrace_flags = 0;
}
/* Handle GNU/Linux's syscall SIGTRAPs. */
if (WIFSTOPPED (status) && WSTOPSIG (status) == SYSCALL_SIGTRAP)
{
/* No longer need the sysgood bit. The ptrace event ends up
recorded in lp->waitstatus if we care for it. We can carry
on handling the event like a regular SIGTRAP from here
on. */
status = W_STOPCODE (SIGTRAP);
if (linux_handle_syscall_trap (lp, 0))
return NULL;
}
gdb: Improve syscall entry/return tracking on Linux The existing logic was simply to flip syscall entry/return state when a syscall trap was seen, and even then only with active 'catch syscall'. That can get out of sync if 'catch syscall' is toggled at odd times. This patch updates the entry/return state for all syscall traps, regardless of catching state, and also updates known syscall state for other kinds of traps. Almost all PTRACE_EVENT stops are delivered from the middle of a syscall, so this can act like an entry. Every other kind of ptrace stop is only delivered outside of syscall event pairs, so marking them ignored ensures the next syscall trap looks like an entry. Three new test scenarios are added to catch-syscall.exp: - Disable 'catch syscall' from an entry to deliberately miss the return event, then re-enable to make sure a new entry is recognized. - Enable 'catch syscall' for the first time from a vfork event, which is a PTRACE_EVENT_VFORK in the middle of the syscall. Make sure the next syscall event is recognized as the return. - Make sure entry and return are recognized for an ENOSYS syscall. This is to defeat a common x86 hack that uses the pre-filled ENOSYS return value as a sign of being on the entry side. gdb/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * linux-nat.c (linux_handle_syscall_trap): Always update entry/ return state, even when not actively catching syscalls at all. (linux_handle_extended_wait): Mark syscall_state like an entry. (wait_lwp): Set syscall_state ignored for other traps. (linux_nat_filter_event): Likewise. gdb/testsuite/ChangeLog: 2015-10-19 Josh Stone <jistone@redhat.com> * gdb.base/catch-syscall.c: Include <sched.h>. (unknown_syscall): New variable. (main): Trigger a vfork and an unknown syscall. * gdb.base/catch-syscall.exp (vfork_syscalls): New variable. (unknown_syscall_number): Likewise. (check_call_to_syscall): Accept an optional syscall pattern. (check_return_from_syscall): Likewise. (check_continue): Likewise. (test_catch_syscall_without_args): Check for vfork and ENOSYS. (test_catch_syscall_skipping_return): New test toggling off 'catch syscall' to step over the syscall return, then toggling back on. (test_catch_syscall_mid_vfork): New test turning on 'catch syscall' during a PTRACE_EVENT_VFORK stop, in the middle of a vfork syscall. (do_syscall_tests): Call test_catch_syscall_without_args and test_catch_syscall_mid_vfork. (test_catch_syscall_without_args_noxml): Check for vfork and ENOSYS. (fill_all_syscalls_numbers): Initialize unknown_syscall_number.
2015-10-20 02:59:38 +02:00
else
{
/* Almost all other ptrace-stops are known to be outside of system
calls, with further exceptions in linux_handle_extended_wait. */
lp->syscall_state = TARGET_WAITKIND_IGNORE;
}
/* Handle GNU/Linux's extended waitstatus for trace events. */
if (WIFSTOPPED (status) && WSTOPSIG (status) == SIGTRAP
&& linux_is_extended_waitstatus (status))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: Handling extended status 0x%06x\n",
status);
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
if (linux_handle_extended_wait (lp, status))
return NULL;
}
/* Check if the thread has exited. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (WIFEXITED (status) || WIFSIGNALED (status))
{
if (!report_thread_events
&& num_lwps (ptid_get_pid (lp->ptid)) > 1)
{
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: %s exited.\n",
target_pid_to_str (lp->ptid));
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
/* If there is at least one more LWP, then the exit signal
was not the end of the debugged application and should be
ignored. */
exit_lwp (lp);
return NULL;
}
/* Note that even if the leader was ptrace-stopped, it can still
exit, if e.g., some other thread brings down the whole
process (calls `exit'). So don't assert that the lwp is
resumed. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LWP %ld exited (resumed=%d)\n",
ptid_get_lwp (lp->ptid), lp->resumed);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Dead LWP's aren't expected to reported a pending sigstop. */
lp->signalled = 0;
/* Store the pending event in the waitstatus, because
W_EXITCODE(0,0) == 0. */
store_waitstatus (&lp->waitstatus, status);
return lp;
}
/* Make sure we don't report a SIGSTOP that we sent ourselves in
an attempt to stop an LWP. */
if (lp->signalled
&& WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP)
{
lp->signalled = 0;
if (lp->last_resume_kind == resume_stop)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: resume_stop SIGSTOP caught for %s.\n",
target_pid_to_str (lp->ptid));
}
else
{
/* This is a delayed SIGSTOP. Filter out the event. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: %s %s, 0, 0 (discard delayed SIGSTOP)\n",
lp->step ?
"PTRACE_SINGLESTEP" : "PTRACE_CONT",
target_pid_to_str (lp->ptid));
linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
gdb_assert (lp->resumed);
return NULL;
}
}
/* Make sure we don't report a SIGINT that we have already displayed
for another thread. */
if (lp->ignore_sigint
&& WIFSTOPPED (status) && WSTOPSIG (status) == SIGINT)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: Delayed SIGINT caught for %s.\n",
target_pid_to_str (lp->ptid));
/* This is a delayed SIGINT. */
lp->ignore_sigint = 0;
linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0);
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: %s %s, 0, 0 (discard SIGINT)\n",
lp->step ?
"PTRACE_SINGLESTEP" : "PTRACE_CONT",
target_pid_to_str (lp->ptid));
gdb_assert (lp->resumed);
/* Discard the event. */
return NULL;
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* Don't report signals that GDB isn't interested in, such as
signals that are neither printed nor stopped upon. Stopping all
threads can be a bit time-consuming so if we want decent
performance with heavily multi-threaded programs, especially when
they're using a high frequency timer, we'd better avoid it if we
can. */
if (WIFSTOPPED (status))
{
enum gdb_signal signo = gdb_signal_from_host (WSTOPSIG (status));
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
if (!target_is_non_stop_p ())
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
/* Only do the below in all-stop, as we currently use SIGSTOP
to implement target_stop (see linux_nat_stop) in
non-stop. */
if (signo == GDB_SIGNAL_INT && signal_pass_state (signo) == 0)
{
/* If ^C/BREAK is typed at the tty/console, SIGINT gets
forwarded to the entire process group, that is, all LWPs
will receive it - unless they're using CLONE_THREAD to
share signals. Since we only want to report it once, we
mark it as ignored for all LWPs except this one. */
iterate_over_lwps (pid_to_ptid (ptid_get_pid (lp->ptid)),
set_ignore_sigint, NULL);
lp->ignore_sigint = 0;
}
else
maybe_clear_ignore_sigint (lp);
}
/* When using hardware single-step, we need to report every signal.
2015-02-12 20:55:08 +01:00
Otherwise, signals in pass_mask may be short-circuited
except signals that might be caused by a breakpoint. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (!lp->step
2015-02-12 20:55:08 +01:00
&& WSTOPSIG (status) && sigismember (&pass_mask, WSTOPSIG (status))
&& !linux_wstatus_maybe_breakpoint (status))
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
linux_resume_one_lwp (lp, lp->step, signo);
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: %s %s, %s (preempt 'handle')\n",
lp->step ?
"PTRACE_SINGLESTEP" : "PTRACE_CONT",
target_pid_to_str (lp->ptid),
(signo != GDB_SIGNAL_0
? strsignal (gdb_signal_to_host (signo))
: "0"));
return NULL;
}
}
/* An interesting event. */
gdb_assert (lp);
lp->status = status;
Handle MIPS Linux SIGTRAP siginfo.si_code values This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
2016-02-24 23:52:06 +01:00
save_stop_reason (lp);
return lp;
}
/* Detect zombie thread group leaders, and "exit" them. We can't reap
their exits until all other threads in the group have exited. */
static void
check_zombie_leaders (void)
{
struct inferior *inf;
ALL_INFERIORS (inf)
{
struct lwp_info *leader_lp;
if (inf->pid == 0)
continue;
leader_lp = find_lwp_pid (pid_to_ptid (inf->pid));
if (leader_lp != NULL
/* Check if there are other threads in the group, as we may
have raced with the inferior simply exiting. */
&& num_lwps (inf->pid) > 1
&& linux_proc_pid_is_zombie (inf->pid))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"CZL: Thread group leader %d zombie "
"(it exited, or another thread execd).\n",
inf->pid);
/* A leader zombie can mean one of two things:
- It exited, and there's an exit status pending
available, or only the leader exited (not the whole
program). In the latter case, we can't waitpid the
leader's exit status until all other threads are gone.
- There are 3 or more threads in the group, and a thread
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
other than the leader exec'd. See comments on exec
events at the top of the file. We could try
distinguishing the exit and exec cases, by waiting once
more, and seeing if something comes out, but it doesn't
sound useful. The previous leader _does_ go away, and
we'll re-add the new one once we see the exec event
(which is just the same as what would happen if the
previous leader did exit voluntarily before some other
thread execs). */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"CZL: Thread group leader %d vanished.\n",
inf->pid);
exit_lwp (leader_lp);
}
}
}
/* Convenience function that is called when the kernel reports an exit
event. This decides whether to report the event to GDB as a
process exit event, a thread exit event, or to suppress the
event. */
static ptid_t
filter_exit_event (struct lwp_info *event_child,
struct target_waitstatus *ourstatus)
{
ptid_t ptid = event_child->ptid;
if (num_lwps (ptid_get_pid (ptid)) > 1)
{
if (report_thread_events)
ourstatus->kind = TARGET_WAITKIND_THREAD_EXITED;
else
ourstatus->kind = TARGET_WAITKIND_IGNORE;
exit_lwp (event_child);
}
return ptid;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static ptid_t
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
linux_nat_wait_1 (struct target_ops *ops,
* target.h (TARGET_WNOHANG): New. * target.c (target_wait): Add `options' argument. Adjust. (struct target_ops) <to_wait>: Add `options' argument. (target_wait): Add `options' argument. * infrun.c (wait_for_inferior): Pass 0 as options to target_wait (blocking wait). (fetch_inferior_event): Pass TARGET_WNOHANG as options to target_wait. * fork-child.c (startup_inferior): Pass 0 as options to target_wait (blocking wait). * linux-nat.c (linux_nat_create_inferior): Remove async masking. (linux_nat_wait_1): Add `target_options' argument. Use it instead of checking on target_can_async_p. (linux_nat_wait): Add `target_options' argument. Adjust. * remote.c (remote_wait_ns): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. (remote_wait_as): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. If doing a blocking wait, keep waiting until an interesting event comes out. (remote_wait): Add `options' argument. Don't loop here if the target is in async mode, and a blocking wait has been requested. * top.c (deprecated_target_wait_hook): Add `options' argument. * linux-thread-db.c (thread_db_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ptrace.c (inf_ptrace_wait): Add `options' argument. * record.c (record_beneath_to_wait): Add `options' argument. (record_wait): Add `options' argument, and pass it down to the layer beneath. * bsd-uthread.c (bsd_uthread_wait): Add `options' argument. * darwin-nat.c (darwin_wait): Likewise. * defs.h (deprecated_target_wait_hook): Likewise. * gnu-nat.c (gnu_wait): Add `options' argument. * go32-nat.c (go32_wait): Likewise. * hpux-thread.c (hpux_thread_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ttrace.c (inf_ttrace_wait): Add `options' argument. * monitor.c (monitor_wait): Likewise. * nto-procfs.c (procfs_wait): Likewise. * remote-mips.c (mips_wait): Add `options' argument. * remote-sim.c (gdbsim_wait): Likewise. * rs6000-nat.c (rs6000_wait): Add `options' argument. * sol-thread.c (sol_thread_wait): Add `options' argument, and pass it down to the layer beneath. * spu-linux-nat.c (spu_child_wait): Add `options' argument. * windows-nat.c (windows_wait): Likewise. * tui/tui-hooks.c (tui_target_wait_hook): Likewise. Adjust.
2009-05-21 17:48:42 +02:00
ptid_t ptid, struct target_waitstatus *ourstatus,
int target_options)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
sigset_t prev_mask;
enum resume_kind last_resume_kind;
struct lwp_info *lp;
int status;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
fprintf_unfiltered (gdb_stdlog, "LLW: enter\n");
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
/* The first time we get here after starting a new inferior, we may
not have added it to the LWP list yet - this is the earliest
moment at which we know its PID. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (ptid_is_pid (inferior_ptid))
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
{
/* Upgrade the main thread's ptid. */
thread_change_ptid (inferior_ptid,
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
ptid_build (ptid_get_pid (inferior_ptid),
ptid_get_pid (inferior_ptid), 0));
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
lp = add_initial_lwp (inferior_ptid);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
lp->resumed = 1;
}
linux-nat.c: no need to block child signals so aggressively. In http://sourceware.org/ml/gdb-patches/2013-08/msg00174.html , the issue of child signal handling around ptrace option support discovery being different between GDB and GDBserver came up. I recalled adding these block_child_signals calls, and the "We don't want those ptrace calls to be interrupted" comment, but not exactly why. So I looked into it. My first guess is that I got confused. The patch that added this <http://sourceware.org/ml/gdb-patches/2009-04/msg00125.html> rewrote the linux native async support completely, and the old async support code had the SIGCHLD handler itself do waitpid, so in places that we'd want a blocking waitpid, we'd have to have the signal handler blocked. That was probably the mindset I had at the time. Anyway, whatever the case, looks like I was wrong on the need for this blocking. Given GDBserver doesn't block like this, I investigated why this is currently needed on GDB but not on GDBserver. I removed the block_child_signals (and restore) calls, and hacked linux-nat.c to call linux_test_for_tracefork in a loop, like: @@ -534,7 +534,10 @@ static int linux_supports_tracefork (int pid) { if (linux_supports_tracefork_flag == -1) - linux_test_for_tracefork (pid); + { + while (1) + linux_test_for_tracefork (pid); + } return linux_supports_tracefork_flag; } Running the resulting GDB, I then saw bad things happening. Specifically, I'd end up with a bunch of zombies, and eventually, the machine would refuse to spawn new processes, claming insufficient resources. The issue is that linux_test_for_tracefork test forks, and has the child fork again. If we don't block SIGCHLD on entry to the function, the children will inherit SIGCHLD's action/disposition (meaning, SIGCHLD will be unblocked in the child). When the first child forks again a second child, and that child exits, the first child gets a SIGCHLD. Now, when we try to wrap up for the whole options test, we kill the first child, and collect the waitstatus. Here, when SIGCHLD isn't blocked, GDB will first see the child reporting a stop with SIGCHLD. gdbserver's ptrace options test does a PTRACE_KILL loop at the end, which catches the SIGCHLD, and retries the kill. The GDB version did not do that. So the GDB version would proceed, leaving the child zombie (until GDB exists), as nothing collected its final waitstatus. So this patch makes the GDB version of linux_test_for_tracefork do the exact same as the GDBserver version, removes all this unnecessary blocking throughout, and adds a couple comments at places that do need it -- namely: places where we'll use sleep with sigsuspend; and linux_async_pipe, as that destroys the pipe the signal handler touches. Tested on x86_64 Fedora 17, sync and async. gdb/ 2013-08-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_test_for_tracefork) (linux_test_for_tracesysgood, linux_child_follow_fork) (lin_lwp_attach_lwp, linux_nat_resume): Don't block child signals. (linux_nat_wait_1): Extend comment. (linux_async_pipe): Add comment.
2013-08-19 15:44:41 +02:00
/* Make sure SIGCHLD is blocked until the sigsuspend below. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
block_child_signals (&prev_mask);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* First check if there is a LWP with a wait status pending. */
lp = iterate_over_lwps (ptid, status_callback, NULL);
if (lp != NULL)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: Using pending wait status %s for %s.\n",
status_to_str (lp->status),
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
target_pid_to_str (lp->ptid));
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* But if we don't find a pending event, we'll have to wait. Always
pull all events out of the kernel. We'll randomly select an
event LWP out of all that have events, to prevent starvation. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
while (lp == NULL)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
pid_t lwpid;
/* Always use -1 and WNOHANG, due to couple of a kernel/ptrace
quirks:
- If the thread group leader exits while other threads in the
thread group still exist, waitpid(TGID, ...) hangs. That
waitpid won't return an exit status until the other threads
in the group are reapped.
- When a non-leader thread execs, that thread just vanishes
without reporting an exit (so we'd hang if we waited for it
explicitly in that case). The exec event is reported to
the TGID pid. */
errno = 0;
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
lwpid = my_waitpid (-1, &status, __WALL | WNOHANG);
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LNW: waitpid(-1, ...) returned %d, %s\n",
lwpid, errno ? safe_strerror (errno) : "ERRNO-OK");
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (lwpid > 0)
{
if (debug_linux_nat)
{
fprintf_unfiltered (gdb_stdlog,
"LLW: waitpid %ld received %s\n",
(long) lwpid, status_to_str (status));
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
linux_nat_filter_event (lwpid, status);
/* Retry until nothing comes out of waitpid. A single
SIGCHLD can indicate more than one child stopped. */
continue;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
Linux: don't resume new LWPs until we've pulled all events out of the kernel Since the starvation avoidance series (https://sourceware.org/ml/gdb-patches/2014-12/msg00631.html), both GDB and GDBserver pull all events out of ptrace before deciding which event to process. There's one problem with that though. Because we resume new threads immediately when we see a PTRACE_EVENT_CLONE event, if the program constantly spawns threads fast enough, new threads can spawn threads faster we can pull events out of the kernel, and thus we'd get stuck in an infinite loop, never returning any event to the core to process. I occasionally see this happen with the attach-many-short-lived-threads.exp test against gdbserver. The fix is to delay resuming new threads until we've pulled out all events out of the kernel. On native, we already have the resume_stopped_resumed_lwps function that knows to resume LWPs that are stopped with no event to report to the core. So the patch just adds another use. GDBserver didn't have the equivalent yet, so the patch adds one. Tested on x86_64 Fedora 20, native and gdbserver (remote and extended-remote). gdb/gdbserver/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-low.c (handle_extended_wait): Don't resume LWPs here. (resume_stopped_resumed_lwps): New function. (linux_wait_for_event_filtered): Use it. gdb/ChangeLog: 2015-02-04 Pedro Alves <palves@redhat.com> * linux-nat.c (handle_extended_wait): Don't resume LWPs here. (wait_lwp): Don't call wait_lwp if linux_handle_extended_wait returns true. (resume_stopped_resumed_lwps): Don't check whether the thread is marked as executing. (linux_nat_wait_1): Use resume_stopped_resumed_lwps.
2015-02-04 19:13:28 +01:00
/* Now that we've pulled all events out of the kernel, resume
LWPs that don't have an interesting event to report. */
iterate_over_lwps (minus_one_ptid,
resume_stopped_resumed_lwps, &minus_one_ptid);
/* ... and find an LWP with a status to report to the core, if
any. */
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
lp = iterate_over_lwps (ptid, status_callback, NULL);
if (lp != NULL)
break;
/* Check for zombie thread group leaders. Those can't be reaped
until all other threads in the thread group are. */
check_zombie_leaders ();
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* If there are no resumed children left, bail. We'd be stuck
forever in the sigsuspend call below otherwise. */
if (iterate_over_lwps (ptid, resumed_callback, NULL) == NULL)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "LLW: exit (no resumed LWP)\n");
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
ourstatus->kind = TARGET_WAITKIND_NO_RESUMED;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
restore_child_signals_mask (&prev_mask);
return minus_one_ptid;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* No interesting event to report to the core. */
if (target_options & TARGET_WNOHANG)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "LLW: exit (ignore)\n");
ourstatus->kind = TARGET_WAITKIND_IGNORE;
restore_child_signals_mask (&prev_mask);
return minus_one_ptid;
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* We shouldn't end up here unless we want to try again. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
gdb_assert (lp == NULL);
/* Block until we get an event reported with SIGCHLD. */
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "LNW: about to sigsuspend\n");
sigsuspend (&suspend_mask);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
gdb_assert (lp);
status = lp->status;
lp->status = 0;
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
if (!target_is_non_stop_p ())
{
/* Now stop all other LWP's ... */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (minus_one_ptid, stop_callback, NULL);
/* ... and wait until all of them have reported back that
they're no longer running. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (minus_one_ptid, stop_wait_callback, NULL);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
}
/* If we're not waiting for a specific LWP, choose an event LWP from
among those that have had events. Giving equal priority to all
LWPs that have had events helps prevent starvation. */
if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
select_event_lwp (ptid, &lp, &status);
gdb_assert (lp != NULL);
/* Now that we've selected our final event LWP, un-adjust its PC if
it was a software breakpoint, and we can't reliably support the
"stopped by software breakpoint" stop reason. */
if (lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT
&& !USE_SIGTRAP_SIGINFO)
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
struct regcache *regcache = get_thread_regcache (lp->ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
int decr_pc = gdbarch_decr_pc_after_break (gdbarch);
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
if (decr_pc != 0)
{
CORE_ADDR pc;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
pc = regcache_read_pc (regcache);
regcache_write_pc (regcache, pc + decr_pc);
}
}
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
/* We'll need this to determine whether to report a SIGSTOP as
GDB_SIGNAL_0. Need to take a copy because resume_clear_callback
clears it. */
last_resume_kind = lp->last_resume_kind;
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
if (!target_is_non_stop_p ())
linux-nat.c: better starvation avoidance, handle non-stop mode too Running the testsuite with a series that reimplements user-visible all-stop behavior on top of a target running in non-stop mode revealed problems related to event starvation avoidance. For example, I see gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing. What happens is that GDB core never gets to see the signal event. It ends up processing the events for the same threads over an over, because Linux's waitpid(-1, ...) returns that first task in the task list that has an event, starving threads on the tail of the task list. So I wrote a non-stop mode test originally inspired by signal-while-stepping-over-bp-other-thread.exp, to stress this independently of all-stop on top of non-stop. Fixing it required the changes described below. The test will be added in a following commit. 1) linux-nat.c has code in place that picks an event LWP at random out of all that have had events. This is because on the kernel side, "waitpid(-1, ...)" just walks the task list linearly looking for the first that had an event. But, this code is currently only used in all-stop mode. So with a multi-threaded program that has multiple events triggering debug events in parallel, GDB ends up starving some threads. To make the event randomization work in non-stop mode too, the patch makes us pull out all the already pending events on the kernel side, with waitpid, before deciding which LWP to report to the core. There's some code in linux_wait that takes care of leaving events pending if they were for LWPs the caller is not interested in. The patch moves that to linux_nat_filter_event, so that we only have one place that leaves events pending. With that in place, conceptually, the flow is simpler and more normalized: #1 - walk the LWP list looking for an LWP with a pending event to report. #2 - if no pending event, pull events out of the kernel, and store them in the LWP structures as pending. #3- goto #1. 2) Then, currently the event randomization code only considers SIGTRAP (or trap-like) events. That means that if e.g., have have multiple threads stepping in parallel that hit a breakpoint that needs stepping over, and one gets a signal, the signal may end up never getting processed, because GDB will always be giving priority to the SIGTRAPs. The patch fixes this by making the randomization code consider all kinds of pending events. 3) If multiple threads hit a breakpoint, we report one of those, and "cancel" the others. Cancelling means decrementing the PC, and discarding the event. If the next time the LWP is resumed the breakpoint is still installed, the LWP should hit it again, and we'll report the hit then. The problem I found is that this delays threads from advancing too much, with the kernel potentially ending up scheduling the same threads over and over, and others not advancing. So the patch switches away from cancelling the breakpoints, and instead remembering that the LWP had stopped for a breakpoint. If on resume the breakpoint is still installed, we report it. If it's no longer installed, we discard the pending event then. This is actually how GDBserver used to handle this before d50171e4 (Teach linux gdbserver to step-over-breakpoints), but with the difference that back then we'd delay adjusting the PC until resuming, which made it so that "info threads" could wrongly see threads with unadjusted PCs. gdb/ 2015-01-09 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_breakpoint_inserted_here_p): New function. * breakpoint.h (hardware_breakpoint_inserted_here_p): New declaration. * linux-nat.c (linux_nat_status_is_event): Move higher up in file. (linux_resume_one_lwp): Store the thread's PC. Adjust to clear stop_reason. (check_stopped_by_watchpoint): New function. (save_sigtrap): Reimplement. (linux_nat_stopped_by_watchpoint): Adjust. (linux_nat_lp_status_is_event): Delete. (stop_wait_callback): Only call save_sigtrap after storing the pending status. (status_callback): If the thread had been stopped for a breakpoint that has since been removed, discard the event and resume the LWP. (count_events_callback, select_event_lwp_callback): Use lwp_status_pending_p instead of linux_nat_lp_status_is_event. (cancel_breakpoint): Rename to ... (check_stopped_by_breakpoint): ... this. Record whether the LWP stopped for a software breakpoint or hardware breakpoint. (select_event_lwp): Only give preference to the stepping LWP in all-stop mode. Adjust comments. (stop_and_resume_callback): Remove references to new_pending_p. (linux_nat_filter_event): Likewise. Leave exit events of the leader thread pending here. Handle signal short circuiting here. Only call save_sigtrap after storing the pending waitstatus. (linux_nat_wait_1): Remove 'retry' label. Remove references to new_pending. Don't handle leaving events the caller is not interested in pending here, nor handle signal short-circuiting here. Also give equal priority to all LWPs that have had events in non-stop mode. If reporting a software breakpoint event, unadjust the LWP's PC. * linux-nat.h (enum lwp_stop_reason): New. (struct lwp_info) <stop_pc>: New field. (struct lwp_info) <stopped_by_watchpoint>: Delete field. (struct lwp_info) <stop_reason>: New field. * x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-07 13:48:32 +01:00
{
/* In all-stop, from the core's perspective, all LWPs are now
stopped until a new resume action is sent over. */
iterate_over_lwps (minus_one_ptid, resume_clear_callback, NULL);
}
else
{
resume_clear_callback (lp, NULL);
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (linux_nat_status_is_event (status))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LLW: trap ptid is %s.\n",
target_pid_to_str (lp->ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
if (lp->waitstatus.kind != TARGET_WAITKIND_IGNORE)
{
*ourstatus = lp->waitstatus;
lp->waitstatus.kind = TARGET_WAITKIND_IGNORE;
}
else
store_waitstatus (ourstatus, status);
if (debug_linux_nat)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
fprintf_unfiltered (gdb_stdlog, "LLW: exit\n");
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
restore_child_signals_mask (&prev_mask);
if (last_resume_kind == resume_stop
&& ourstatus->kind == TARGET_WAITKIND_STOPPED
&& WSTOPSIG (status) == SIGSTOP)
{
/* A thread that has been requested to stop by GDB with
target_stop, and it stopped cleanly, so report as SIG0. The
use of SIGSTOP is an implementation detail. */
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
ourstatus->value.sig = GDB_SIGNAL_0;
}
if (ourstatus->kind == TARGET_WAITKIND_EXITED
|| ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
lp->core = -1;
else
lp->core = linux_common_core_of_thread (lp->ptid);
if (ourstatus->kind == TARGET_WAITKIND_EXITED)
return filter_exit_event (lp, ourstatus);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
return lp->ptid;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Resume LWPs that are currently stopped without any pending status
to report, but are resumed from the core's perspective. */
static int
resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
{
Add some more casts (1/2) Note: I needed to split this patch in two, otherwise it's too big for the mailing list. This patch adds explicit casts to situations where a void pointer is assigned to a pointer to the "real" type. Building in C++ mode requires those assignments to use an explicit cast. This includes, for example: - callback arguments (cleanups, comparison functions, ...) - data attached to some object (objfile, program space, etc) in the form of a void pointer - "user data" passed to some function This patch comes from the commit "(mostly) auto-generated patch to insert casts needed for C++", taken from Pedro's C++ branch. Only files built on x86 with --enable-targets=all are modified, so the native files for other arches will need to be dealt with separately. I built-tested this with --enable-targets=all and reg-tested. To my surprise, a test case (selftest.exp) had to be adjusted. Here's the ChangeLog entry. Again, this was relatively quick to make despite the length, thanks to David Malcom's script, although I don't believe it's very useful information in that particular case... gdb/ChangeLog: * aarch64-tdep.c (aarch64_make_prologue_cache): Add cast(s). (aarch64_make_stub_cache): Likewise. (value_of_aarch64_user_reg): Likewise. * ada-lang.c (ada_inferior_data_cleanup): Likewise. (get_ada_inferior_data): Likewise. (get_ada_pspace_data): Likewise. (ada_pspace_data_cleanup): Likewise. (ada_complete_symbol_matcher): Likewise. (ada_exc_search_name_matches): Likewise. * ada-tasks.c (get_ada_tasks_pspace_data): Likewise. (get_ada_tasks_inferior_data): Likewise. * addrmap.c (addrmap_mutable_foreach_worker): Likewise. (splay_obstack_alloc): Likewise. (splay_obstack_free): Likewise. * alpha-linux-tdep.c (alpha_linux_supply_gregset): Likewise. (alpha_linux_collect_gregset): Likewise. (alpha_linux_supply_fpregset): Likewise. (alpha_linux_collect_fpregset): Likewise. * alpha-mdebug-tdep.c (alpha_mdebug_frame_unwind_cache): Likewise. * alpha-tdep.c (alpha_lds): Likewise. (alpha_sts): Likewise. (alpha_sigtramp_frame_unwind_cache): Likewise. (alpha_heuristic_frame_unwind_cache): Likewise. (alpha_supply_int_regs): Likewise. (alpha_fill_int_regs): Likewise. (alpha_supply_fp_regs): Likewise. (alpha_fill_fp_regs): Likewise. * alphanbsd-tdep.c (alphanbsd_supply_fpregset): Likewise. (alphanbsd_aout_supply_gregset): Likewise. (alphanbsd_supply_gregset): Likewise. * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise. (amd64_x32_linux_init_abi): Likewise. * amd64-nat.c (amd64_supply_native_gregset): Likewise. (amd64_collect_native_gregset): Likewise. * amd64-tdep.c (amd64_frame_cache): Likewise. (amd64_sigtramp_frame_cache): Likewise. (amd64_epilogue_frame_cache): Likewise. (amd64_supply_fxsave): Likewise. (amd64_supply_xsave): Likewise. (amd64_collect_fxsave): Likewise. (amd64_collect_xsave): Likewise. * amd64-windows-tdep.c (amd64_windows_frame_cache): Likewise. * amd64obsd-tdep.c (amd64obsd_trapframe_cache): Likewise. * arm-linux-tdep.c (arm_linux_supply_gregset): Likewise. (arm_linux_collect_gregset): Likewise. (arm_linux_supply_nwfpe): Likewise. (arm_linux_collect_nwfpe): Likewise. (arm_linux_supply_vfp): Likewise. (arm_linux_collect_vfp): Likewise. * arm-tdep.c (arm_find_mapping_symbol): Likewise. (arm_prologue_unwind_stop_reason): Likewise. (arm_prologue_this_id): Likewise. (arm_prologue_prev_register): Likewise. (arm_exidx_data_free): Likewise. (arm_find_exidx_entry): Likewise. (arm_stub_this_id): Likewise. (arm_m_exception_this_id): Likewise. (arm_m_exception_prev_register): Likewise. (arm_normal_frame_base): Likewise. (gdb_print_insn_arm): Likewise. (arm_objfile_data_free): Likewise. (arm_record_special_symbol): Likewise. (value_of_arm_user_reg): Likewise. * armbsd-tdep.c (armbsd_supply_fpregset): Likewise. (armbsd_supply_gregset): Likewise. * auto-load.c (auto_load_pspace_data_cleanup): Likewise. (get_auto_load_pspace_data): Likewise. (hash_loaded_script_entry): Likewise. (eq_loaded_script_entry): Likewise. (clear_section_scripts): Likewise. (collect_matching_scripts): Likewise. * auxv.c (auxv_inferior_data_cleanup): Likewise. (get_auxv_inferior_data): Likewise. * avr-tdep.c (avr_frame_unwind_cache): Likewise. * ax-general.c (do_free_agent_expr_cleanup): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. (target_bfd_xclose): Likewise. (target_bfd_get_section_table): Likewise. * bfin-tdep.c (bfin_frame_cache): Likewise. * block.c (find_block_in_blockvector): Likewise. (call_site_for_pc): Likewise. (block_find_non_opaque_type_preferred): Likewise. * break-catch-sig.c (signal_catchpoint_insert_location): Likewise. (signal_catchpoint_remove_location): Likewise. (signal_catchpoint_breakpoint_hit): Likewise. (signal_catchpoint_print_one): Likewise. (signal_catchpoint_print_mention): Likewise. (signal_catchpoint_print_recreate): Likewise. * break-catch-syscall.c (get_catch_syscall_inferior_data): Likewise. * breakpoint.c (do_cleanup_counted_command_line): Likewise. (bp_location_compare_addrs): Likewise. (get_first_locp_gte_addr): Likewise. (check_tracepoint_command): Likewise. (do_map_commands_command): Likewise. (get_breakpoint_objfile_data): Likewise. (free_breakpoint_probes): Likewise. (do_captured_breakpoint_query): Likewise. (compare_breakpoints): Likewise. (bp_location_compare): Likewise. (bpstat_remove_breakpoint_callback): Likewise. (do_delete_breakpoint_cleanup): Likewise. * bsd-uthread.c (bsd_uthread_set_supply_uthread): Likewise. (bsd_uthread_set_collect_uthread): Likewise. (bsd_uthread_activate): Likewise. (bsd_uthread_fetch_registers): Likewise. (bsd_uthread_store_registers): Likewise. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt_raw): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. (do_btrace_data_cleanup): Likewise. * c-typeprint.c (find_typedef_for_canonicalize): Likewise. * charset.c (cleanup_iconv): Likewise. (do_cleanup_iterator): Likewise. * cli-out.c (cli_uiout_dtor): Likewise. (cli_table_begin): Likewise. (cli_table_body): Likewise. (cli_table_end): Likewise. (cli_table_header): Likewise. (cli_begin): Likewise. (cli_end): Likewise. (cli_field_int): Likewise. (cli_field_skip): Likewise. (cli_field_string): Likewise. (cli_field_fmt): Likewise. (cli_spaces): Likewise. (cli_text): Likewise. (cli_message): Likewise. (cli_wrap_hint): Likewise. (cli_flush): Likewise. (cli_redirect): Likewise. (out_field_fmt): Likewise. (field_separator): Likewise. (cli_out_set_stream): Likewise. * cli/cli-cmds.c (compare_symtabs): Likewise. * cli/cli-dump.c (call_dump_func): Likewise. (restore_section_callback): Likewise. * cli/cli-script.c (clear_hook_in_cleanup): Likewise. (do_restore_user_call_depth): Likewise. (do_free_command_lines_cleanup): Likewise. * coff-pe-read.c (get_section_vmas): Likewise. (pe_as16): Likewise. (pe_as32): Likewise. * coffread.c (coff_symfile_read): Likewise. * common/agent.c (agent_look_up_symbols): Likewise. * common/filestuff.c (do_close_cleanup): Likewise. * common/format.c (free_format_pieces_cleanup): Likewise. * common/vec.c (vec_o_reserve): Likewise. * compile/compile-c-support.c (print_one_macro): Likewise. * compile/compile-c-symbols.c (hash_symbol_error): Likewise. (eq_symbol_error): Likewise. (del_symbol_error): Likewise. (error_symbol_once): Likewise. (gcc_convert_symbol): Likewise. (gcc_symbol_address): Likewise. (hash_symname): Likewise. (eq_symname): Likewise. * compile/compile-c-types.c (hash_type_map_instance): Likewise. (eq_type_map_instance): Likewise. (insert_type): Likewise. (convert_type): Likewise. * compile/compile-object-load.c (munmap_listp_free_cleanup): Likewise. (setup_sections): Likewise. (link_hash_table_free): Likewise. (copy_sections): Likewise. * compile/compile-object-run.c (do_module_cleanup): Likewise. * compile/compile.c (compile_print_value): Likewise. (do_rmdir): Likewise. (cleanup_compile_instance): Likewise. (cleanup_unlink_file): Likewise. * completer.c (free_completion_tracker): Likewise. * corelow.c (add_to_spuid_list): Likewise. * cp-namespace.c (reset_directive_searched): Likewise. * cp-support.c (reset_directive_searched): Likewise. * cris-tdep.c (cris_sigtramp_frame_unwind_cache): Likewise. (cris_frame_unwind_cache): Likewise. * d-lang.c (builtin_d_type): Likewise. * d-namespace.c (reset_directive_searched): Likewise. * dbxread.c (dbx_free_symfile_info): Likewise. (do_free_bincl_list_cleanup): Likewise. * disasm.c (hash_dis_line_entry): Likewise. (eq_dis_line_entry): Likewise. (dis_asm_print_address): Likewise. (fprintf_disasm): Likewise. (do_ui_file_delete): Likewise. * doublest.c (convert_floatformat_to_doublest): Likewise. * dummy-frame.c (pop_dummy_frame_bpt): Likewise. (dummy_frame_prev_register): Likewise. (dummy_frame_this_id): Likewise. * dwarf2-frame-tailcall.c (cache_hash): Likewise. (cache_eq): Likewise. (cache_find): Likewise. (tailcall_frame_this_id): Likewise. (dwarf2_tailcall_prev_register_first): Likewise. (tailcall_frame_prev_register): Likewise. (tailcall_frame_dealloc_cache): Likewise. (tailcall_frame_prev_arch): Likewise. * dwarf2-frame.c (dwarf2_frame_state_free): Likewise. (dwarf2_frame_set_init_reg): Likewise. (dwarf2_frame_init_reg): Likewise. (dwarf2_frame_set_signal_frame_p): Likewise. (dwarf2_frame_signal_frame_p): Likewise. (dwarf2_frame_set_adjust_regnum): Likewise. (dwarf2_frame_adjust_regnum): Likewise. (clear_pointer_cleanup): Likewise. (dwarf2_frame_cache): Likewise. (find_cie): Likewise. (dwarf2_frame_find_fde): Likewise. * dwarf2expr.c (dwarf_expr_address_type): Likewise. (free_dwarf_expr_context_cleanup): Likewise. * dwarf2loc.c (locexpr_find_frame_base_location): Likewise. (locexpr_get_frame_base): Likewise. (loclist_find_frame_base_location): Likewise. (loclist_get_frame_base): Likewise. (dwarf_expr_dwarf_call): Likewise. (dwarf_expr_get_base_type): Likewise. (dwarf_expr_push_dwarf_reg_entry_value): Likewise. (dwarf_expr_get_obj_addr): Likewise. (entry_data_value_coerce_ref): Likewise. (entry_data_value_copy_closure): Likewise. (entry_data_value_free_closure): Likewise. (get_frame_address_in_block_wrapper): Likewise. (dwarf2_evaluate_property): Likewise. (dwarf2_compile_property_to_c): Likewise. (needs_frame_read_addr_from_reg): Likewise. (needs_frame_get_reg_value): Likewise. (needs_frame_frame_base): Likewise. (needs_frame_frame_cfa): Likewise. (needs_frame_tls_address): Likewise. (needs_frame_dwarf_call): Likewise. (needs_dwarf_reg_entry_value): Likewise. (get_ax_pc): Likewise. (locexpr_read_variable): Likewise. (locexpr_read_variable_at_entry): Likewise. (locexpr_read_needs_frame): Likewise. (locexpr_describe_location): Likewise. (locexpr_tracepoint_var_ref): Likewise. (locexpr_generate_c_location): Likewise. (loclist_read_variable): Likewise. (loclist_read_variable_at_entry): Likewise. (loclist_describe_location): Likewise. (loclist_tracepoint_var_ref): Likewise. (loclist_generate_c_location): Likewise. * dwarf2read.c (line_header_hash_voidp): Likewise. (line_header_eq_voidp): Likewise. (dwarf2_has_info): Likewise. (dwarf2_get_section_info): Likewise. (locate_dwz_sections): Likewise. (hash_file_name_entry): Likewise. (eq_file_name_entry): Likewise. (delete_file_name_entry): Likewise. (dw2_setup): Likewise. (dw2_get_file_names_reader): Likewise. (dw2_find_pc_sect_compunit_symtab): Likewise. (hash_signatured_type): Likewise. (eq_signatured_type): Likewise. (add_signatured_type_cu_to_table): Likewise. (create_debug_types_hash_table): Likewise. (lookup_dwo_signatured_type): Likewise. (lookup_dwp_signatured_type): Likewise. (lookup_signatured_type): Likewise. (hash_type_unit_group): Likewise. (eq_type_unit_group): Likewise. (get_type_unit_group): Likewise. (process_psymtab_comp_unit_reader): Likewise. (sort_tu_by_abbrev_offset): Likewise. (process_skeletonless_type_unit): Likewise. (psymtabs_addrmap_cleanup): Likewise. (dwarf2_read_symtab): Likewise. (psymtab_to_symtab_1): Likewise. (die_hash): Likewise. (die_eq): Likewise. (load_full_comp_unit_reader): Likewise. (reset_die_in_process): Likewise. (free_cu_line_header): Likewise. (handle_DW_AT_stmt_list): Likewise. (hash_dwo_file): Likewise. (eq_dwo_file): Likewise. (hash_dwo_unit): Likewise. (eq_dwo_unit): Likewise. (create_dwo_cu_reader): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (lookup_dwo_unit_in_dwp): Likewise. (dwarf2_locate_dwo_sections): Likewise. (dwarf2_locate_common_dwp_sections): Likewise. (dwarf2_locate_v2_dwp_sections): Likewise. (hash_dwp_loaded_cutus): Likewise. (eq_dwp_loaded_cutus): Likewise. (lookup_dwo_cutu): Likewise. (abbrev_table_free_cleanup): Likewise. (dwarf2_free_abbrev_table): Likewise. (find_partial_die_in_comp_unit): Likewise. (free_line_header_voidp): Likewise. (follow_die_offset): Likewise. (follow_die_sig_1): Likewise. (free_heap_comp_unit): Likewise. (free_stack_comp_unit): Likewise. (dwarf2_free_objfile): Likewise. (per_cu_offset_and_type_hash): Likewise. (per_cu_offset_and_type_eq): Likewise. (get_die_type_at_offset): Likewise. (partial_die_hash): Likewise. (partial_die_eq): Likewise. (dwarf2_per_objfile_free): Likewise. (hash_strtab_entry): Likewise. (eq_strtab_entry): Likewise. (add_string): Likewise. (hash_symtab_entry): Likewise. (eq_symtab_entry): Likewise. (delete_symtab_entry): Likewise. (cleanup_mapped_symtab): Likewise. (add_indices_to_cpool): Likewise. (hash_psymtab_cu_index): Likewise. (eq_psymtab_cu_index): Likewise. (add_address_entry_worker): Likewise. (unlink_if_set): Likewise. (write_one_signatured_type): Likewise. (save_gdb_index_command): Likewise. * elfread.c (elf_symtab_read): Likewise. (elf_gnu_ifunc_cache_hash): Likewise. (elf_gnu_ifunc_cache_eq): Likewise. (elf_gnu_ifunc_record_cache): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_get_probes): Likewise. (probe_key_free): Likewise. * f-lang.c (builtin_f_type): Likewise. * frame-base.c (frame_base_append_sniffer): Likewise. (frame_base_set_default): Likewise. (frame_base_find_by_frame): Likewise. * frame-unwind.c (frame_unwind_prepend_unwinder): Likewise. (frame_unwind_append_unwinder): Likewise. (frame_unwind_find_by_frame): Likewise. * frame.c (frame_addr_hash): Likewise. (frame_addr_hash_eq): Likewise. (frame_stash_find): Likewise. (do_frame_register_read): Likewise. (unwind_to_current_frame): Likewise. (frame_cleanup_after_sniffer): Likewise. * frv-linux-tdep.c (frv_linux_sigtramp_frame_cache): Likewise. * frv-tdep.c (frv_frame_unwind_cache): Likewise. * ft32-tdep.c (ft32_frame_cache): Likewise. * gcore.c (do_bfd_delete_cleanup): Likewise. (gcore_create_callback): Likewise. * gdb_bfd.c (hash_bfd): Likewise. (eq_bfd): Likewise. (gdb_bfd_open): Likewise. (free_one_bfd_section): Likewise. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (get_section_descriptor): Likewise. (gdb_bfd_map_section): Likewise. (gdb_bfd_crc): Likewise. (gdb_bfd_mark_parent): Likewise. (gdb_bfd_record_inclusion): Likewise. (gdb_bfd_requires_relocations): Likewise. (print_one_bfd): Likewise. * gdbtypes.c (type_pair_hash): Likewise. (type_pair_eq): Likewise. (builtin_type): Likewise. (objfile_type): Likewise. * gnu-v3-abi.c (vtable_ptrdiff_type): Likewise. (vtable_address_point_offset): Likewise. (gnuv3_get_vtable): Likewise. (hash_value_and_voffset): Likewise. (eq_value_and_voffset): Likewise. (compare_value_and_voffset): Likewise. (compute_vtable_size): Likewise. (gnuv3_get_typeid_type): Likewise. * go-lang.c (builtin_go_type): Likewise. * guile/scm-block.c (bkscm_hash_block_smob): Likewise. (bkscm_eq_block_smob): Likewise. (bkscm_objfile_block_map): Likewise. (bkscm_del_objfile_blocks): Likewise. * guile/scm-breakpoint.c (bpscm_build_bp_list): Likewise. * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): Likewise. (gdbscm_disasm_print_address): Likewise. * guile/scm-frame.c (frscm_hash_frame_smob): Likewise. (frscm_eq_frame_smob): Likewise. (frscm_inferior_frame_map): Likewise. (frscm_del_inferior_frames): Likewise. * guile/scm-gsmob.c (gdbscm_add_objfile_ref): Likewise. * guile/scm-objfile.c (ofscm_handle_objfile_deleted): Likewise. (ofscm_objfile_smob_from_objfile): Likewise. * guile/scm-ports.c (ioscm_write): Likewise. (ioscm_file_port_delete): Likewise. (ioscm_file_port_rewind): Likewise. (ioscm_file_port_put): Likewise. (ioscm_file_port_write): Likewise. * guile/scm-progspace.c (psscm_handle_pspace_deleted): Likewise. (psscm_pspace_smob_from_pspace): Likewise. * guile/scm-safe-call.c (scscm_recording_pre_unwind_handler): Likewise. (scscm_recording_unwind_handler): Likewise. (gdbscm_with_catch): Likewise. (scscm_call_0_body): Likewise. (scscm_call_1_body): Likewise. (scscm_call_2_body): Likewise. (scscm_call_3_body): Likewise. (scscm_call_4_body): Likewise. (scscm_apply_1_body): Likewise. (scscm_eval_scheme_string): Likewise. (gdbscm_safe_eval_string): Likewise. (scscm_source_scheme_script): Likewise. (gdbscm_safe_source_script): Likewise. * guile/scm-string.c (gdbscm_call_scm_to_stringn): Likewise. (gdbscm_call_scm_from_stringn): Likewise. * guile/scm-symbol.c (syscm_hash_symbol_smob): Likewise. (syscm_eq_symbol_smob): Likewise. (syscm_get_symbol_map): Likewise. (syscm_del_objfile_symbols): Likewise. * guile/scm-symtab.c (stscm_hash_symtab_smob): Likewise. (stscm_eq_symtab_smob): Likewise. (stscm_objfile_symtab_map): Likewise. (stscm_del_objfile_symtabs): Likewise. * guile/scm-type.c (tyscm_hash_type_smob): Likewise. (tyscm_eq_type_smob): Likewise. (tyscm_type_map): Likewise. (tyscm_copy_type_recursive): Likewise. (save_objfile_types): Likewise. * guile/scm-utils.c (extract_arg): Likewise. * h8300-tdep.c (h8300_frame_cache): Likewise. * hppa-linux-tdep.c (hppa_linux_sigtramp_frame_unwind_cache): Likewise. * hppa-tdep.c (compare_unwind_entries): Likewise. (find_unwind_entry): Likewise. (hppa_frame_cache): Likewise. (hppa_stub_frame_unwind_cache): Likewise. * hppanbsd-tdep.c (hppanbsd_supply_gregset): Likewise. * hppaobsd-tdep.c (hppaobsd_supply_gregset): Likewise. (hppaobsd_supply_fpregset): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * i386-tdep.c (i386_frame_cache): Likewise. (i386_epilogue_frame_cache): Likewise. (i386_sigtramp_frame_cache): Likewise. (i386_supply_gregset): Likewise. (i386_collect_gregset): Likewise. (i386_gdbarch_init): Likewise. * i386obsd-tdep.c (i386obsd_aout_supply_regset): Likewise. (i386obsd_trapframe_cache): Likewise. * i387-tdep.c (i387_supply_fsave): Likewise. (i387_collect_fsave): Likewise. (i387_supply_fxsave): Likewise. (i387_collect_fxsave): Likewise. (i387_supply_xsave): Likewise. (i387_collect_xsave): Likewise. * ia64-tdep.c (ia64_frame_cache): Likewise. (ia64_sigtramp_frame_cache): Likewise. * infcmd.c (attach_command_continuation): Likewise. (attach_command_continuation_free_args): Likewise. * inferior.c (restore_inferior): Likewise. (delete_thread_of_inferior): Likewise. * inflow.c (inflow_inferior_data_cleanup): Likewise. (get_inflow_inferior_data): Likewise. (inflow_inferior_exit): Likewise. * infrun.c (displaced_step_clear_cleanup): Likewise. (restore_current_uiout_cleanup): Likewise. (release_stop_context_cleanup): Likewise. (do_restore_infcall_suspend_state_cleanup): Likewise. (do_restore_infcall_control_state_cleanup): Likewise. (restore_inferior_ptid): Likewise. * inline-frame.c (block_starting_point_at): Likewise. * iq2000-tdep.c (iq2000_frame_cache): Likewise. * jit.c (get_jit_objfile_data): Likewise. (get_jit_program_space_data): Likewise. (jit_object_close_impl): Likewise. (jit_find_objf_with_entry_addr): Likewise. (jit_breakpoint_deleted): Likewise. (jit_unwind_reg_set_impl): Likewise. (jit_unwind_reg_get_impl): Likewise. (jit_dealloc_cache): Likewise. (jit_frame_sniffer): Likewise. (jit_frame_prev_register): Likewise. (jit_prepend_unwinder): Likewise. (jit_inferior_exit_hook): Likewise. (free_objfile_data): Likewise. * jv-lang.c (jv_per_objfile_free): Likewise. (get_dynamics_objfile): Likewise. (get_java_class_symtab): Likewise. (builtin_java_type): Likewise. * language.c (language_string_char_type): Likewise. (language_bool_type): Likewise. (language_lookup_primitive_type): Likewise. (language_lookup_primitive_type_as_symbol): Likewise. * linespec.c (hash_address_entry): Likewise. (eq_address_entry): Likewise. (iterate_inline_only): Likewise. (iterate_name_matcher): Likewise. (decode_line_2_compare_items): Likewise. (collect_one_symbol): Likewise. (compare_symbols): Likewise. (compare_msymbols): Likewise. (add_symtabs_to_list): Likewise. (collect_symbols): Likewise. (compare_msyms): Likewise. (add_minsym): Likewise. (cleanup_linespec_result): Likewise. * linux-fork.c (inferior_call_waitpid_cleanup): Likewise. * linux-nat.c (delete_lwp_cleanup): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (resume_stopped_resumed_lwps): Likewise. * linux-tdep.c (get_linux_gdbarch_data): Likewise. (invalidate_linux_cache_inf): Likewise. (get_linux_inferior_data): Likewise. (linux_find_memory_regions_thunk): Likewise. (linux_make_mappings_callback): Likewise. (linux_corefile_thread_callback): Likewise. (find_mapping_size): Likewise. * linux-thread-db.c (find_new_threads_callback): Likewise. * lm32-tdep.c (lm32_frame_cache): Likewise. * m2-lang.c (builtin_m2_type): Likewise. * m32c-tdep.c (m32c_analyze_frame_prologue): Likewise. * m32r-linux-tdep.c (m32r_linux_sigtramp_frame_cache): Likewise. (m32r_linux_supply_gregset): Likewise. (m32r_linux_collect_gregset): Likewise. * m32r-tdep.c (m32r_frame_unwind_cache): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * m68k-tdep.c (m68k_frame_cache): Likewise. * m68kbsd-tdep.c (m68kbsd_supply_fpregset): Likewise. (m68kbsd_supply_gregset): Likewise. * m68klinux-tdep.c (m68k_linux_sigtramp_frame_cache): Likewise. * m88k-tdep.c (m88k_frame_cache): Likewise. (m88k_supply_gregset): Likewise. gdb/gdbserver/ChangeLog: * dll.c (match_dll): Add cast(s). (unloaded_dll): Likewise. * linux-low.c (second_thread_of_pid_p): Likewise. (delete_lwp_callback): Likewise. (count_events_callback): Likewise. (select_event_lwp_callback): Likewise. (linux_set_resume_request): Likewise. * server.c (accumulate_file_name_length): Likewise. (emit_dll_description): Likewise. (handle_qxfer_threads_worker): Likewise. (visit_actioned_threads): Likewise. * thread-db.c (any_thread_of): Likewise. * tracepoint.c (same_process_p): Likewise. (match_blocktype): Likewise. (build_traceframe_info_xml): Likewise. gdb/testsuite/ChangeLog: * gdb.gdb/selftest.exp (do_steps_and_nexts): Adjust expected source line.
2015-09-25 20:08:07 +02:00
ptid_t *wait_ptid_p = (ptid_t *) data;
PR threads/18600: Threads left stopped after fork+thread spawn When a program forks and another process start threads while gdb is handling the fork event, newly created threads are left stuck stopped by gdb, even though gdb presents them as "running", to the user. This can be seen with the test added by this patch. The test has the inferior fork a certain number of times and waits for all children to exit. Each fork child spawns a number of threads that do nothing and joins them immediately. Normally, the program should run unimpeded (from the point of view of the user) and exit very quickly. Without this fix, it doesn't because of some threads left stopped by gdb, so inferior 1 never exits. The program triggers when a new clone thread is found while inside the linux_stop_and_wait_all_lwps call in linux-thread-db.c: linux_stop_and_wait_all_lwps (); ALL_LWPS (lp) if (ptid_get_pid (lp->ptid) == pid) thread_from_lwp (lp->ptid); linux_unstop_all_lwps (); Within linux_stop_and_wait_all_lwps, we reach linux_handle_extended_wait with the "stopping" parameter set to 1, and because of that we don't mark the new lwp as resumed. As consequence, the subsequent resume_stopped_resumed_lwps, called from linux_unstop_all_lwps, never resumes the new LWP. There's lots of cruft in linux_handle_extended_wait that no longer makes sense. On systems with CLONE events support, we don't rely on libthread_db for thread listing anymore, so the code that preserves stop_requested and the handling of last_resume_kind is all dead. So the fix is to remove all that, and simply always mark the new LWP as resumed, so that resume_stopped_resumed_lwps re-resumes it. gdb/ChangeLog: 2015-07-30 Pedro Alves <palves@redhat.com> Simon Marchi <simon.marchi@ericsson.com> PR threads/18600 * linux-nat.c (linux_handle_extended_wait): On CLONE event, always mark the new thread as resumed. Remove STOPPING parameter. (wait_lwp): Adjust call to linux_handle_extended_wait. (linux_nat_filter_event): Adjust call to linux_handle_extended_wait. (resume_stopped_resumed_lwps): Add debug output. gdb/testsuite/ChangeLog: 2015-07-30 Simon Marchi <simon.marchi@ericsson.com> Pedro Alves <palves@redhat.com> PR threads/18600 * gdb.threads/fork-plus-threads.c: New file. * gdb.threads/fork-plus-threads.exp: New file.
2015-07-30 19:50:29 +02:00
if (!lp->stopped)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RSRL: NOT resuming LWP %s, not stopped\n",
target_pid_to_str (lp->ptid));
}
else if (!lp->resumed)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RSRL: NOT resuming LWP %s, not resumed\n",
target_pid_to_str (lp->ptid));
}
else if (lwp_status_pending_p (lp))
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RSRL: NOT resuming LWP %s, has pending status\n",
target_pid_to_str (lp->ptid));
}
else
{
struct regcache *regcache = get_thread_regcache (lp->ptid);
struct gdbarch *gdbarch = get_regcache_arch (regcache);
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
TRY
{
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
CORE_ADDR pc = regcache_read_pc (regcache);
int leave_stopped = 0;
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
/* Don't bother if there's a breakpoint at PC that we'd hit
immediately, and we're not waiting for this LWP. */
if (!ptid_match (lp->ptid, *wait_ptid_p))
{
if (breakpoint_inserted_here_p (get_regcache_aspace (regcache), pc))
leave_stopped = 1;
}
Fix race exposed by gdb.threads/killed.exp On GNU/Linux, this test sometimes FAILs like this: (gdb) run Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". ptrace: No such process. (gdb) Program terminated with signal SIGKILL, Killed. The program no longer exists. FAIL: gdb.threads/killed.exp: run program to completion (timeout) Note the suspicious "No such process" line (that's errno==ESRCH). Adding debug output we see: linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Stopped (signal) (stopped) LNW: waitpid(-1, ...) returned 18461, ERRNO-OK LLW: waitpid 18461 received Trace/breakpoint trap (stopped) LLW: Handling extended status 0x03057f LHEW: Got clone event from LWP 18461, new child is LWP 18465 LNW: waitpid(-1, ...) returned 0, ERRNO-OK RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 sigchld ptrace: No such process. (gdb) linux_nat_wait: [process -1], [TARGET_WNOHANG] LLW: enter LNW: waitpid(-1, ...) returned 18465, ERRNO-OK LLW: waitpid 18465 received Killed (terminated) LLW: LWP 18465 exited. LNW: waitpid(-1, ...) returned 18461, No child processes LLW: waitpid 18461 received Killed (terminated) Process 18461 exited LNW: waitpid(-1, ...) returned -1, No child processes LLW: exit sigchld infrun: target_wait (-1, status) = infrun: 18461 [process 18461], infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL infrun: TARGET_WAITKIND_SIGNALLED Program terminated with signal SIGKILL, Killed. The program no longer exists. infrun: stop_waiting FAIL: gdb.threads/killed.exp: run program to completion (timeout) The issue is that here: RSRL: resuming stopped-resumed LWP LWP 18465 at 0x3b36af4b51: step=0 RSRL: resuming stopped-resumed LWP LWP 18461 at 0x3b36af4b51: step=0 The first line shows we had just resumed LWP 18465, which does: void * child_func (void *dummy) { kill (pid, SIGKILL); exit (1); } So if the kernel manages to schedule that thread fast enough, the process may be killed before GDB has a chance to resume LWP 18461. GDBserver has code at the tail end of linux_resume_one_lwp to cope with this: ~~~ ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, lwpid_of (thread), (PTRACE_TYPE_ARG3) 0, /* Coerce to a uintptr_t first to avoid potential gcc warning of coercing an 8 byte integer to a 4 byte pointer. */ (PTRACE_TYPE_ARG4) (uintptr_t) signal); current_thread = saved_thread; if (errno) { /* ESRCH from ptrace either means that the thread was already running (an error) or that it is gone (a race condition). If it's gone, we will get a notification the next time we wait, so we can ignore the error. We could differentiate these two, but it's tricky without waiting; the thread still exists as a zombie, so sending it signal 0 would succeed. So just ignore ESRCH. */ if (errno == ESRCH) return; perror_with_name ("ptrace"); } ~~~ However, that's not a complete fix, because between starting to handle the resume request and getting that PTRACE_CONTINUE, we run other ptrace calls that can also fail with ESRCH, and that end up throwing an error (with perror_with_name). In the case above, I indeed sometimes see resume_stopped_resumed_lwps fail in the registers read: resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) { ... CORE_ADDR pc = regcache_read_pc (regcache); Or e.g., in 32-bit mode, i386_linux_resume has several calls that can throw too. Whether to ignore ptrace errors or not depends on context that is only available somewhere up the call chain. So the fix is to let ptrace errors throw as they do today, and wrap the resume request in a TRY/CATCH that swallows it iff the lwp that we were trying to resume is no longer ptrace-stopped. gdb/gdbserver/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-low.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. gdb/ChangeLog: 2015-03-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_resume_one_lwp): Rename to ... (linux_resume_one_lwp_throw): ... this. Don't handle ESRCH here, instead call perror_with_name. (check_ptrace_stopped_lwp_gone): New function. (linux_resume_one_lwp): Reimplement as wrapper around linux_resume_one_lwp_throw that swallows errors if the LWP is gone. (resume_stopped_resumed_lwps): Try register reads in TRY/CATCH and swallows errors if the LWP is gone. Use linux_resume_one_lwp_throw instead of linux_resume_one_lwp.
2015-03-19 16:12:33 +01:00
if (!leave_stopped)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"RSRL: resuming stopped-resumed LWP %s at "
"%s: step=%d\n",
target_pid_to_str (lp->ptid),
paddress (gdbarch, pc),
lp->step);
linux_resume_one_lwp_throw (lp, lp->step, GDB_SIGNAL_0);
}
}
CATCH (ex, RETURN_MASK_ERROR)
{
if (!check_ptrace_stopped_lwp_gone (lp))
throw_exception (ex);
}
END_CATCH
}
return 0;
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
static ptid_t
linux_nat_wait (struct target_ops *ops,
* target.h (TARGET_WNOHANG): New. * target.c (target_wait): Add `options' argument. Adjust. (struct target_ops) <to_wait>: Add `options' argument. (target_wait): Add `options' argument. * infrun.c (wait_for_inferior): Pass 0 as options to target_wait (blocking wait). (fetch_inferior_event): Pass TARGET_WNOHANG as options to target_wait. * fork-child.c (startup_inferior): Pass 0 as options to target_wait (blocking wait). * linux-nat.c (linux_nat_create_inferior): Remove async masking. (linux_nat_wait_1): Add `target_options' argument. Use it instead of checking on target_can_async_p. (linux_nat_wait): Add `target_options' argument. Adjust. * remote.c (remote_wait_ns): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. (remote_wait_as): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. If doing a blocking wait, keep waiting until an interesting event comes out. (remote_wait): Add `options' argument. Don't loop here if the target is in async mode, and a blocking wait has been requested. * top.c (deprecated_target_wait_hook): Add `options' argument. * linux-thread-db.c (thread_db_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ptrace.c (inf_ptrace_wait): Add `options' argument. * record.c (record_beneath_to_wait): Add `options' argument. (record_wait): Add `options' argument, and pass it down to the layer beneath. * bsd-uthread.c (bsd_uthread_wait): Add `options' argument. * darwin-nat.c (darwin_wait): Likewise. * defs.h (deprecated_target_wait_hook): Likewise. * gnu-nat.c (gnu_wait): Add `options' argument. * go32-nat.c (go32_wait): Likewise. * hpux-thread.c (hpux_thread_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ttrace.c (inf_ttrace_wait): Add `options' argument. * monitor.c (monitor_wait): Likewise. * nto-procfs.c (procfs_wait): Likewise. * remote-mips.c (mips_wait): Add `options' argument. * remote-sim.c (gdbsim_wait): Likewise. * rs6000-nat.c (rs6000_wait): Add `options' argument. * sol-thread.c (sol_thread_wait): Add `options' argument, and pass it down to the layer beneath. * spu-linux-nat.c (spu_child_wait): Add `options' argument. * windows-nat.c (windows_wait): Likewise. * tui/tui-hooks.c (tui_target_wait_hook): Likewise. Adjust.
2009-05-21 17:48:42 +02:00
ptid_t ptid, struct target_waitstatus *ourstatus,
int target_options)
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
{
ptid_t event_ptid;
if (debug_linux_nat)
{
char *options_string;
options_string = target_options_to_string (target_options);
fprintf_unfiltered (gdb_stdlog,
"linux_nat_wait: [%s], [%s]\n",
target_pid_to_str (ptid),
options_string);
xfree (options_string);
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Flush the async file first. */
if (target_is_async_p ())
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
async_file_flush ();
/* Resume LWPs that are currently stopped without any pending status
to report, but are resumed from the core's perspective. LWPs get
in this state if we find them stopping at a time we're not
interested in reporting the event (target_wait on a
specific_process, for example, see linux_nat_wait_1), and
meanwhile the event became uninteresting. Don't bother resuming
LWPs we're not going to wait for if they'd stop immediately. */
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
if (target_is_non_stop_p ())
iterate_over_lwps (minus_one_ptid, resume_stopped_resumed_lwps, &ptid);
* target.h (TARGET_WNOHANG): New. * target.c (target_wait): Add `options' argument. Adjust. (struct target_ops) <to_wait>: Add `options' argument. (target_wait): Add `options' argument. * infrun.c (wait_for_inferior): Pass 0 as options to target_wait (blocking wait). (fetch_inferior_event): Pass TARGET_WNOHANG as options to target_wait. * fork-child.c (startup_inferior): Pass 0 as options to target_wait (blocking wait). * linux-nat.c (linux_nat_create_inferior): Remove async masking. (linux_nat_wait_1): Add `target_options' argument. Use it instead of checking on target_can_async_p. (linux_nat_wait): Add `target_options' argument. Adjust. * remote.c (remote_wait_ns): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. (remote_wait_as): Add `options' argument. Adjust to check on TARGET_WNOWAIT instead of checking on remote_is_async_p. If doing a blocking wait, keep waiting until an interesting event comes out. (remote_wait): Add `options' argument. Don't loop here if the target is in async mode, and a blocking wait has been requested. * top.c (deprecated_target_wait_hook): Add `options' argument. * linux-thread-db.c (thread_db_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ptrace.c (inf_ptrace_wait): Add `options' argument. * record.c (record_beneath_to_wait): Add `options' argument. (record_wait): Add `options' argument, and pass it down to the layer beneath. * bsd-uthread.c (bsd_uthread_wait): Add `options' argument. * darwin-nat.c (darwin_wait): Likewise. * defs.h (deprecated_target_wait_hook): Likewise. * gnu-nat.c (gnu_wait): Add `options' argument. * go32-nat.c (go32_wait): Likewise. * hpux-thread.c (hpux_thread_wait): Add `options' argument, and pass it down to the layer beneath. * inf-ttrace.c (inf_ttrace_wait): Add `options' argument. * monitor.c (monitor_wait): Likewise. * nto-procfs.c (procfs_wait): Likewise. * remote-mips.c (mips_wait): Add `options' argument. * remote-sim.c (gdbsim_wait): Likewise. * rs6000-nat.c (rs6000_wait): Add `options' argument. * sol-thread.c (sol_thread_wait): Add `options' argument, and pass it down to the layer beneath. * spu-linux-nat.c (spu_child_wait): Add `options' argument. * windows-nat.c (windows_wait): Likewise. * tui/tui-hooks.c (tui_target_wait_hook): Likewise. Adjust.
2009-05-21 17:48:42 +02:00
event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus, target_options);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* If we requested any event, and something came out, assume there
may be more. If we requested a specific lwp or process, also
assume there may be more. */
if (target_is_async_p ()
&& ((ourstatus->kind != TARGET_WAITKIND_IGNORE
&& ourstatus->kind != TARGET_WAITKIND_NO_RESUMED)
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
|| !ptid_equal (ptid, minus_one_ptid)))
async_file_mark ();
return event_ptid;
}
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
/* Kill one LWP. */
static void
kill_one_lwp (pid_t pid)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
/* PTRACE_KILL may resume the inferior. Send SIGKILL first. */
errno = 0;
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
kill_lwp (pid, SIGKILL);
if (debug_linux_nat)
{
int save_errno = errno;
fprintf_unfiltered (gdb_stdlog,
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
"KC: kill (SIGKILL) %ld, 0, 0 (%s)\n", (long) pid,
save_errno ? safe_strerror (save_errno) : "OK");
}
/* Some kernels ignore even SIGKILL for processes under ptrace. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
errno = 0;
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
ptrace (PTRACE_KILL, pid, 0, 0);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
if (debug_linux_nat)
{
int save_errno = errno;
fprintf_unfiltered (gdb_stdlog,
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
"KC: PTRACE_KILL %ld, 0, 0 (%s)\n", (long) pid,
save_errno ? safe_strerror (save_errno) : "OK");
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
/* Wait for an LWP to die. */
static void
kill_wait_one_lwp (pid_t pid)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
pid_t res;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* We must make sure that there are no pending events (delayed
SIGSTOPs, pending SIGTRAPs, etc.) to make sure the current
program doesn't interfere with any following debugging session. */
do
{
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
res = my_waitpid (pid, NULL, __WALL);
if (res != (pid_t) -1)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
"KWC: wait %ld received unknown.\n",
(long) pid);
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
/* The Linux kernel sometimes fails to kill a thread
completely after PTRACE_KILL; that goes from the stop
point in do_fork out to the one in get_signal_to_deliver
and waits again. So kill it again. */
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
kill_one_lwp (pid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
}
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
while (res == pid);
gdb_assert (res == -1 && errno == ECHILD);
}
/* Callback for iterate_over_lwps. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
static int
kill_callback (struct lwp_info *lp, void *data)
{
kill_one_lwp (ptid_get_lwp (lp->ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return 0;
}
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
/* Callback for iterate_over_lwps. */
static int
kill_wait_callback (struct lwp_info *lp, void *data)
{
kill_wait_one_lwp (ptid_get_lwp (lp->ptid));
return 0;
}
/* Kill the fork children of any threads of inferior INF that are
stopped at a fork event. */
static void
kill_unfollowed_fork_children (struct inferior *inf)
{
struct thread_info *thread;
ALL_NON_EXITED_THREADS (thread)
if (thread->inf == inf)
{
struct target_waitstatus *ws = &thread->pending_follow;
if (ws->kind == TARGET_WAITKIND_FORKED
|| ws->kind == TARGET_WAITKIND_VFORKED)
{
ptid_t child_ptid = ws->value.related_pid;
int child_pid = ptid_get_pid (child_ptid);
int child_lwp = ptid_get_lwp (child_ptid);
kill_one_lwp (child_lwp);
kill_wait_one_lwp (child_lwp);
/* Let the arch-specific native code know this process is
gone. */
linux_nat_forget_process (child_pid);
}
}
}
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
static void
linux_nat_kill (struct target_ops *ops)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
/* If we're stopped while forking and we haven't followed yet,
kill the other task. We need to do this first because the
parent will be sleeping if this is a vfork. */
Fix PR 19494: hang when killing unfollowed fork children linux_nat_kill relies on get_last_target_status to determine whether the current inferior is stopped at a unfollowed fork/vfork event. This is bad because many things can happen ever since we caught the fork/vfork event... This commit rewrites that code to instead walk the thread list looking for unfollowed fork events, similarly to what was done for remote.c. New test included. The main idea of the test is make sure that when the program stops for a fork catchpoint, and the user kills the parent, gdb also kills the unfollowed fork child. Since the child hasn't been added as an inferior at that point, we need some other portable way to detect that the child is gone. The test uses a pipe for that. The program forks twice, so you have grandparent, child and grandchild. The grandchild inherits the write side of the pipe. The grandparent hangs reading from the pipe, since nothing ever writes to it. If, when GDB kills the child, it also kills the grandchild, then the grandparent's pipe read returns 0/EOF and the test passes. Otherwise, if GDB doesn't kill the grandchild, then the pipe read never returns and the test times out, like: FAIL: gdb.base/catch-fork-kill.exp: fork-kind=fork: exit-kind=kill: fork: kill parent (timeout) FAIL: gdb.base/catch-fork-kill.exp: fork-kind=vfork: exit-kind=kill: vfork: kill parent (timeout) No regressions on x86_64 Fedora 20. New test passes with gdbserver as well. gdb/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * linux-nat.c (kill_one_lwp): New, factored out from ... (kill_callback): ... this. (kill_wait_callback): New, factored out from ... (kill_wait_one_lwp): ... this. (kill_unfollowed_fork_children): New function. (linux_nat_kill): Use it. gdb/testsuite/ChangeLog: 2016-01-25 Pedro Alves <palves@redhat.com> PR gdb/19494 * gdb.base/catch-fork-kill.c: New file. * gdb.base/catch-fork-kill.exp: New file.
2016-01-25 13:00:20 +01:00
kill_unfollowed_fork_children (current_inferior ());
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
if (forks_exist_p ())
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
linux_fork_killall ();
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
else
{
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
ptid_t ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
/* Stop all threads before killing them, since ptrace requires
that the thread is stopped to sucessfully PTRACE_KILL. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (ptid, stop_callback, NULL);
/* ... and wait until all of them have reported back that
they're no longer running. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (ptid, stop_wait_callback, NULL);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
/* Kill all LWP's ... */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (ptid, kill_callback, NULL);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
/* ... and wait until we've flushed all events. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
iterate_over_lwps (ptid, kill_wait_callback, NULL);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
}
Consolidate target_mourn_inferior between GDB and gdbserver This patch consolidates the API of target_mourn_inferior between GDB and gdbserver, in my continuing efforts to make sharing the fork_inferior function possible between both. GDB's version of the function did not care about the inferior's ptid being mourned, but gdbserver's needed to know this information. Since it actually makes sense to pass the ptid as an argument, instead of depending on a global value directly (which GDB's version did), I decided to make the generic API to accept it. I then went on and extended all calls being made on GDB to include a ptid argument (which ended up being inferior_ptid most of the times, anyway), and now we have a more sane interface. On GDB's side, after talking to Pedro a bit about it, we decided that just an assertion to make sure that the ptid being passed is equal to inferior_ptid would be enough for now, on the GDB side. We can remove the assertion and perform more operations later if we ever pass anything different than inferior_ptid. Regression tested on our BuildBot, everything OK. I'd appreciate a special look at gdb/windows-nat.c's modification because I wasn't really sure what to do there. It seemed to me that maybe I should build a ptid out of the process information there, but then I am almost sure the assertion on GDB's side would trigger. gdb/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * darwin-nat.c (darwin_kill_inferior): Adjusting call to target_mourn_inferior to include ptid_t argument. * fork-child.c (startup_inferior): Likewise. * gnu-nat.c (gnu_kill_inferior): Likewise. * inf-ptrace.c (inf_ptrace_kill): Likewise. * infrun.c (handle_inferior_event_1): Likewise. * linux-nat.c (linux_nat_attach): Likewise. (linux_nat_kill): Likewise. * nto-procfs.c (interrupt_query): Likewise. (procfs_interrupt): Likewise. (procfs_kill_inferior): Likewise. * procfs.c (procfs_kill_inferior): Likewise. * record.c (record_mourn_inferior): Likewise. * remote-sim.c (gdbsim_kill): Likewise. * remote.c (remote_detach_1): Likewise. (remote_kill): Likewise. * target.c (target_mourn_inferior): Change declaration to accept new ptid_t argument; use gdb_assert on it. * target.h (target_mourn_inferior): Move function prototype from here... * target/target.h (target_mourn_inferior): ... to here. Adjust it to accept new ptid_t argument. * windows-nat.c (get_windows_debug_event): Adjusting call to target_mourn_inferior to include ptid_t argument. gdb/gdbserver/ChangeLog: 2016-09-19 Sergio Durigan Junior <sergiodj@redhat.com> * server.c (start_inferior): Call target_mourn_inferior instead of mourn_inferior; pass ptid_t argument to it. (resume): Likewise. (handle_target_event): Likewise. * target.c (target_mourn_inferior): New function. * target.h (mourn_inferior): Delete macro.
2016-09-12 05:45:31 +02:00
target_mourn_inferior (inferior_ptid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
static void
Kill pthread_ops_hack * target.h (struct target_ops): Make to_attach, to_detach, to_create_inferior and to_mourn_inferior accept a pointer to struct target_ops. (target_attach, target_create_inferior, target_create_inferior): Convert from macros to function. Find the right target to invoke a method of. (find_default_attach, find_default_create_inferior): New parameter ops. * corefile.c (core_file_command): Pass target to to_detach. * corelow.c (core_detach): Add 'ops' parameter. * fork-child.c (fork_inferior): Return the pid. Allow init_trace_fun to be NULL. * inf-ptrace (ptrace_ops_hack): Remove. (inf_ptrace_him): Remove, moving all logic into.... (inf_ptrace_create_inferior): ... here. Push the target passed as parameter. (inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach): Push/pop target passed as parameter, no ptrace_ops_hack. (inf_ptrace_target): Don't remember result. * inferior.h (fork_inferior): Adjust prototype. * linux-nat.c (linux_nat_create_inferior, linux_nat_attach) (linux_nat_detach, linux_nat_mourn_inferior): New parameter ops. Pass it to linux_ops target. * linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior): New parameter ops. Pass it to the target beneath. * remote.c (remote_mourn, extended_remote_mourn, remote_detach) (extended_remote_create_inferior): New parameter ops. Pass it further. * target.c (debug_to_attach, debug_to_detach) (debug_to_mourn_inferior): New parameter ops. (target_create_inferior): New. (update_current_target): Do not inherit to_attach, to_detach, to_create_inferiour, to_mourn_inferior. Do not default to_detach and to_mourn_inferior. (target_detach): Find the right target to use. (target_mourn_inferior): New. (find_default_attach, find_default_create_inferior): New parameter ops. Pass the found target when calling its method. (init_dummy_target): Provide fallback definition of to_detach. (target_attach): New. (debug_to_attach, debug_to_detach, debug_to_create_inferior) (debug_to_mourn_inferiour): New parameter ops. * aix-thread.c: Adjust. * bsd-uthread.c: Adjust. * gnu-nat.c: Adjust. * go32-nat.c: Adjust. * hpux-thread.c: Adjust. * inf-ttrace.c: Ajust. * monitor.c: Adjust. * nto-procfs.c: Adjust. * procfs.c: Adjust. * remote-m32r-sdi.c: Adjust. * remote-mips.c: Adjust. * remote-sim.c: Adjust. * rs6000-nat.c: Adjust. * sol-thread.c: Adjust. * win32-nat.c: Adjust. * dec-thread.c: Adjust.
2008-11-09 12:27:18 +01:00
linux_nat_mourn_inferior (struct target_ops *ops)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
int pid = ptid_get_pid (inferior_ptid);
purge_lwp_list (pid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
if (! forks_exist_p ())
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
/* Normal case, no other forks available. */
linux_ops->to_mourn_inferior (ops);
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
else
/* Multi-fork case. The current inferior_ptid has exited, but
there are other viable forks to debug. Delete the exiting
one and context-switch to the first available. */
linux_fork_mourn_inferior ();
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
/* Let the arch-specific native code know this process is gone. */
linux_nat_forget_process (pid);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* Convert a native/host siginfo object, into/from the siginfo in the
layout of the inferiors' architecture. */
static void
siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, int direction)
{
int done = 0;
if (linux_nat_siginfo_fixup != NULL)
done = linux_nat_siginfo_fixup (siginfo, inf_siginfo, direction);
/* If there was no callback, or the callback didn't do anything,
then just do a straight memcpy. */
if (!done)
{
if (direction == 1)
memcpy (siginfo, inf_siginfo, sizeof (siginfo_t));
else
memcpy (inf_siginfo, siginfo, sizeof (siginfo_t));
}
}
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len)
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
{
int pid;
siginfo_t siginfo;
gdb_byte inf_siginfo[sizeof (siginfo_t)];
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
gdb_assert (object == TARGET_OBJECT_SIGNAL_INFO);
gdb_assert (readbuf || writebuf);
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_lwp (inferior_ptid);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
if (pid == 0)
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_pid (inferior_ptid);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
if (offset > sizeof (siginfo))
Replace -1 with TARGET_XFER_E_IO Hi, This patch replaces -1 with TARGET_XFER_E_IO in the implementations of to_xfer_partial and their callees. This change is quite mechanical, and makes the next patch shorter. gdb: 2014-02-07 Yao Qi <yao@codesourcery.com> * auxv.c (procfs_xfer_auxv): Replace -1 with TARGET_XFER_E_IO. (ld_so_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (exec_xfer_partial): Likewise. * gnu-nat.c (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_uregs): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_proc_xfer_spu): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_qxfer): Likewise. (remote_write_qxfer, remote_read_qxfer): Likewise. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * target.c (memory_xfer_partial_1): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise.
2014-01-27 10:32:33 +01:00
return TARGET_XFER_E_IO;
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
errno = 0;
ptrace (PTRACE_GETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo);
if (errno != 0)
Replace -1 with TARGET_XFER_E_IO Hi, This patch replaces -1 with TARGET_XFER_E_IO in the implementations of to_xfer_partial and their callees. This change is quite mechanical, and makes the next patch shorter. gdb: 2014-02-07 Yao Qi <yao@codesourcery.com> * auxv.c (procfs_xfer_auxv): Replace -1 with TARGET_XFER_E_IO. (ld_so_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (exec_xfer_partial): Likewise. * gnu-nat.c (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_uregs): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_proc_xfer_spu): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_qxfer): Likewise. (remote_write_qxfer, remote_read_qxfer): Likewise. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * target.c (memory_xfer_partial_1): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise.
2014-01-27 10:32:33 +01:00
return TARGET_XFER_E_IO;
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
/* When GDB is built as a 64-bit application, ptrace writes into
SIGINFO an object with 64-bit layout. Since debugging a 32-bit
inferior with a 64-bit GDB should look the same as debugging it
with a 32-bit GDB, we need to convert it. GDB core always sees
the converted layout, so any read/write will have to be done
post-conversion. */
siginfo_fixup (&siginfo, inf_siginfo, 0);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
if (offset + len > sizeof (siginfo))
len = sizeof (siginfo) - offset;
if (readbuf != NULL)
memcpy (readbuf, inf_siginfo + offset, len);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
else
{
memcpy (inf_siginfo + offset, writebuf, len);
/* Convert back to ptrace layout before flushing it out. */
siginfo_fixup (&siginfo, inf_siginfo, 1);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
errno = 0;
ptrace (PTRACE_SETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo);
if (errno != 0)
Replace -1 with TARGET_XFER_E_IO Hi, This patch replaces -1 with TARGET_XFER_E_IO in the implementations of to_xfer_partial and their callees. This change is quite mechanical, and makes the next patch shorter. gdb: 2014-02-07 Yao Qi <yao@codesourcery.com> * auxv.c (procfs_xfer_auxv): Replace -1 with TARGET_XFER_E_IO. (ld_so_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (exec_xfer_partial): Likewise. * gnu-nat.c (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_uregs): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_proc_xfer_spu): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_qxfer): Likewise. (remote_write_qxfer, remote_read_qxfer): Likewise. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * target.c (memory_xfer_partial_1): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise.
2014-01-27 10:32:33 +01:00
return TARGET_XFER_E_IO;
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
}
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
*xfered_len = len;
return TARGET_XFER_OK;
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
}
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
linux_nat_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
enum target_xfer_status xfer;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
if (object == TARGET_OBJECT_SIGNAL_INFO)
return linux_xfer_siginfo (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/ * target.h (enum target_object): Add new TARGET_OBJECT_SIGNAL_INFO. * infrun.c (siginfo_value_read, siginfo_value_write): New. (siginfo_value_funcs): New. (siginfo_make_value): New. (_initialize_infrun): Create the $_siginfo convenience variable. * gdbtypes.h (append_composite_type_field_aligned): Declare. * gdbtypes.c (append_composite_type_field): Rename to... (append_composite_type_field_aligned): ... this. Add ALIGNMENT argument. Handle it. (append_composite_type_field): Rewrite on top of append_composite_type_field_aligned. * value.h (internalvar_make_value): New typedef. (struct internalvar) <make_value>: New field. (create_internalvar_type_lazy): Declare. * value.c (create_internalvar): Clear make_value. (create_internalvar_type_lazy): New. (value_of_internalvar): If make_value is set use it. (preserve_values): Skip internal variables that don't have a value. * gdbarch.sh (get_siginfo_type): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.h, linux-tdep.c: New. * amd64-linux-tdep.c: Include "linux-tdep.h". (amd64_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * i386-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * arm-linux-tdep.c: Include "linux-tdep.h". (i386_linux_init_abi): Register linux_get_siginfo_type and linux_get_siginfo_mapper. * linux-nat.c (linux_xfer_siginfo): New. (linux_nat_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. * remote.c (PACKET_qXfer_siginfo_read) (PACKET_qXfer_siginfo_write): New. (feature remote_protocol_features): Add "qXfer:siginfo:read" and "qXfer:siginfo:write" features. (remote_xfer_partial): Handle TARGET_OBJECT_SIGNAL_INFO. (_initialize_remote): Add "set/show remote read-siginfo-object" and "set/show remote write-siginfo-object" commands. * Makefile.in (ALL_TARGET_OBS): Add linux-tdep.o. (HFILES_NO_SRCDIR): Add linux-tdep.h. (ALLDEPFILES): Add linux-tdep.c. * configure.tgt (arm*-*-linux* | arm*-*-uclinux*) (i[34567]86-*-linux*, x86_64-*-linux*): Add linux-tdep.o to gdb_target_obs. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/gdbserver/ * server.c (handle_query): Report qXfer:siginfo:read and qXfer:siginfo:write as supported and handle them. * target.h (struct target_ops) <qxfer_siginfo>: New field. * linux-low.c (linux_xfer_siginfo): New. (linux_target_ops): Set it. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/doc/ * gdb.texinfo (Signals): Document $_siginfo. (Convenience Variables): Mention $_siginfo. (Remote Configuration): Document qXfer:siginfo:read, qXfer:siginfo:write packets, and the read-siginfo-object, write-siginfo-object commands. 2009-02-06 Pedro Alves <pedro@codesourcery.com> gdb/testsuite/ * gdb.base/siginfo-obj.c, gdb.base/siginfo-obj.exp: New.
2009-02-06 23:59:01 +01:00
* target.h (struct target_ops): Make to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution methods instead of variables. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1) (target_has_registers_1, target_has_execution_1): Declare functions. (target_has_all_memory): Rewrite to call target_has_all_memory_1. (target_has_memory): Rewrite to call target_has_memory_1. (target_has_stack): Rewrite to call target_has_all_stack_1. (target_has_registers): Rewrite to call target_has_registers_1. (target_has_execution): Rewrite to call target_has_execution_1. (default_child_has_all_memory, default_child_has_memory) (default_child_has_stack, default_child_has_registers) (default_child_has_execution): Declare. (target_mark_running, target_mark_exited): Delete declarations. * target.c (default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution): New. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1, target_has_registers_1, target_has_execution_1): New. (add_target): Default the to_has_all_memory, to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution callbacks to return 0. (update_current_target): Do not inherit to_has_all_memory, to_has_memory, to_has_stack, to_has_registers or to_has_execution. (target_mark_running, target_mark_exited): Delete. (memory_xfer_partial): Adjust. (target_read_memory, target_write_memory, target_search_memory): Dispatch to the the top-most target, not the flattened current_target. (target_info): Adjust. (init_dummy_target): Install return_zero as callback for to_has_all_memory, to_has_memory, to_has_stack, to_has_registers, to_has_execution. (set_maintenance_target_async_permitted): Use have_live_inferiors instead of target_has_execution. * target-memory.c (target_write_memory_blocks): Dispatch memory writes to the the top-most target, not the flattened current_target. * breakpoint.c (insert_breakpoints): Don't check for target_has_execution here. (update_global_location_list): Check if there are live inferiors to debug instead of target_has_execution. * infcmd.c (kill_command, detach_command): Check if there are inferiors instead of target_has_execution. * inferior.h (have_live_inferiors): Declare. * inferior.c (have_live_inferiors): New. * infrun.c (normal_stop): Don't check for target_has_execution to finish the thread states. * thread.c (is_thread_state, is_stopped, is_exited, is_running) (any_running, is_executing): Remove checks for target_has_execution. * top.c (kill_or_detach): Don't try to kill core inferiors. (quit_target): Don't check for target_has_execution. * corelow.c (core_has_memory, core_has_stack, core_has_registers): New. (init_core_ops): Install core_has_memory, core_has_stack and core_has_registers. * exec.c (exec_has_memory): New. (init_exec_ops): Install exec_has_memory. * remote.c (remote_add_inferior): Don't call target_mark_running. (remote_start_remote): Don't call target_mark_exited or call target_mark_running. (remote_open_1): Use have_inferiors instead of target_has_execution. Don't use target_mark_exited. (init_remote_ops): Install deafult_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution. * bsd-kvm.c (bsd_kvm_return_one): New. (bsd_kvm_add_target): Register bsd_kvm_return_one as to_has_memory, to_has_stack and to_has_registers callbacks. * remote-m32r-sdi.c (m32r_return_one): New. (init_m32r_ops): Register it. * inf-child.c (inf_child_target): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * gnu-nat.c (init_gnu_ops): Likewise. * go32-nat.c (init_go32_ops): Likewise. * hpux-thread.c (init_hpux_thread_ops): Likewise. * monitor.c (init_base_monitor_ops): Likewise. * nto-procfs.c (init_procfs_ops): Likewise. * remote-mips.c (_initialize_remote_mips): Likewise. * windows-nat.c (init_windows_ops): Likewise. * remote-sim.c (gdbsim_create_inferior): Don't use target_mark_running or target_mark_exited. (gdbsim_mourn_inferior): Don't call target_mark_exited. (init_gdbsim_ops): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * linux-nat.c (linux_nat_xfer_partial): If reading memory, and there's no inferior selected, defer to a lower stratum.
2009-06-07 18:46:48 +02:00
/* The target is connected but no live inferior is selected. Pass
this request down to a lower stratum (e.g., the executable
file). */
if (object == TARGET_OBJECT_MEMORY && ptid_equal (inferior_ptid, null_ptid))
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
return TARGET_XFER_EOF;
* target.h (struct target_ops): Make to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution methods instead of variables. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1) (target_has_registers_1, target_has_execution_1): Declare functions. (target_has_all_memory): Rewrite to call target_has_all_memory_1. (target_has_memory): Rewrite to call target_has_memory_1. (target_has_stack): Rewrite to call target_has_all_stack_1. (target_has_registers): Rewrite to call target_has_registers_1. (target_has_execution): Rewrite to call target_has_execution_1. (default_child_has_all_memory, default_child_has_memory) (default_child_has_stack, default_child_has_registers) (default_child_has_execution): Declare. (target_mark_running, target_mark_exited): Delete declarations. * target.c (default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution): New. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1, target_has_registers_1, target_has_execution_1): New. (add_target): Default the to_has_all_memory, to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution callbacks to return 0. (update_current_target): Do not inherit to_has_all_memory, to_has_memory, to_has_stack, to_has_registers or to_has_execution. (target_mark_running, target_mark_exited): Delete. (memory_xfer_partial): Adjust. (target_read_memory, target_write_memory, target_search_memory): Dispatch to the the top-most target, not the flattened current_target. (target_info): Adjust. (init_dummy_target): Install return_zero as callback for to_has_all_memory, to_has_memory, to_has_stack, to_has_registers, to_has_execution. (set_maintenance_target_async_permitted): Use have_live_inferiors instead of target_has_execution. * target-memory.c (target_write_memory_blocks): Dispatch memory writes to the the top-most target, not the flattened current_target. * breakpoint.c (insert_breakpoints): Don't check for target_has_execution here. (update_global_location_list): Check if there are live inferiors to debug instead of target_has_execution. * infcmd.c (kill_command, detach_command): Check if there are inferiors instead of target_has_execution. * inferior.h (have_live_inferiors): Declare. * inferior.c (have_live_inferiors): New. * infrun.c (normal_stop): Don't check for target_has_execution to finish the thread states. * thread.c (is_thread_state, is_stopped, is_exited, is_running) (any_running, is_executing): Remove checks for target_has_execution. * top.c (kill_or_detach): Don't try to kill core inferiors. (quit_target): Don't check for target_has_execution. * corelow.c (core_has_memory, core_has_stack, core_has_registers): New. (init_core_ops): Install core_has_memory, core_has_stack and core_has_registers. * exec.c (exec_has_memory): New. (init_exec_ops): Install exec_has_memory. * remote.c (remote_add_inferior): Don't call target_mark_running. (remote_start_remote): Don't call target_mark_exited or call target_mark_running. (remote_open_1): Use have_inferiors instead of target_has_execution. Don't use target_mark_exited. (init_remote_ops): Install deafult_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution. * bsd-kvm.c (bsd_kvm_return_one): New. (bsd_kvm_add_target): Register bsd_kvm_return_one as to_has_memory, to_has_stack and to_has_registers callbacks. * remote-m32r-sdi.c (m32r_return_one): New. (init_m32r_ops): Register it. * inf-child.c (inf_child_target): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * gnu-nat.c (init_gnu_ops): Likewise. * go32-nat.c (init_go32_ops): Likewise. * hpux-thread.c (init_hpux_thread_ops): Likewise. * monitor.c (init_base_monitor_ops): Likewise. * nto-procfs.c (init_procfs_ops): Likewise. * remote-mips.c (_initialize_remote_mips): Likewise. * windows-nat.c (init_windows_ops): Likewise. * remote-sim.c (gdbsim_create_inferior): Don't use target_mark_running or target_mark_exited. (gdbsim_mourn_inferior): Don't call target_mark_exited. (init_gdbsim_ops): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * linux-nat.c (linux_nat_xfer_partial): If reading memory, and there's no inferior selected, defer to a lower stratum.
2009-06-07 18:46:48 +02:00
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
xfer = linux_ops->to_xfer_partial (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return xfer;
}
* corelow.c (get_core_registers): Adjust. (core_file_thread_alive): Rename to... (core_thread_alive): ... this. (core_pid_to_str): Try gdbarch_core_pid_to_str first. (init_core_ops): Adjust. (coreops_suppress_target): Delete. (_initialize_corelow): Unconditionally add core_ops. * procfs.c: Include "inf-child.h". (procfs_ops): Delete. (init_procfs_ops): Delete. Reimplement as... (procfs_target): ... this, inheriting from inf-child. (procfs_attach, procfs_detach, procfs_fetch_registers): Adjust. (procfs_prepare_to_store): Delete. (procfs_store_registers, procfs_resume): Adjust. (procfs_open): Delete. (procfs_suppress_run): Delete. (procfs_can_run): Delete. (procfs_mourn_inferior): Adjust. (procfs_init_inferior): Add target_ops parameter. Adjust. (procfs_create_inferior): Don't pass procfs_init_inferior to fork_inferior. Instead call it after fork_inferior returns. (procfs_find_new_threads): Adjust. (_initialize_procfs): Adjust to use procfs_target instead of init_procfs_ops. * sol-thread.c (orig_core_ops, sol_core_ops): Delete. (lwp_to_thread): Use target_thread_alive. (sol_thread_open): Delete. (sol_thread_attach): Delete. (sol_thread_detach, sol_thread_resume, sol_thread_wait) (sol_thread_fetch_registers, sol_thread_store_registers): Adjust to use find_target_beneath. (sol_thread_prepare_to_store, sol_thread_xfer_memory): Delete. (sol_thread_xfer_partial): Adjust to use find_target_beneath. (sol_thread_files_info, sol_thread_kill_inferior): Delete. (check_for_thread_db): New. (sol_thread_notice_signals, sol_thread_create_inferior): Delete. (sol_thread_new_objfile): Call check_for_thread_db. (sol_thread_mourn_inferior): Adjust to use find_target_beneath. (sol_thread_can_run): Delete. (sol_thread_alive): Adjust to use find_target_beneath. (sol_thread_stop): Delete. (rw_common): Use target_write_memory or target_read_memory. (ps_lgetregs, ps_lgetfpregs): Use target_fetch_registers. (ps_lsetregs, ps_lsetfpregs): Use target_store_registers. (solaris_pid_to_str): Remove check for libthread_db initialization failing. (sol_find_new_threads): Remove check for libthread_db initialization failing, or for an invalid inferior_ptid. Adjust to use find_target_beneath. (sol_core_open, sol_core_close, sol_core_detach, sol_core_files_info, sol_find_memory_regions, sol_make_note_section, ignore): Delete. (init_sol_thread_ops): Make it a thread_stratum target. Remove unneeded callback settings. (init_sol_core_ops): Delete. (_initialize_sol_thread): No longer call init_sol_core_ops, set procfs_suppress_run, or hack with core_ops. * target.h (struct target_ops): Add a target_ops * parameter to to_resume, to_fetch_registers, to_store_registers, to_thread_alive and to_find_new_threads. (target_fetch_registers, target_store_registers) (target_thread_alive, target_find_new_threads): Redeclare as function. * target.c (update_current_target): Do not inherit or de_fault to_resume, to_fetch_registers, to_store_registers, to_thread_alive, to_find_new_threads. (target_resume): Adjust. (target_thread_alive, target_find_new_threads): New. (debug_to_resume, debug_to_fetch_registers): Delete. (target_fetch_registers): New. (debug_to_store_registers): Delete. (target_store_registers): New. (debug_to_thread_alive, debug_to_find_new_threads): Delete. (setup_target_debug): Adjust. * gdbcore.h (core_ops): Delete declaration. * inf-ptrace.c, linux-nat.c, remote.c, amd64-linux-nat.c, inf-child.c, linux-thread-db.c, bsd-uthread.c, inf-ttrace.c, i386-sol2-tdep.c, darwin-nat.c, gnu-nat.c, go32-nat.c, hpux-thread.c, i386-linux-nat.c, i386fbsd-nat.c, monitor.c, nto-procfs.c, remote-m32r-sdi.c, remote-mips.c, windows-nat.c, alphabsd-nat.c, amd64bsd-nat.c, arm-linux-nat.c, armnbsd-nat.c, bsd-kvm.c, hppa-hpux-nat.c, hppa-linux-nat.c, hppabsd-nat.c, hppanbsd-nat.c, i386-darwin-nat.c, i386bsd-nat.c, ia64-linux-nat.c, m32r-linux-nat.c, m68kbsd-nat.c, m68klinux-nat.c, m88kbsd-nat.c, mips-linux-nat.c, mips64obsd-nat.c, mipsnbsd-nat.c, ppc-linux-nat.c, ppcnbsd-nat.c, ppcobsd-nat.c, remote-sim.c, rs6000-nat.c, s390-nat.c, shnbsd-nat.c, sparc-nat.c, sparc-nat.h, spu-linux-nat.c, vaxbsd-nat.c, xtensa-linux-nat.c: Adjust to target_ops changes. * gdbarch.sh (core_pid_to_str): New gdbarch callback. * gdbarch.h, gdbarch.c: Regenerate. * sol2-tdep.c: Include "inferior.h". (sol2_core_pid_to_str): New. * sol2-tdep.h (sol2_core_pid_to_str): Declare. * amd64-sol2-tdep.c (amd64_sol2_init_abi): Set it. * sparc-sol2-tdep.c (sparc32_sol2_init_abi): Set it. * sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Set it. * i386-sol2-tdep.c (i386_sol2_init_abi): Set it.
2009-02-23 01:03:50 +01:00
static int
linux_nat_thread_alive (struct target_ops *ops, ptid_t ptid)
{
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
/* As long as a PTID is in lwp list, consider it alive. */
return find_lwp_pid (ptid) != NULL;
* corelow.c (get_core_registers): Adjust. (core_file_thread_alive): Rename to... (core_thread_alive): ... this. (core_pid_to_str): Try gdbarch_core_pid_to_str first. (init_core_ops): Adjust. (coreops_suppress_target): Delete. (_initialize_corelow): Unconditionally add core_ops. * procfs.c: Include "inf-child.h". (procfs_ops): Delete. (init_procfs_ops): Delete. Reimplement as... (procfs_target): ... this, inheriting from inf-child. (procfs_attach, procfs_detach, procfs_fetch_registers): Adjust. (procfs_prepare_to_store): Delete. (procfs_store_registers, procfs_resume): Adjust. (procfs_open): Delete. (procfs_suppress_run): Delete. (procfs_can_run): Delete. (procfs_mourn_inferior): Adjust. (procfs_init_inferior): Add target_ops parameter. Adjust. (procfs_create_inferior): Don't pass procfs_init_inferior to fork_inferior. Instead call it after fork_inferior returns. (procfs_find_new_threads): Adjust. (_initialize_procfs): Adjust to use procfs_target instead of init_procfs_ops. * sol-thread.c (orig_core_ops, sol_core_ops): Delete. (lwp_to_thread): Use target_thread_alive. (sol_thread_open): Delete. (sol_thread_attach): Delete. (sol_thread_detach, sol_thread_resume, sol_thread_wait) (sol_thread_fetch_registers, sol_thread_store_registers): Adjust to use find_target_beneath. (sol_thread_prepare_to_store, sol_thread_xfer_memory): Delete. (sol_thread_xfer_partial): Adjust to use find_target_beneath. (sol_thread_files_info, sol_thread_kill_inferior): Delete. (check_for_thread_db): New. (sol_thread_notice_signals, sol_thread_create_inferior): Delete. (sol_thread_new_objfile): Call check_for_thread_db. (sol_thread_mourn_inferior): Adjust to use find_target_beneath. (sol_thread_can_run): Delete. (sol_thread_alive): Adjust to use find_target_beneath. (sol_thread_stop): Delete. (rw_common): Use target_write_memory or target_read_memory. (ps_lgetregs, ps_lgetfpregs): Use target_fetch_registers. (ps_lsetregs, ps_lsetfpregs): Use target_store_registers. (solaris_pid_to_str): Remove check for libthread_db initialization failing. (sol_find_new_threads): Remove check for libthread_db initialization failing, or for an invalid inferior_ptid. Adjust to use find_target_beneath. (sol_core_open, sol_core_close, sol_core_detach, sol_core_files_info, sol_find_memory_regions, sol_make_note_section, ignore): Delete. (init_sol_thread_ops): Make it a thread_stratum target. Remove unneeded callback settings. (init_sol_core_ops): Delete. (_initialize_sol_thread): No longer call init_sol_core_ops, set procfs_suppress_run, or hack with core_ops. * target.h (struct target_ops): Add a target_ops * parameter to to_resume, to_fetch_registers, to_store_registers, to_thread_alive and to_find_new_threads. (target_fetch_registers, target_store_registers) (target_thread_alive, target_find_new_threads): Redeclare as function. * target.c (update_current_target): Do not inherit or de_fault to_resume, to_fetch_registers, to_store_registers, to_thread_alive, to_find_new_threads. (target_resume): Adjust. (target_thread_alive, target_find_new_threads): New. (debug_to_resume, debug_to_fetch_registers): Delete. (target_fetch_registers): New. (debug_to_store_registers): Delete. (target_store_registers): New. (debug_to_thread_alive, debug_to_find_new_threads): Delete. (setup_target_debug): Adjust. * gdbcore.h (core_ops): Delete declaration. * inf-ptrace.c, linux-nat.c, remote.c, amd64-linux-nat.c, inf-child.c, linux-thread-db.c, bsd-uthread.c, inf-ttrace.c, i386-sol2-tdep.c, darwin-nat.c, gnu-nat.c, go32-nat.c, hpux-thread.c, i386-linux-nat.c, i386fbsd-nat.c, monitor.c, nto-procfs.c, remote-m32r-sdi.c, remote-mips.c, windows-nat.c, alphabsd-nat.c, amd64bsd-nat.c, arm-linux-nat.c, armnbsd-nat.c, bsd-kvm.c, hppa-hpux-nat.c, hppa-linux-nat.c, hppabsd-nat.c, hppanbsd-nat.c, i386-darwin-nat.c, i386bsd-nat.c, ia64-linux-nat.c, m32r-linux-nat.c, m68kbsd-nat.c, m68klinux-nat.c, m88kbsd-nat.c, mips-linux-nat.c, mips64obsd-nat.c, mipsnbsd-nat.c, ppc-linux-nat.c, ppcnbsd-nat.c, ppcobsd-nat.c, remote-sim.c, rs6000-nat.c, s390-nat.c, shnbsd-nat.c, sparc-nat.c, sparc-nat.h, spu-linux-nat.c, vaxbsd-nat.c, xtensa-linux-nat.c: Adjust to target_ops changes. * gdbarch.sh (core_pid_to_str): New gdbarch callback. * gdbarch.h, gdbarch.c: Regenerate. * sol2-tdep.c: Include "inferior.h". (sol2_core_pid_to_str): New. * sol2-tdep.h (sol2_core_pid_to_str): Declare. * amd64-sol2-tdep.c (amd64_sol2_init_abi): Set it. * sparc-sol2-tdep.c (sparc32_sol2_init_abi): Set it. * sparc64-sol2-tdep.c (sparc64_sol2_init_abi): Set it. * i386-sol2-tdep.c (i386_sol2_init_abi): Set it.
2009-02-23 01:03:50 +01:00
}
update thread list, delete exited threads On GNU/Linux, if the running kernel supports clone events, then linux-thread-db.c defers thread listing to the target beneath: static void thread_db_update_thread_list (struct target_ops *ops) { ... if (target_has_execution && !thread_db_use_events ()) ops->beneath->to_update_thread_list (ops->beneath); else thread_db_update_thread_list_td_ta_thr_iter (ops); ... } However, when live debugging, the target beneath, linux-nat.c, does not implement the to_update_thread_list method. The result is that if a thread is marked exited (because it can't be deleted right now, e.g., it was the selected thread), then it won't ever be deleted, until the process exits or is killed/detached. A similar thing happens with the remote.c target. Because its target_update_thread_list implementation skips exited threads when it walks the current thread list looking for threads that no longer exits on the target side, using ALL_NON_EXITED_THREADS_SAFE, stale exited threads are never deleted. This is not a big deal -- I can't think of any way this might be user visible, other than gdb's memory growing a tiny bit whenever a thread gets stuck in exited state. Still, might as well clean things up properly. All other targets use prune_threads, so are unaffected. The fix adds a ALL_THREADS_SAFE macro, that like ALL_NON_EXITED_THREADS_SAFE, walks the thread list and allows deleting the iterated thread, and uses that in places that are walking the thread list in order to delete threads. Actually, after converting linux-nat.c and remote.c to use this, we find the only other user of ALL_NON_EXITED_THREADS_SAFE is also walking the list to delete threads. So we convert that too, and end up deleting ALL_NON_EXITED_THREADS_SAFE. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog 2015-04-07 Pedro Alves <palves@redhat.com> * gdbthread.h (ALL_NON_EXITED_THREADS_SAFE): Rename to ... (ALL_THREADS_SAFE): ... this, and don't skip exited threads. (delete_exited_threads): New declaration. * infrun.c (follow_exec): Use ALL_THREADS_SAFE. * linux-nat.c (linux_nat_update_thread_list): New function. (linux_nat_add_target): Install it. * remote.c (remote_update_thread_list): Use ALL_THREADS_SAFE. * thread.c (prune_threads): Use ALL_THREADS_SAFE. (delete_exited_threads): New function.
2015-04-07 16:47:22 +02:00
/* Implement the to_update_thread_list target method for this
target. */
static void
linux_nat_update_thread_list (struct target_ops *ops)
{
Fix PR threads/19354: "info threads" error with multiple inferiors Note: this applies on top of: [PATCH] Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL https://sourceware.org/ml/gdb-patches/2015-12/msg00214.html We try to avoid using libthread_db.so to list threads in the inferior when debugging live processes, but the code that decides whether to use it decides incorrectly if you have more than one inferior, and the current inferior doesn't have execution yet. The result is visible as: (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 15397 /home/pedro/gdb/tests/threads * 2 <null> (gdb) info threads Cannot find new threads: generic error (gdb) Fix this by checking whether each inferior has execution rather than just the current inferior. By moving the core updating to linux-nat.c's update_thread_list implementation, this also ends up fixing the lwp-last-seen-running-on-core updating in the case we're debugging a program that uses raw clone rather than pthreads, as linux-thread-db.c isn't pushed in the target stack in that scenario. Tested on x86_64 Fedora 20. gdb/ChangeLog: 2015-12-17 Pedro Alves <palves@redhat.com> PR threads/19354 * linux-nat.c (linux_nat_update_thread_list): Update process cores each lwp was last seen running on here. * linux-thread-db.c (update_thread_core): Delete. (thread_db_update_thread_list_td_ta_thr_iter): Rename to ... (thread_db_update_thread_list): ... this. Skip inferiors with execution. Also call the target beneath. (thread_db_update_thread_list): Delete. gdb/testsuite/ChangeLog: 2015-12-17 Pedro Alves <palves@redhat.com> PR threads/19354 * gdb.multi/info-threads.exp: New file.
2015-12-17 15:20:52 +01:00
struct lwp_info *lwp;
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
/* We add/delete threads from the list as clone/exit events are
processed, so just try deleting exited threads still in the
thread list. */
delete_exited_threads ();
Fix PR threads/19354: "info threads" error with multiple inferiors Note: this applies on top of: [PATCH] Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL https://sourceware.org/ml/gdb-patches/2015-12/msg00214.html We try to avoid using libthread_db.so to list threads in the inferior when debugging live processes, but the code that decides whether to use it decides incorrectly if you have more than one inferior, and the current inferior doesn't have execution yet. The result is visible as: (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 15397 /home/pedro/gdb/tests/threads * 2 <null> (gdb) info threads Cannot find new threads: generic error (gdb) Fix this by checking whether each inferior has execution rather than just the current inferior. By moving the core updating to linux-nat.c's update_thread_list implementation, this also ends up fixing the lwp-last-seen-running-on-core updating in the case we're debugging a program that uses raw clone rather than pthreads, as linux-thread-db.c isn't pushed in the target stack in that scenario. Tested on x86_64 Fedora 20. gdb/ChangeLog: 2015-12-17 Pedro Alves <palves@redhat.com> PR threads/19354 * linux-nat.c (linux_nat_update_thread_list): Update process cores each lwp was last seen running on here. * linux-thread-db.c (update_thread_core): Delete. (thread_db_update_thread_list_td_ta_thr_iter): Rename to ... (thread_db_update_thread_list): ... this. Skip inferiors with execution. Also call the target beneath. (thread_db_update_thread_list): Delete. gdb/testsuite/ChangeLog: 2015-12-17 Pedro Alves <palves@redhat.com> PR threads/19354 * gdb.multi/info-threads.exp: New file.
2015-12-17 15:20:52 +01:00
/* Update the processor core that each lwp/thread was last seen
running on. */
ALL_LWPS (lwp)
{
/* Avoid accessing /proc if the thread hasn't run since we last
time we fetched the thread's core. Accessing /proc becomes
noticeably expensive when we have thousands of LWPs. */
if (lwp->core == -1)
lwp->core = linux_common_core_of_thread (lwp->ptid);
}
update thread list, delete exited threads On GNU/Linux, if the running kernel supports clone events, then linux-thread-db.c defers thread listing to the target beneath: static void thread_db_update_thread_list (struct target_ops *ops) { ... if (target_has_execution && !thread_db_use_events ()) ops->beneath->to_update_thread_list (ops->beneath); else thread_db_update_thread_list_td_ta_thr_iter (ops); ... } However, when live debugging, the target beneath, linux-nat.c, does not implement the to_update_thread_list method. The result is that if a thread is marked exited (because it can't be deleted right now, e.g., it was the selected thread), then it won't ever be deleted, until the process exits or is killed/detached. A similar thing happens with the remote.c target. Because its target_update_thread_list implementation skips exited threads when it walks the current thread list looking for threads that no longer exits on the target side, using ALL_NON_EXITED_THREADS_SAFE, stale exited threads are never deleted. This is not a big deal -- I can't think of any way this might be user visible, other than gdb's memory growing a tiny bit whenever a thread gets stuck in exited state. Still, might as well clean things up properly. All other targets use prune_threads, so are unaffected. The fix adds a ALL_THREADS_SAFE macro, that like ALL_NON_EXITED_THREADS_SAFE, walks the thread list and allows deleting the iterated thread, and uses that in places that are walking the thread list in order to delete threads. Actually, after converting linux-nat.c and remote.c to use this, we find the only other user of ALL_NON_EXITED_THREADS_SAFE is also walking the list to delete threads. So we convert that too, and end up deleting ALL_NON_EXITED_THREADS_SAFE. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog 2015-04-07 Pedro Alves <palves@redhat.com> * gdbthread.h (ALL_NON_EXITED_THREADS_SAFE): Rename to ... (ALL_THREADS_SAFE): ... this, and don't skip exited threads. (delete_exited_threads): New declaration. * infrun.c (follow_exec): Use ALL_THREADS_SAFE. * linux-nat.c (linux_nat_update_thread_list): New function. (linux_nat_add_target): Install it. * remote.c (remote_update_thread_list): Use ALL_THREADS_SAFE. * thread.c (prune_threads): Use ALL_THREADS_SAFE. (delete_exited_threads): New function.
2015-04-07 16:47:22 +02:00
}
-Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info -Wwrite-strings flagged a missing cast for example here: static char * ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp) { return "Ravenscar task"; Since callers are not supposed to free the string returned by these methods, change the methods' signature to return const strings. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * aix-thread.c (aix_thread_pid_to_str) (aix_thread_extra_thread_info): Constify. * bsd-kvm.c (bsd_kvm_pid_to_str): Constify. * bsd-uthread.c (bsd_uthread_extra_thread_info) (bsd_uthread_pid_to_str): Constify. * corelow.c (core_pid_to_str): Constify. * darwin-nat.c (darwin_pid_to_str): Constify. * fbsd-nat.c (fbsd_pid_to_str): Constify. * fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str): Constify. * gnu-nat.c (gnu_pid_to_str): Constify. * go32-nat.c (go32_pid_to_str): Constify. * i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify. * inf-ptrace.c (inf_ptrace_pid_to_str): Constify. * inferior.c (inferior_pid_to_str): Constify. * linux-nat.c (linux_nat_pid_to_str): Constify. * linux-tdep.c (linux_core_pid_to_str): Constify. * linux-thread-db.c (thread_db_pid_to_str) (thread_db_extra_thread_info): Constify. * nto-tdep.c (nto_extra_thread_info): Constify. * nto-tdep.h (nto_extra_thread_info): Constify. * obsd-nat.c (obsd_pid_to_str): Constify. * procfs.c (procfs_pid_to_str): Constify. * ravenscar-thread.c (ravenscar_extra_thread_info) (ravenscar_pid_to_str): Constify. * remote-sim.c (gdbsim_pid_to_str): Constify. * remote.c (remote_threads_extra_info, remote_pid_to_str): Constify. * sol-thread.c (solaris_pid_to_str): Constify. * sol2-tdep.c (sol2_core_pid_to_str): Constify. * sol2-tdep.h (sol2_core_pid_to_str): Constify. * target.c (default_pid_to_str, target_pid_to_str) (normal_pid_to_str, default_pid_to_str): Constify. * target.h (target_ops::to_pid_to_str) (target_ops::to_extra_thread_info): Constify. (target_pid_to_str, normal_pid_to_str): Constify. * windows-nat.c (windows_pid_to_str): Constify. * gdbarch.sh (core_pid_to_str): Constify. * target-delegates.c: Regenerate. * gdbarch.h, gdbarch.c: Regenerate.
2017-04-05 20:21:34 +02:00
static const char *
* linux-nat.c (linux_nat_wait): Adjust. (linux_nat_pid_to_str): Adjust. Remove call to thread_db_init. * linux-nat.h (thread_db_init): Delete declaration. * linux-thread-db.c (target_beneath): Delete. (thread_db_init): Delete. (thread_db_detach): Use find_target_beneath. (thread_db_wait): Adjust interface. Use find_target_beneath. (thread_db_mourn_inferior): Use find_target_beneath. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): Delete. (thread_db_pid_to_str): Adjust interface. Use find_target_beneath. (thread_db_get_thread_local_address): Adjust interface. Use find_target_beneath. (init_thread_db_ops): Delete references to delete functions. * target.c (update_current_target): Don't inherit or default to_wait. Don't inherit to_pid_to_str and to_get_thread_local_address. (target_translate_tls_address): Look for a pushed target that implements to_get_thread_local_address, and use it instead of checking for target_get_thread_local_address_p. (target_wait, target_pid_to_str): Reimplement as functions. (dummy_pid_to_str): New. (init_dummy_target): Register it. (debug_to_wait): Delete. * target.h (struct target_ops): Make to_wait, to_pid_to_str and to_get_thread_local_address accept a pointer to struct target_ops. (target_wait): Delete macro, and declare as function. (target_pid_to_str): Likewise. (target_get_thread_local_address) (target_get_thread_local_address_p): Delete. (noprocess): Add NORETURN and ATTR_NORETURN tags. * inf-ptrace.c (inf_ptrace_wait): Adjust. (inf_ptrace_pid_to_str): New. (inf_ptrace_target): Use inf_ptrace_pid_to_str. * aix-thread.c (aix_thread_wait, aix_thread_pid_to_str): Adjust. * bsd-kvm.c (bsd_kvm_pid_to_str): Adjust. * bsd-uthread.c (bsd_uthread_wait, bsd_uthread_pid_to_str): Adjust. * corelow.c (core_pid_to_str): Adjust. * darwin-nat.c (darwin_wait, darwin_pid_to_str): Adjust. * dec-thread.c (dec_thread_wait, dec_thread_pid_to_str): Adjust. * gnu-nat.c (gnu_wait, gnu_pid_to_str): Adjust. * go32-nat.c (go32_wait, go32_pid_to_str): Adjust. * hpux-thread.c (hpux_thread_wait): Adjust. * inf-ttrace.c (inf_ttrace_wait, inf_ttrace_pid_to_str): Adjust. * monitor.c (monitor_wait, monitor_pid_to_str): Adjust. * nto-procfs.c (procfs_wait, procfs_pid_to_str): Adjust. * procfs.c (procfs_pid_to_str): Adjust. * remote-m32r-sdi.c (m32r_wait, m32r_pid_to_str): Adjust. * remote-mips.c (mips_wait): Adjust. * remote-sim.c (gdbsim_wait, gdbsim_pid_to_str): Adjust. * remote.c (remote_wait, remote_pid_to_str) (remote_get_thread_local_address): Adjust. * rs6000-nat.c (rs6000_wait): Adjust. * sol-thread.c (procfs_pid_to_str): Adjust declaration. (sol_thread_wait, solaris_pid_to_str): Adjust. * spu-linux-nat.c (spu_child_wait): Adjust. * windows-nat.c (windows_wait, windows_pid_to_str): Adjust.
2009-02-06 23:21:26 +01:00
linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid)
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
static char buf[64];
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (ptid_lwp_p (ptid)
&& (ptid_get_pid (ptid) != ptid_get_lwp (ptid)
|| num_lwps (ptid_get_pid (ptid)) > 1))
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
{
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
snprintf (buf, sizeof (buf), "LWP %ld", ptid_get_lwp (ptid));
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
return buf;
}
return normal_pid_to_str (ptid);
}
static const char *
linux_nat_thread_name (struct target_ops *self, struct thread_info *thr)
{
return linux_proc_tid_get_name (thr->ptid);
}
/* Accepts an integer PID; Returns a string representing a file that
can be opened to get the symbols for the child process. */
static char *
linux_child_pid_to_exec_file (struct target_ops *self, int pid)
{
return linux_proc_pid_to_exec_file (pid);
}
/* Implement the to_xfer_partial target method using /proc/<pid>/mem.
Because we can use a single read/write call, this can be much more
efficient than banging away at PTRACE_PEEKTEXT. */
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
{
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
LONGEST ret;
int fd;
char filename[64];
if (object != TARGET_OBJECT_MEMORY)
Mostly trivial enum fixes This is a patch I extracted from Pedro's C++ branch. It contains the most trivial enum fixes, where an integer type/value was used instead of the appropriate enum type/value. It fixes many C++ errors, since in C++ you can't mix integers and enums implicitely. Regardless of the C++ conversion, I think this is a good cleanup to make use of the appropriate enum types. Regression-tested on native x86_64. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_linux_can_use_hw_breakpoint): Use enum type or value instead of integer. (aarch64_linux_insert_watchpoint): Likewise. (aarch64_linux_remove_watchpoint): Likewise. * ada-lang.c (ada_op_print_tab): Likewise. * amd64-linux-tdep.c (amd64_canonicalize_syscall): Likewise. (amd64_linux_syscall_record_common): Likewise. * arch-utils.c (target_byte_order_user): Likewise. (default_byte_order): Likewise. * arm-linux-nat.c (arm_linux_can_use_hw_breakpoint): Likewise. (arm_linux_get_hwbp_type): Likewise. (arm_linux_hw_watchpoint_initialize): Likewise. (arm_linux_insert_watchpoint): Likewise. * arm-linux-tdep.c (arm_canonicalize_syscall): Likewise. (arm_linux_syscall_record): Likewise. * breakpoint.c (update_watchpoint): Likewise. (breakpoint_here_p): Likewise. (bpstat_print): Likewise. (enable_breakpoint_disp): Likewise. * c-lang.c (c_op_print_tab): Likewise. * cli/cli-decode.c (add_info_alias): Likewise. * d-lang.c (d_op_print_tab): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * f-exp.y (dot_ops): Likewise. (f77_keywords): Likewise. * f-lang.c (f_op_print_tab): Likewise. * go-lang.c (go_op_print_tab): Likewise. * guile/scm-breakpoint.c (gdbscm_make_breakpoint): Likewise. * guile/scm-cmd.c (gdbscm_make_command): Likewise. * guile/scm-param.c (gdbscm_make_parameter): Likewise. * guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Likewise. * guile/scm-string.c (struct scm_to_stringn_data): Likewise. (struct scm_from_stringn_data): Likewise. * i386-linux-tdep.c (i386_canonicalize_syscall): Likewise. * ia64-linux-nat.c (ia64_linux_insert_watchpoint): Likewise. (ia64_linux_remove_watchpoint): Likewise. (ia64_linux_can_use_hw_breakpoint): Likewise. * infrun.c (print_stop_event): Likewise. * jv-lang.c (java_op_print_tab): Likewise. * linux-nat.c (linux_proc_xfer_partial): Likewise. * linux-nat.h (struct lwp_info): Likewise. * linux-thread-db.c (enable_thread_event): Likewise. * m2-lang.c (m2_op_print_tab): Likewise. * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Likewise. (mi_cmd_stack_list_variables): Likewise. * mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise. * mi/mi-out.c (mi_table_begin): Likewise. (mi_table_header): Likewise. * mips-linux-nat.c (mips_linux_can_use_hw_breakpoint): Likewise. (mips_linux_insert_watchpoint): Likewise. (mips_linux_remove_watchpoint): Likewise. * nat/mips-linux-watch.c (mips_linux_watch_type_to_irw): Likewise. * nat/mips-linux-watch.h (struct mips_watchpoint): Likewise. (mips_linux_watch_type_to_irw): Likewise. * nto-procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_hw_watchpoint): Likewise. (procfs_can_use_hw_breakpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. * p-lang.c (pascal_op_print_tab): Likewise. * ppc-linux-nat.c (ppc_linux_can_use_hw_breakpoint): Likewise. * ppc-linux-tdep.c (ppu2spu_unwind_register): Likewise. * ppc-sysv-tdep.c (get_decimal_float_return_value): Likewise. * procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_watchpoint): Likewise. (procfs_remove_watchpoint): Likewise. * psymtab.c (recursively_search_psymtabs): Likewise. * remote-m32r-sdi.c (m32r_can_use_hw_watchpoint): Likewise. (m32r_insert_watchpoint): Likewise. * remote-mips.c (mips_can_use_watchpoint): Likewise. (mips_insert_watchpoint): Likewise. (mips_remove_watchpoint): Likewise. * remote.c (watchpoint_to_Z_packet): Likewise. (remote_insert_watchpoint): Likewise. (remote_remove_watchpoint): Likewise. (remote_check_watch_resources): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. (s390_remove_watchpoint): Likewise. (s390_can_use_hw_breakpoint): Likewise. * s390-linux-tdep.c (s390_gdbarch_init): Likewise. * spu-linux-nat.c (spu_can_use_hw_breakpoint): Likewise. * target.h (struct target_ops): Likewise. * tilegx-tdep.c (tilegx_analyze_prologue): Likewise. * ui-out.c (struct ui_out_hdr): Likewise. (append_header_to_list): Likewise. (get_next_header): Likewise. (verify_field): Likewise. (ui_out_begin): Likewise. (ui_out_field_int): Likewise. (ui_out_field_fmt_int): Likewise. (ui_out_field_skip): Likewise. (ui_out_field_string): Likewise. (ui_out_field_fmt): Likewise. * varobj.c (new_variable): Likewise. * x86-nat.c (x86_insert_watchpoint): Likewise. (x86_remove_watchpoint): Likewise. (x86_can_use_hw_breakpoint): Likewise. * xtensa-tdep.h (struct gdbarch_tdep): Likewise. * inflow.c (enum gdb_has_a_terminal_flag_enum): Add name to previously anonymous enumeration type.. * linux-record.h (enum gdb_syscall): Add gdb_sys_no_syscall value. * target-debug.h (target_debug_print_enum_target_hw_bp_type): New. (target_debug_print_enum_bptype): New. * target-delegates.c: Regenerate.
2015-07-31 19:19:53 +02:00
return TARGET_XFER_EOF;
/* Don't bother for one word. */
if (len < 3 * sizeof (long))
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
return TARGET_XFER_EOF;
/* We could keep this file open and cache it - possibly one per
thread. That requires some juggling, but is even faster. */
xsnprintf (filename, sizeof filename, "/proc/%ld/mem",
ptid_get_lwp (inferior_ptid));
fd = gdb_open_cloexec (filename, ((readbuf ? O_RDONLY : O_WRONLY)
| O_LARGEFILE), 0);
if (fd == -1)
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
return TARGET_XFER_EOF;
/* Use pread64/pwrite64 if available, since they save a syscall and can
handle 64-bit offsets even on 32-bit platforms (for instance, SPARC
debugging a SPARC64 application). */
#ifdef HAVE_PREAD64
ret = (readbuf ? pread64 (fd, readbuf, len, offset)
: pwrite64 (fd, writebuf, len, offset));
#else
ret = lseek (fd, offset, SEEK_SET);
if (ret != -1)
ret = (readbuf ? read (fd, readbuf, len)
: write (fd, writebuf, len));
#endif
close (fd);
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
if (ret == -1 || ret == 0)
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
return TARGET_XFER_EOF;
else
{
*xfered_len = ret;
return TARGET_XFER_OK;
}
}
/* Enumerate spufs IDs for process PID. */
static LONGEST
Change to_xfer_partial 'len' type to ULONGEST. This patch changes to_xfer_partial's len's type to ULONGEST, and adjust its implementations. gdb: 2014-01-14 Yao Qi <yao@codesourcery.com> * target.h (target_xfer_partial_ftype): Update. (struct target_ops) <to_xfer_partial>: Change 'len' type to ULONGEST. * aix-thread.c (aix_thread_xfer_partial): Change type of argument 'len' to ULONGEST. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv): Likewise. (memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_write_inferior): Likewise. Use '%u'. (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Call pulongest instead of plongest. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory): Likewise. (ia64_hpux_xfer_solib_got): Likewise. (ia64_hpux_xfer_partial): Likewise. * ia64-linux-nat.c (ia64_linux_xfer_partial): * inf-ptrace.c (inf_ptrace_xfer_partial): * inf-ttrace.c (inf_ttrace_xfer_partial): * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_nat_xfer_partial): Likewise. (spu_enumerate_spu_ids, linux_proc_xfer_spu): Likewise. (linux_nat_xfer_osdata, linux_xfer_partial): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. Call pulongest instead of plongest. (gdbsim_xfer_partial): Likewise. * remote.c (remote_xfer_partial): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. * rs6000-aix-tdep.h (rs6000_aix_ld_info_to_xml): Update declaration. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * target.c (target_read_live_memory): Likewise. (memory_xfer_live_readonly_partial): Likewise. (memory_xfer_partial, memory_xfer_partial_1): Likewise. (target_xfer_partial, default_xfer_partial): Likewise. (current_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. Call pulongest instead of plongest. (windows_xfer_partial): Likewise. (windows_xfer_shared_libraries): Likewise.
2014-01-03 14:11:46 +01:00
spu_enumerate_spu_ids (int pid, gdb_byte *buf, ULONGEST offset, ULONGEST len)
{
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
LONGEST pos = 0;
LONGEST written = 0;
char path[128];
DIR *dir;
struct dirent *entry;
xsnprintf (path, sizeof path, "/proc/%d/fd", pid);
dir = opendir (path);
if (!dir)
return -1;
rewinddir (dir);
while ((entry = readdir (dir)) != NULL)
{
struct stat st;
struct statfs stfs;
int fd;
fd = atoi (entry->d_name);
if (!fd)
continue;
xsnprintf (path, sizeof path, "/proc/%d/fd/%d", pid, fd);
if (stat (path, &st) != 0)
continue;
if (!S_ISDIR (st.st_mode))
continue;
if (statfs (path, &stfs) != 0)
continue;
if (stfs.f_type != SPUFS_MAGIC)
continue;
if (pos >= offset && pos + 4 <= offset + len)
{
store_unsigned_integer (buf + pos - offset, 4, byte_order, fd);
written += 4;
}
pos += 4;
}
closedir (dir);
return written;
}
/* Implement the to_xfer_partial interface for the TARGET_OBJECT_SPU
object type, using the /proc file system. */
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
linux_proc_xfer_spu (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
char buf[128];
int fd = 0;
int ret = -1;
int pid = ptid_get_lwp (inferior_ptid);
if (!annex)
{
if (!readbuf)
Replace -1 with TARGET_XFER_E_IO Hi, This patch replaces -1 with TARGET_XFER_E_IO in the implementations of to_xfer_partial and their callees. This change is quite mechanical, and makes the next patch shorter. gdb: 2014-02-07 Yao Qi <yao@codesourcery.com> * auxv.c (procfs_xfer_auxv): Replace -1 with TARGET_XFER_E_IO. (ld_so_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (exec_xfer_partial): Likewise. * gnu-nat.c (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_uregs): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_proc_xfer_spu): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_qxfer): Likewise. (remote_write_qxfer, remote_read_qxfer): Likewise. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * target.c (memory_xfer_partial_1): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise.
2014-01-27 10:32:33 +01:00
return TARGET_XFER_E_IO;
else
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
{
LONGEST l = spu_enumerate_spu_ids (pid, readbuf, offset, len);
if (l < 0)
return TARGET_XFER_E_IO;
else if (l == 0)
return TARGET_XFER_EOF;
else
{
*xfered_len = (ULONGEST) l;
return TARGET_XFER_OK;
}
}
}
xsnprintf (buf, sizeof buf, "/proc/%d/fd/%s", pid, annex);
PR gdb/7912: * Makefile.in (SFILES): Add filestuff.c (COMMON_OBS): Add filestuff.o. (filestuff.o): New target. * auto-load.c (auto_load_objfile_script_1): Use gdb_fopen_cloexec. * auxv.c (procfs_xfer_auxv): Use gdb_open_cloexec. * cli/cli-cmds.c (shell_escape): Call close_most_fds. * cli/cli-dump.c (fopen_with_cleanup): Use gdb_fopen_cloexec. * common/agent.c (gdb_connect_sync_socket): Use gdb_socket_cloexec. * common/filestuff.c: New file. * common/filestuff.h: New file. * common/linux-osdata.c (linux_common_core_of_thread) (command_from_pid, commandline_from_pid, print_source_lines) (linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Use gdb_fopen_cloexec. * common/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_has_state): Use gdb_fopen_cloexec. * config.in, configure: Rebuild. * configure.ac: Don't check for sys/socket.h. Check for fdwalk, pipe2. * corelow.c (core_open): Use gdb_open_cloexec. * dwarf2read.c (write_psymtabs_to_index): Use gdb_fopen_cloexec. * fork-child.c (fork_inferior): Call close_most_fds. * gdb_bfd.c (gdb_bfd_open): Use gdb_open_cloexec. * inf-child.c (inf_child_fileio_readlink): Use gdb_open_cloexec. * linux-nat.c (linux_nat_thread_name, linux_proc_pending_signals): Use gdb_fopen_cloexec. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use gdb_open_cloexec. (linux_async_pipe): Use gdb_pipe_cloexec. * remote-fileio.c (remote_fileio_func_open): Use gdb_open_cloexec. * remote.c (remote_file_put, remote_file_get): Use gdb_fopen_cloexec. * ser-pipe.c (pipe_open): Use gdb_socketpair_cloexec, close_most_fds. * ser-tcp.c (net_open): Use gdb_socket_cloexec. * ser-unix.c (hardwire_open): Use gdb_open_cloexec. * solib.c (solib_find): Use gdb_open_cloexec. * source.c (openp, find_and_open_source): Use gdb_open_cloexec. * tracepoint.c (tfile_start): Use gdb_fopen_cloexec. (tfile_open): Use gdb_open_cloexec. * tui/tui-io.c (tui_initialize_io): Use gdb_pipe_cloexec. * ui-file.c (gdb_fopen): Use gdb_fopen_cloexec. * xml-support.c (xml_fetch_content_from_file): Use gdb_fopen_cloexec. * main.c (captured_main): Call notice_open_fds. gdbserver * Makefile.in (SFILES): Add filestuff.c. (OBS): Add filestuff.o. (filestuff.o): New target. * config.in, configure: Rebuild. * configure.ac: Check for fdwalk, pipe2.
2013-04-22 18:46:15 +02:00
fd = gdb_open_cloexec (buf, writebuf? O_WRONLY : O_RDONLY, 0);
if (fd <= 0)
Replace -1 with TARGET_XFER_E_IO Hi, This patch replaces -1 with TARGET_XFER_E_IO in the implementations of to_xfer_partial and their callees. This change is quite mechanical, and makes the next patch shorter. gdb: 2014-02-07 Yao Qi <yao@codesourcery.com> * auxv.c (procfs_xfer_auxv): Replace -1 with TARGET_XFER_E_IO. (ld_so_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. (darwin_xfer_partial): Likewise. * exec.c (exec_xfer_partial): Likewise. * gnu-nat.c (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_uregs): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo): Likewise. (linux_proc_xfer_spu): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_qxfer): Likewise. (remote_write_qxfer, remote_read_qxfer): Likewise. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. (spu_xfer_partial): Likewise. * target.c (memory_xfer_partial_1): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise.
2014-01-27 10:32:33 +01:00
return TARGET_XFER_E_IO;
if (offset != 0
&& lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
{
close (fd);
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
return TARGET_XFER_EOF;
}
if (writebuf)
ret = write (fd, writebuf, (size_t) len);
else if (readbuf)
ret = read (fd, readbuf, (size_t) len);
close (fd);
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
if (ret < 0)
return TARGET_XFER_E_IO;
else if (ret == 0)
return TARGET_XFER_EOF;
else
{
*xfered_len = (ULONGEST) ret;
return TARGET_XFER_OK;
}
}
/* Parse LINE as a signal set and add its set bits to SIGS. */
static void
add_line_to_sigset (const char *line, sigset_t *sigs)
{
int len = strlen (line) - 1;
const char *p;
int signum;
if (line[len] != '\n')
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
error (_("Could not parse signal set: %s"), line);
p = line;
signum = len * 4;
while (len-- > 0)
{
int digit;
if (*p >= '0' && *p <= '9')
digit = *p - '0';
else if (*p >= 'a' && *p <= 'f')
digit = *p - 'a' + 10;
else
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
error (_("Could not parse signal set: %s"), line);
signum -= 4;
if (digit & 1)
sigaddset (sigs, signum + 1);
if (digit & 2)
sigaddset (sigs, signum + 2);
if (digit & 4)
sigaddset (sigs, signum + 3);
if (digit & 8)
sigaddset (sigs, signum + 4);
p++;
}
}
/* Find process PID's pending signals from /proc/pid/status and set
SIGS to match. */
void
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
linux_proc_pending_signals (int pid, sigset_t *pending,
sigset_t *blocked, sigset_t *ignored)
{
FILE *procfile;
Normalize on PATH_MAX instead of MAXPATHLEN throughout. With the pathmax gnulib module in place, we can use PATH_MAX consistently throughout, instead of the current mixbag of PATH_MAX and MAXPATHLEN uses. It's no longer necessary to include sys/param.h (supposedly, I can't check all ports touched here) for MAXPATHLEN. Don't remove sys/param.h from GDB's configure.ac, as later tests in the file use HAVE_SYS_PARAM_H checks. Tested on x86_64 Fedora 17. Also cross-built for --host=i686-w64-mingw32, and --host=i586-pc-msdosdjgpp. gdb/ 2013-07-01 Pedro Alves <palves@redhat.com> * defs.h: Include "pathmax.h". * utils.c: Don't include sys/param.h. (gdb_realpath): Remove code that checks for MAXPATHLEN. * solib-ia64-hpux.c (ia64_hpux_handle_load_event): Use PATH_MAX instead of MAXPATHLEN. * solib-sunos.c: Don't include sys/param.h. * xcoffread.c: Don't include sys/param.h. * bsd-kvm.c: Don't include sys/param.h. * darwin-nat.c: Don't include sys/param.h. (darwin_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * darwin-nat-info.c: Don't include sys/param.h. * fbsd-nat.c (fbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * i386obsd-nat.c: Don't include sys/param.h. * inf-child.c: Don't include sys/param.h. (inf_child_fileio_readlink): Use PATH_MAX instead of MAXPATHLEN. * linux-fork.c: Don't include sys/param.h. (fork_save_infrun_state): Use PATH_MAX instead of MAXPATHLEN. * linux-nat.c: Don't include sys/param.h. (linux_child_pid_to_exec_file, linux_proc_pending_signals) (linux_proc_pending_signals): Use PATH_MAX instead of MAXPATHLEN. * m68klinux-nat.c: Don't include sys/param.h. * nbsd-nat.c: Don't include sys/param.h. (nbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * ppc-linux-nat.c: Don't include sys/param.h. * rs6000-nat.c: Don't include sys/param.h. * spu-linux-nat.c. Don't include sys/param.h. * windows-nat.c: Don't include sys/param.h. * xtensa-linux-nat.c: Don't include sys/param.h. * config/i386/nm-fbsd.h: Don't include sys/param.h. gdb/gdbserver/ 2013-07-01 Pedro Alves <palves@redhat.com> * server.h: Include "pathmax.h". * linux-low.c: Don't include sys/param.h. (linux_pid_exe_is_elf_64_file): Use PATH_MAX instead of MAXPATHLEN. * win32-low.c: Don't include sys/param.h. (win32_create_inferior): Use PATH_MAX instead of MAXPATHLEN.
2013-07-01 13:28:30 +02:00
char buffer[PATH_MAX], fname[PATH_MAX];
struct cleanup *cleanup;
sigemptyset (pending);
sigemptyset (blocked);
sigemptyset (ignored);
xsnprintf (fname, sizeof fname, "/proc/%d/status", pid);
PR gdb/7912: * Makefile.in (SFILES): Add filestuff.c (COMMON_OBS): Add filestuff.o. (filestuff.o): New target. * auto-load.c (auto_load_objfile_script_1): Use gdb_fopen_cloexec. * auxv.c (procfs_xfer_auxv): Use gdb_open_cloexec. * cli/cli-cmds.c (shell_escape): Call close_most_fds. * cli/cli-dump.c (fopen_with_cleanup): Use gdb_fopen_cloexec. * common/agent.c (gdb_connect_sync_socket): Use gdb_socket_cloexec. * common/filestuff.c: New file. * common/filestuff.h: New file. * common/linux-osdata.c (linux_common_core_of_thread) (command_from_pid, commandline_from_pid, print_source_lines) (linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Use gdb_fopen_cloexec. * common/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_has_state): Use gdb_fopen_cloexec. * config.in, configure: Rebuild. * configure.ac: Don't check for sys/socket.h. Check for fdwalk, pipe2. * corelow.c (core_open): Use gdb_open_cloexec. * dwarf2read.c (write_psymtabs_to_index): Use gdb_fopen_cloexec. * fork-child.c (fork_inferior): Call close_most_fds. * gdb_bfd.c (gdb_bfd_open): Use gdb_open_cloexec. * inf-child.c (inf_child_fileio_readlink): Use gdb_open_cloexec. * linux-nat.c (linux_nat_thread_name, linux_proc_pending_signals): Use gdb_fopen_cloexec. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use gdb_open_cloexec. (linux_async_pipe): Use gdb_pipe_cloexec. * remote-fileio.c (remote_fileio_func_open): Use gdb_open_cloexec. * remote.c (remote_file_put, remote_file_get): Use gdb_fopen_cloexec. * ser-pipe.c (pipe_open): Use gdb_socketpair_cloexec, close_most_fds. * ser-tcp.c (net_open): Use gdb_socket_cloexec. * ser-unix.c (hardwire_open): Use gdb_open_cloexec. * solib.c (solib_find): Use gdb_open_cloexec. * source.c (openp, find_and_open_source): Use gdb_open_cloexec. * tracepoint.c (tfile_start): Use gdb_fopen_cloexec. (tfile_open): Use gdb_open_cloexec. * tui/tui-io.c (tui_initialize_io): Use gdb_pipe_cloexec. * ui-file.c (gdb_fopen): Use gdb_fopen_cloexec. * xml-support.c (xml_fetch_content_from_file): Use gdb_fopen_cloexec. * main.c (captured_main): Call notice_open_fds. gdbserver * Makefile.in (SFILES): Add filestuff.c. (OBS): Add filestuff.o. (filestuff.o): New target. * config.in, configure: Rebuild. * configure.ac: Check for fdwalk, pipe2.
2013-04-22 18:46:15 +02:00
procfile = gdb_fopen_cloexec (fname, "r");
if (procfile == NULL)
2005-02-10 Andrew Cagney <cagney@gnu.org> Mark up all error and warning messages. * ada-lang.c, amd64-tdep.c, arch-utils.c, breakpoint.c: Update. * bsd-kvm.c, bsd-uthread.c, coff-solib.h, coffread.c: Update. * core-aout.c, core-regset.c, corefile.c, corelow.c: Update. * cp-abi.c, cp-support.c, cp-valprint.c, cris-tdep.c: Update. * dbxread.c, demangle.c, doublest.c, dsrec.c: Update. * dve3900-rom.c, dwarf2expr.c, dwarf2loc.c: Update. * dwarf2read.c, dwarfread.c, elfread.c, eval.c: Update. * event-top.c, exec.c, expprint.c, f-lang.c: Update. * f-typeprint.c, f-valprint.c, fbsd-nat.c, findvar.c: Update. * frame.c, frv-linux-tdep.c, gcore.c, gdbtypes.c: Update. * gnu-nat.c, gnu-v2-abi.c, gnu-v3-abi.c, go32-nat.c: Update. * hpacc-abi.c, hppa-hpux-nat.c, hppa-hpux-tdep.c: Update. * hppa-linux-nat.c, hppa-linux-tdep.c, hppa-tdep.c: Update. * hpread.c, hpux-thread.c, i386-linux-nat.c: Update. * i386-linux-tdep.c, i386-tdep.c, i386bsd-nat.c: Update. * i386gnu-nat.c, i387-tdep.c, ia64-linux-nat.c: Update. * ia64-tdep.c, inf-child.c, inf-ptrace.c, inf-ttrace.c: Update. * infcall.c, infcmd.c, inflow.c, infptrace.c, infrun.c: Update. * inftarg.c, interps.c, irix5-nat.c, jv-lang.c: Update. * kod-cisco.c, kod.c, language.c, libunwind-frame.c: Update. * linespec.c, linux-nat.c, linux-thread-db.c, m2-lang.c: Update. * m32r-rom.c, m68hc11-tdep.c, m68k-tdep.c: Update. * m68klinux-nat.c, macrocmd.c, macroexp.c, main.c: Update. * maint.c, mdebugread.c, mem-break.c, memattr.c: Update. * mips-linux-tdep.c, mips-tdep.c, mipsread.c, monitor.c: Update. * nlmread.c, nto-procfs.c, objc-lang.c, objfiles.c: Update. * observer.c, ocd.c, p-lang.c, p-typeprint.c: Update. * p-valprint.c, pa64solib.c, parse.c, ppc-linux-tdep.c: Update. * ppcnbsd-tdep.c, printcmd.c, procfs.c, remote-e7000.c: Update. * remote-fileio.c, remote-m32r-sdi.c, remote-rdi.c: Update. * remote-rdp.c, remote-sim.c, remote-st.c: Update. * remote-utils.c, remote-utils.h, remote.c: Update. * rom68k-rom.c, rs6000-nat.c, s390-tdep.c, scm-lang.c: Update. * ser-e7kpc.c, ser-tcp.c, ser-unix.c, sh-tdep.c: Update. * sh3-rom.c, shnbsd-tdep.c, sol-thread.c, solib-aix5.c: Update. * solib-frv.c, solib-irix.c, solib-osf.c, solib-pa64.c: Update. * solib-som.c, solib-sunos.c, solib-svr4.c, solib.c: Update. * somread.c, somsolib.c, source.c, stabsread.c: Update. * stack.c, std-regs.c, symfile-mem.c, symfile.c: Update. * symmisc.c, symtab.c, target.c, thread.c, top.c: Update. * tracepoint.c, trad-frame.c, typeprint.c, utils.c: Update. * uw-thread.c, valarith.c, valops.c, valprint.c: Update. * value.c, varobj.c, version.in, win32-nat.c, wince.c: Update. * xcoffread.c, xcoffsolib.c, cli/cli-cmds.c: Update. * cli/cli-decode.c, cli/cli-dump.c, cli/cli-logging.c: Update. * cli/cli-script.c, cli/cli-setshow.c, mi/mi-cmd-break.c: Update. * mi/mi-cmd-disas.c, mi/mi-cmd-env.c, mi/mi-cmd-file.c: Update. * mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-getopt.c: Update. * mi/mi-symbol-cmds.c, tui/tui-layout.c, tui/tui-stack.c: Update. * tui/tui-win.c: Update.
2005-02-11 05:06:14 +01:00
error (_("Could not open %s"), fname);
cleanup = make_cleanup_fclose (procfile);
Normalize on PATH_MAX instead of MAXPATHLEN throughout. With the pathmax gnulib module in place, we can use PATH_MAX consistently throughout, instead of the current mixbag of PATH_MAX and MAXPATHLEN uses. It's no longer necessary to include sys/param.h (supposedly, I can't check all ports touched here) for MAXPATHLEN. Don't remove sys/param.h from GDB's configure.ac, as later tests in the file use HAVE_SYS_PARAM_H checks. Tested on x86_64 Fedora 17. Also cross-built for --host=i686-w64-mingw32, and --host=i586-pc-msdosdjgpp. gdb/ 2013-07-01 Pedro Alves <palves@redhat.com> * defs.h: Include "pathmax.h". * utils.c: Don't include sys/param.h. (gdb_realpath): Remove code that checks for MAXPATHLEN. * solib-ia64-hpux.c (ia64_hpux_handle_load_event): Use PATH_MAX instead of MAXPATHLEN. * solib-sunos.c: Don't include sys/param.h. * xcoffread.c: Don't include sys/param.h. * bsd-kvm.c: Don't include sys/param.h. * darwin-nat.c: Don't include sys/param.h. (darwin_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * darwin-nat-info.c: Don't include sys/param.h. * fbsd-nat.c (fbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * i386obsd-nat.c: Don't include sys/param.h. * inf-child.c: Don't include sys/param.h. (inf_child_fileio_readlink): Use PATH_MAX instead of MAXPATHLEN. * linux-fork.c: Don't include sys/param.h. (fork_save_infrun_state): Use PATH_MAX instead of MAXPATHLEN. * linux-nat.c: Don't include sys/param.h. (linux_child_pid_to_exec_file, linux_proc_pending_signals) (linux_proc_pending_signals): Use PATH_MAX instead of MAXPATHLEN. * m68klinux-nat.c: Don't include sys/param.h. * nbsd-nat.c: Don't include sys/param.h. (nbsd_pid_to_exec_file): Use PATH_MAX instead of MAXPATHLEN. * ppc-linux-nat.c: Don't include sys/param.h. * rs6000-nat.c: Don't include sys/param.h. * spu-linux-nat.c. Don't include sys/param.h. * windows-nat.c: Don't include sys/param.h. * xtensa-linux-nat.c: Don't include sys/param.h. * config/i386/nm-fbsd.h: Don't include sys/param.h. gdb/gdbserver/ 2013-07-01 Pedro Alves <palves@redhat.com> * server.h: Include "pathmax.h". * linux-low.c: Don't include sys/param.h. (linux_pid_exe_is_elf_64_file): Use PATH_MAX instead of MAXPATHLEN. * win32-low.c: Don't include sys/param.h. (win32_create_inferior): Use PATH_MAX instead of MAXPATHLEN.
2013-07-01 13:28:30 +02:00
while (fgets (buffer, PATH_MAX, procfile) != NULL)
{
/* Normal queued signals are on the SigPnd line in the status
file. However, 2.6 kernels also have a "shared" pending
queue for delivering signals to a thread group, so check for
a ShdPnd line also.
Unfortunately some Red Hat kernels include the shared pending
queue but not the ShdPnd status field. */
if (startswith (buffer, "SigPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
else if (startswith (buffer, "ShdPnd:\t"))
add_line_to_sigset (buffer + 8, pending);
else if (startswith (buffer, "SigBlk:\t"))
add_line_to_sigset (buffer + 8, blocked);
else if (startswith (buffer, "SigIgn:\t"))
add_line_to_sigset (buffer + 8, ignored);
}
do_cleanups (cleanup);
}
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
linux_nat_xfer_osdata (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len)
{
gdb_assert (object == TARGET_OBJECT_OSDATA);
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
*xfered_len = linux_common_xfer_osdata (annex, readbuf, offset, len);
if (*xfered_len == 0)
return TARGET_XFER_EOF;
else
return TARGET_XFER_OK;
}
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
static enum target_xfer_status
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
linux_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
ULONGEST *xfered_len)
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
{
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
enum target_xfer_status xfer;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
if (object == TARGET_OBJECT_AUXV)
return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
if (object == TARGET_OBJECT_OSDATA)
return linux_nat_xfer_osdata (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
if (object == TARGET_OBJECT_SPU)
return linux_proc_xfer_spu (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
/* GDB calculates all the addresses in possibly larget width of the address.
Address width needs to be masked before its final use - either by
linux_proc_xfer_partial or inf_ptrace_xfer_partial.
Compare ADDR_BIT first to avoid a compiler warning on shift overflow. */
if (object == TARGET_OBJECT_MEMORY)
{
int addr_bit = gdbarch_addr_bit (target_gdbarch ());
if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT))
offset &= ((ULONGEST) 1 << addr_bit) - 1;
}
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
if (xfer != TARGET_XFER_EOF)
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
return xfer;
return super_xfer_partial (ops, object, annex, readbuf, writebuf,
Return target_xfer_status in to_xfer_partial This patch does the conversion of to_xfer_partial from LONGEST (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len); to enum target_xfer_status (*to_xfer_partial) (struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len); It changes to_xfer_partial return the transfer status and the transfered length by *XFERED_LEN. Generally, the return status has three stats, - TARGET_XFER_OK, - TARGET_XFER_EOF, - TARGET_XFER_E_XXXX, See the comments to them in 'enum target_xfer_status'. Note that Pedro suggested not name TARGET_XFER_DONE, as it is confusing, compared with "TARGET_XFER_OK". We finally name it TARGET_XFER_EOF. With this change, GDB core can handle unavailable data in a convenient way. The rationale behind this change was mentioned here https://sourceware.org/ml/gdb-patches/2013-10/msg00761.html Consider an object/value like this: 0 100 150 200 512 DDDDDDDDDDDxxxxxxxxxDDDDDD...DDIIIIIIIIIIII..III where D is valid data, and xxx is unavailable data, and I is beyond the end of the object (Invalid). Currently, if we start the xfer at 0, requesting, say 512 bytes, we'll first get back 100 bytes. The xfer machinery then retries fetching [100,512), and gets back TARGET_XFER_E_UNAVAILABLE. That's sufficient when you're either interested in either having the whole of the 512 bytes available, or erroring out. But, in this scenario, we're interested in the data at [150,512). The problem is that the last TARGET_XFER_E_UNAVAILABLE gives us no indication where to start the read next. We'd need something like: get me [0,512) >>> <<< here's [0,100), *xfered_len is 100, returns TARGET_XFER_OK get me [100,512) >>> (**1) <<< [100,150) is unavailable, *xfered_len is 50, return TARGET_XFER_E_UNAVAILABLE. get me [150,512) >>> <<< here's [150,200), *xfered_len is 50, return TARGET_XFER_OK. get me [200,512) >>> <<< no more data, return TARGET_XFER_EOF. This naturally implies pushing down the decision of whether to return TARGET_XFER_E_UNAVAILABLE or something else down to the target. (Which kinds of leads back to tfile itself reading from RO memory from file (though we could export a function in exec.c for that that tfile delegates to, instead of re-adding the old code). Beside this change, we also add a macro TARGET_XFER_STATUS_ERROR_P to check whether a status is an error or not, to stop using "status < 0". This patch also eliminates the comparison between status and 0. No target implementations to to_xfer_partial adapts this new interface. The interface still behaves as before. gdb: 2014-02-11 Yao Qi <yao@codesourcery.com> * target.h (enum target_xfer_error): Rename to ... (enum target_xfer_status): ... it. New. All users updated. (enum target_xfer_status) <TARGET_XFER_OK>, <TARGET_XFER_EOF>: New. (TARGET_XFER_STATUS_ERROR_P): New macro. (target_xfer_error_to_string): Remove declaration. (target_xfer_status_to_string): Declare. (target_xfer_partial_ftype): Adjust it. (struct target_ops) <to_xfer_partial>: Return target_xfer_status. Add argument xfered_len. Update comments. * target.c (target_xfer_error_to_string): Rename to ... (target_xfer_status_to_string): ... it. New. All callers updated. (target_read_live_memory): Likewise. Call target_xfer_partial instead of target_read. (memory_xfer_live_readonly_partial): Return target_xfer_status. Add argument xfered_len. (raw_memory_xfer_partial): Likewise. (memory_xfer_partial_1): Likewise. (memory_xfer_partial): Likewise. (target_xfer_partial): Likewise. Check *XFERED_LEN is set properly. Update debug message. (default_xfer_partial, current_xfer_partial): Likewise. (target_write_partial): Likewise. (target_read_partial): Likewise. All callers updated. (read_whatever_is_readable): Likewise. (target_write_with_progress): Likewise. (target_read_alloc_1): Likewise. * aix-thread.c (aix_thread_xfer_partial): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. (ld_so_xfer_auxv, memory_xfer_auxv): Likewise. * bfd-target.c (target_bfd_xfer_partial): Likewise. * bsd-kvm.c (bsd_kvm_xfer_partial): Likewise. * bsd-uthread.c (bsd_uthread_xfer_partia): Likewise. * corefile.c (read_memory): Adjust. * corelow.c (core_xfer_partial): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * darwin-nat.c (darwin_read_dyld_info): Likewise. All callers updated. (darwin_xfer_partial): Likewise. * exec.c (section_table_xfer_memory_partial): Likewise. All callers updated. (exec_xfer_partial): Likewise. * exec.h (section_table_xfer_memory_partial): Update declaration. * gnu-nat.c (gnu_xfer_memory): Likewise. Assert 'res' is not negative. (gnu_xfer_partial): Likewise. * ia64-hpux-nat.c (ia64_hpux_xfer_memory_no_bs): Likewise. (ia64_hpux_xfer_memory, ia64_hpux_xfer_uregs): Likewise. (ia64_hpux_xfer_solib_got): Likewise. * inf-ptrace.c (inf_ptrace_xfer_partial): Likewise. Change type of 'partial_len' to ULONGEST. * inf-ttrace.c (inf_ttrace_xfer_partial): Likewise. * linux-nat.c (linux_xfer_siginfo ): Likewise. (linux_nat_xfer_partial): Likewise. (linux_proc_xfer_partial, linux_xfer_partial): Likewise. (linux_proc_xfer_spu, linux_nat_xfer_osdata): Likewise. * monitor.c (monitor_xfer_memory): Likewise. (monitor_xfer_partial): Likewise. * procfs.c (procfs_xfer_partial): Likewise. * record-btrace.c (record_btrace_xfer_partial): Likewise. * record-full.c (record_full_xfer_partial): Likewise. (record_full_core_xfer_partial): Likewise. * remote-sim.c (gdbsim_xfer_memory): Likewise. (gdbsim_xfer_partial): Likewise. * remote.c (remote_write_bytes_aux): Likewise. All callers updated. (remote_write_bytes, remote_read_bytes): Likewise. All callers updated. (remote_flash_erase): Likewise. All callers updated. (remote_write_qxfer): Likewise. All callers updated. (remote_read_qxfer): Likewise. All callers updated. (remote_xfer_partial): Likewise. * rs6000-nat.c (rs6000_xfer_partial): Likewise. (rs6000_xfer_shared_libraries): Likewise. * sol-thread.c (sol_thread_xfer_partial): Likewise. (sol_thread_xfer_partial): Likewise. * sparc-nat.c (sparc_xfer_wcookie): Likewise. (sparc_xfer_partial): Likewise. * spu-linux-nat.c (spu_proc_xfer_spu): Likewise. All callers updated. (spu_xfer_partial): Likewise. * spu-multiarch.c (spu_xfer_partial): Likewise. * tracepoint.c (tfile_xfer_partial): Likewise. * windows-nat.c (windows_xfer_memory): Likewise. (windows_xfer_shared_libraries): Likewise. (windows_xfer_partial): Likewise. * valprint.c: Replace 'target_xfer_error' with 'target_xfer_status' in comments.
2014-01-27 13:35:33 +01:00
offset, len, xfered_len);
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
}
static void
cleanup_target_stop (void *arg)
{
ptid_t *ptid = (ptid_t *) arg;
gdb_assert (arg != NULL);
/* Unpause all */
target_continue_no_signal (*ptid);
}
static VEC(static_tracepoint_marker_p) *
linux_child_static_tracepoint_markers_by_strid (struct target_ops *self,
const char *strid)
{
char s[IPA_CMD_BUF_SIZE];
struct cleanup *old_chain;
int pid = ptid_get_pid (inferior_ptid);
VEC(static_tracepoint_marker_p) *markers = NULL;
struct static_tracepoint_marker *marker = NULL;
char *p = s;
ptid_t ptid = ptid_build (pid, 0, 0);
/* Pause all */
target_stop (ptid);
memcpy (s, "qTfSTM", sizeof ("qTfSTM"));
s[sizeof ("qTfSTM")] = 0;
agent_run_command (pid, s, strlen (s) + 1);
old_chain = make_cleanup (free_current_marker, &marker);
make_cleanup (cleanup_target_stop, &ptid);
while (*p++ == 'm')
{
if (marker == NULL)
marker = XCNEW (struct static_tracepoint_marker);
do
{
parse_static_tracepoint_marker_definition (p, &p, marker);
if (strid == NULL || strcmp (strid, marker->str_id) == 0)
{
VEC_safe_push (static_tracepoint_marker_p,
markers, marker);
marker = NULL;
}
else
{
release_static_tracepoint_marker (marker);
memset (marker, 0, sizeof (*marker));
}
}
while (*p++ == ','); /* comma-separated list */
memcpy (s, "qTsSTM", sizeof ("qTsSTM"));
s[sizeof ("qTsSTM")] = 0;
agent_run_command (pid, s, strlen (s) + 1);
p = s;
}
do_cleanups (old_chain);
return markers;
}
/* Create a prototype generic GNU/Linux target. The client can override
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
it with local methods. */
* linux-nat.c (linux_register_u_offset): Remove. (linux_target_install_ops): New function. (linux_target): Use it. (linux_trad_target): New function. * linux-nat.h (linux_trad_target): Declare. * alpha-linux-nat.c: Include "gdbcore.h". (alpha_linux_register_u_offset): New function. (_initialize_alpha_linux_nat): Use linux_trad_target. * mips-linux-nat.c: Include "gdbcore.h". (mips_linux_register_u_offset): New function. (_initialize_mips_linux_nat): Use linux_trad_target. * config/arm/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/arm/nm-linux.h: Delete file. * config/i386/nm-linux64.h (FETCH_INFERIOR_REGISTERS): Remove. * config/i386/nm-linux.h (FETCH_INFERIOR_REGISTERS): Remove. * config/ia64/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/ia64/nm-linux.h: Delete file. * config/m32r/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m32r/nm-linux.h: Delete file. * config/m68k/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m68k/nm-linux.h: Delete file. * config/pa/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/pa/nm-linux.h: Delete file. * config/powerpc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/powerpc/ppc64-linux.mh (NAT_FILE): Likewise. * config/powerpc/nm-linux.h: Delete file. * config/s390/s390.mh (NAT_FILE): Set to config/nm-linux.h. * config/s390/nm-linux.h: Delete file. * config/sparc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/sparc/linux64.mh (NAT_FILE): Likewise. * config/sparc/nm-linux.h: Delete file. * Makefile.in (alpha-linux-nat.o): Update dependencies. (mips-linux-nat.o): Likewise.
2007-04-26 00:17:48 +02:00
static void
linux_target_install_ops (struct target_ops *t)
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
{
t->to_insert_fork_catchpoint = linux_child_insert_fork_catchpoint;
t->to_remove_fork_catchpoint = linux_child_remove_fork_catchpoint;
t->to_insert_vfork_catchpoint = linux_child_insert_vfork_catchpoint;
t->to_remove_vfork_catchpoint = linux_child_remove_vfork_catchpoint;
t->to_insert_exec_catchpoint = linux_child_insert_exec_catchpoint;
t->to_remove_exec_catchpoint = linux_child_remove_exec_catchpoint;
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
t->to_set_syscall_catchpoint = linux_child_set_syscall_catchpoint;
t->to_pid_to_exec_file = linux_child_pid_to_exec_file;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
t->to_post_startup_inferior = linux_child_post_startup_inferior;
t->to_post_attach = linux_child_post_attach;
t->to_follow_fork = linux_child_follow_fork;
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
super_xfer_partial = t->to_xfer_partial;
t->to_xfer_partial = linux_xfer_partial;
t->to_static_tracepoint_markers_by_strid
= linux_child_static_tracepoint_markers_by_strid;
* linux-nat.c (linux_register_u_offset): Remove. (linux_target_install_ops): New function. (linux_target): Use it. (linux_trad_target): New function. * linux-nat.h (linux_trad_target): Declare. * alpha-linux-nat.c: Include "gdbcore.h". (alpha_linux_register_u_offset): New function. (_initialize_alpha_linux_nat): Use linux_trad_target. * mips-linux-nat.c: Include "gdbcore.h". (mips_linux_register_u_offset): New function. (_initialize_mips_linux_nat): Use linux_trad_target. * config/arm/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/arm/nm-linux.h: Delete file. * config/i386/nm-linux64.h (FETCH_INFERIOR_REGISTERS): Remove. * config/i386/nm-linux.h (FETCH_INFERIOR_REGISTERS): Remove. * config/ia64/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/ia64/nm-linux.h: Delete file. * config/m32r/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m32r/nm-linux.h: Delete file. * config/m68k/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m68k/nm-linux.h: Delete file. * config/pa/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/pa/nm-linux.h: Delete file. * config/powerpc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/powerpc/ppc64-linux.mh (NAT_FILE): Likewise. * config/powerpc/nm-linux.h: Delete file. * config/s390/s390.mh (NAT_FILE): Set to config/nm-linux.h. * config/s390/nm-linux.h: Delete file. * config/sparc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/sparc/linux64.mh (NAT_FILE): Likewise. * config/sparc/nm-linux.h: Delete file. * Makefile.in (alpha-linux-nat.o): Update dependencies. (mips-linux-nat.o): Likewise.
2007-04-26 00:17:48 +02:00
}
struct target_ops *
linux_target (void)
{
struct target_ops *t;
t = inf_ptrace_target ();
linux_target_install_ops (t);
return t;
}
struct target_ops *
linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int))
* linux-nat.c (linux_register_u_offset): Remove. (linux_target_install_ops): New function. (linux_target): Use it. (linux_trad_target): New function. * linux-nat.h (linux_trad_target): Declare. * alpha-linux-nat.c: Include "gdbcore.h". (alpha_linux_register_u_offset): New function. (_initialize_alpha_linux_nat): Use linux_trad_target. * mips-linux-nat.c: Include "gdbcore.h". (mips_linux_register_u_offset): New function. (_initialize_mips_linux_nat): Use linux_trad_target. * config/arm/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/arm/nm-linux.h: Delete file. * config/i386/nm-linux64.h (FETCH_INFERIOR_REGISTERS): Remove. * config/i386/nm-linux.h (FETCH_INFERIOR_REGISTERS): Remove. * config/ia64/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/ia64/nm-linux.h: Delete file. * config/m32r/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m32r/nm-linux.h: Delete file. * config/m68k/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/m68k/nm-linux.h: Delete file. * config/pa/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/pa/nm-linux.h: Delete file. * config/powerpc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/powerpc/ppc64-linux.mh (NAT_FILE): Likewise. * config/powerpc/nm-linux.h: Delete file. * config/s390/s390.mh (NAT_FILE): Set to config/nm-linux.h. * config/s390/nm-linux.h: Delete file. * config/sparc/linux.mh (NAT_FILE): Set to config/nm-linux.h. * config/sparc/linux64.mh (NAT_FILE): Likewise. * config/sparc/nm-linux.h: Delete file. * Makefile.in (alpha-linux-nat.o): Update dependencies. (mips-linux-nat.o): Likewise.
2007-04-26 00:17:48 +02:00
{
struct target_ops *t;
t = inf_ptrace_trad_target (register_u_offset);
linux_target_install_ops (t);
* Makefile.in (ALLDEPFILES): Update. (alpha-linux-nat.o, sparc-linux-nat.o): New rules. (amd64-linux-nat.o, arm-linux-nat.o, hppa-linux-nat.o) (i386-linux-nat.o, ia64-linux-nat.o, linux-nat.o, m32r-linux-nat.o) (m68klinux-nat.o, mips-linux-nat.o, ppc-linux-nat.o, s390-nat.o) (sparc64-linux-nat.o): Update dependencies. * alpha-linux-nat.c, sparc-linux-nat.c: New files. * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (amd64_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (amd64_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_amd64_linux_nat): Set it. Call linux_target and add_target. * arm-linux-nat.c (arm_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (arm_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_arm_linux_nat): Add a prototype. Use linux_target and add_target. * hppa-linux-nat.c (hppa_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (hppa_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_hppa_linux_nat): New function. * i386-linux-nat.c (i386_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (i386_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (i386_linux_resume): Renamed from child_resume and made static. (i386_linux_child_post_start_inferior): Renamed from child_post_startup_inferior and made static. Call super_post_startup_inferior. (super_post_startup_inferior): New. (_initialize_i386_linux_nat): New function. * i386-nat.c: Remove LINUX_CHILD_POST_STARTUP_INFERIOR #ifndef. * ia64-linux-nat.c (ia64_linux_xfer_unwind_table): Remove. (super_xfer_partial): New. (ia64_linux_xfer_partial): New function. Use it. (_initialize_ia64_linux_nat): New function. * ia64-tdep.c (getunwind_table): Revert 2005-06-08 change; use target_read_partial and document the problem. * inf-ptrace.c (inf_ptrace_fetch_register): Use CANNOT_FETCH_REGISTER. Fix some comments. (inf_ptrace_store_register): Use CANNOT_STORE_REGISTER. Fix some comments. * linux-nat.c: Include "inf-ptrace.h" and "auxv.h". (linux_ops, super_xfer_partial): New variables. (linux_child_post_startup_inferior): Make static. (child_post_startup_inferior): Delete. (linux_nat_attach, linux_nat_detach, resume_callback) (linux_nat_resume, linux_nat_wait, linux_nat_create_inferior) (linux_nat_mourn_inferior): Use linux_ops instead of deprecated_child_ops. (child_wait): Do not depend on CHILD_WAIT. (linux_nat_xfer_memory): Remove, replace by ... (linux_nat_xfer_partial): ... this. Use linux_ops->to_xfer_partial instead of linux_proc_xfer_memory and child_xfer_memory. (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior): New functions. (init_linux_nat_ops): Use the new functions. (linux_proc_xfer_memory): Remove, replace by ... (linux_proc_xfer_partial): ... this. Make static. (linux_xfer_partial, linux_register_u_offset, linux_target): New functions. (_initialize_linux_nat): Do not modify deprecated_child_ops. * linux-nat.h (linux_proc_xfer_memory): Remove prototype. (struct mem_attrib, struct target_ops): Remove forward declarations. (linux_child_post_startup_inferior): Remove prototype. (linux_target): Add prototype. * linux-thread-db.c (thread_db_xfer_memory): Remove, replace by ... (thread_db_xfer_partial): ... this. (init_thread_db_ops): Set to_xfer_partial instead of deprecated_xfer_memory. * m32r-linux-nat.c (m32r_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m32r_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_m32r_linux_nat): New function. * m68klinux-nat.c (m68k_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (m68k_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (old_fetch_inferior_registers, old_store_inferior_registers): Made static. (_initialize_m68k_linux_nat): Use linux_target and add_target. * mips-linux-nat.c (_initialize_mips_linux_nat): New function. * ppc-linux-nat.c (ppc_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (ppc_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_ppc_linux_nat): New function. * s390-nat.c (s390_linux_fetch_inferior_registers): Renamed from fetch_inferior_registers and made static. (s390_linux_store_inferior_registers): Renamed from store_inferior_registers and made static. (_initialize_s390_nat): New function. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Use linux_target and add_target. * config/nm-linux.h: Don't include "auxv.h". (struct target_waitstatus, child_wait, CHILD_WAIT) (CHILD_PID_TO_EXEC_FILE, CHILD_INSERT_FORK_CATCHPOINT) (CHILD_INSERT_VFORK_CATCHPOINT, CHILD_INSERT_EXEC_CATCHPOINT) (CHILD_POST_STARTUP_INFERIOR, CHILD_POST_ATTACH, CHILD_FOLLOW_FORK) (DEPRECATED_KILL_INFERIOR, NATIVE_XFER_AUXV): Delete. * config/alpha/alpha-linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o and alpha-linux-nat.o. * config/sparc/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with sparc-linux-nat.o. * config/sparc/linux64.mh (NATDEPFILES): Remove infptrace.o and inftarg.o. * config/arm/linux.mh (NATDEPFILES): Replace infptrace.o and inftarg.o with inf-ptrace.o. * config/i386/linux.mh (NATDEPFILES): Likewise. * config/i386/linux64.mh (NATDEPFILES): Likewise. * config/ia64/linux.mh (NATDEPFILES): Likewise. * config/m32r/linux.mh (NATDEPFILES): Likewise. * config/m68k/linux.mh (NATDEPFILES): Likewise. * config/mips/linux.mh (NATDEPFILES): Likewise. * config/pa/linux.mh (NATDEPFILES): Likewise. * config/powerpc/linux.mh (NATDEPFILES): Likewise. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise. * config/s390/s390.mh (NATDEPFILES): Likewise. * config/i386/nm-linux.h (DEPRECATED_CHILD_RESUME): Don't define. (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/i386/nm-linux64.h (LINUX_CHILD_POST_STARTUP_INFERIOR): Don't define. * config/ia64/nm-linux.h: Don't include "target.h". (NATIVE_XFER_UNWIND_TABLE, ia64_linux_xfer_unwind_table): Remove. * config/djgpp/fnchange.lst: Add alpha-linux-tdep.c, alpha-linux-nat.c, sparc-linux-tdep.c, and sparc-linux-nat.c.
2005-09-10 20:11:14 +02:00
return t;
}
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* target_is_async_p implementation. */
static int
add "this" pointers to more target APIs A subsequent pass introduces delegation helper functions to the target API. This delegation is much cleaner if the target_ops pointer is directly available at delegation time. This patch adds the "this" pointer to various to_* methods for this purpose. This updates a number of ports which I am unable to test. Please give them a look-over. Any possible problem here is trivial, though, as all that is required is adding an argument to a function. 2014-02-19 Tom Tromey <tromey@redhat.com> * aarch64-linux-nat.c (aarch64_linux_stopped_by_watchpoint): Add 'ops' argument. * arm-linux-nat.c (arm_linux_stopped_by_watchpoint): Add 'ops' argument. * i386-nat.c (i386_stopped_by_watchpoint): Add 'ops' argument. * ia64-linux-nat.c (ia64_linux_stopped_by_watchpoint): Add 'ops' argument. * inf-ttrace.c (inf_ttrace_stopped_by_watchpoint): Add 'ops' argument. * linux-nat.c (save_sigtrap): Update. (linux_nat_stopped_by_watchpoint, linux_nat_is_async_p) (linux_nat_can_async_p, linux_nat_async): Add 'ops' argument. (linux_nat_close): Update. * mips-linux-nat.c (mips_linux_stopped_by_watchpoint): Add 'ops' argument. * ppc-linux-nat.c (ppc_linux_stopped_by_watchpoint): Add 'ops' argument. * procfs.c (procfs_stopped_by_watchpoint): Add 'ops' argument. * record-full.c (record_full_beneath_to_stopped_by_watchpoint) (record_full_beneath_to_async, tmp_to_stopped_by_watchpoint) (tmp_to_async): Add 'ops' argument. (record_full_stopped_by_watchpoint, record_full_async) (record_full_can_async_p, record_full_is_async_p): Add 'ops' argument. * remote-m32r-sdi.c (m32r_insert_breakpoint, m32r_remove_breakpoint) (m32r_stopped_by_watchpoint): Add 'ops' argument. * remote-mips.c (mips_stopped_by_watchpoint): Add 'ops' argument. * remote.c (remote_stopped_by_watchpoint_p, remote_can_async_p) (remote_is_async_p, remote_async): Add 'ops' argument. (remote_stopped_data_address): Update. * s390-nat.c (s390_stopped_by_watchpoint): Add 'ops' argument. * target.c (update_current_target) (find_default_can_async_p, find_default_is_async_p): Update. (init_dummy_target): Update. (debug_to_stopped_by_watchpoint): Add 'ops' argument. * target.h (struct target_ops) <to_stopped_by_watchpoint, to_can_async_p, to_is_async_p, to_async>: Add 'ops' argument. (target_can_async_p, target_is_async_p, target_async) (target_stopped_by_watchpoint): Update.
2013-07-30 18:36:07 +02:00
linux_nat_is_async_p (struct target_ops *ops)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
return linux_is_async_p ();
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
/* target_can_async_p implementation. */
static int
add "this" pointers to more target APIs A subsequent pass introduces delegation helper functions to the target API. This delegation is much cleaner if the target_ops pointer is directly available at delegation time. This patch adds the "this" pointer to various to_* methods for this purpose. This updates a number of ports which I am unable to test. Please give them a look-over. Any possible problem here is trivial, though, as all that is required is adding an argument to a function. 2014-02-19 Tom Tromey <tromey@redhat.com> * aarch64-linux-nat.c (aarch64_linux_stopped_by_watchpoint): Add 'ops' argument. * arm-linux-nat.c (arm_linux_stopped_by_watchpoint): Add 'ops' argument. * i386-nat.c (i386_stopped_by_watchpoint): Add 'ops' argument. * ia64-linux-nat.c (ia64_linux_stopped_by_watchpoint): Add 'ops' argument. * inf-ttrace.c (inf_ttrace_stopped_by_watchpoint): Add 'ops' argument. * linux-nat.c (save_sigtrap): Update. (linux_nat_stopped_by_watchpoint, linux_nat_is_async_p) (linux_nat_can_async_p, linux_nat_async): Add 'ops' argument. (linux_nat_close): Update. * mips-linux-nat.c (mips_linux_stopped_by_watchpoint): Add 'ops' argument. * ppc-linux-nat.c (ppc_linux_stopped_by_watchpoint): Add 'ops' argument. * procfs.c (procfs_stopped_by_watchpoint): Add 'ops' argument. * record-full.c (record_full_beneath_to_stopped_by_watchpoint) (record_full_beneath_to_async, tmp_to_stopped_by_watchpoint) (tmp_to_async): Add 'ops' argument. (record_full_stopped_by_watchpoint, record_full_async) (record_full_can_async_p, record_full_is_async_p): Add 'ops' argument. * remote-m32r-sdi.c (m32r_insert_breakpoint, m32r_remove_breakpoint) (m32r_stopped_by_watchpoint): Add 'ops' argument. * remote-mips.c (mips_stopped_by_watchpoint): Add 'ops' argument. * remote.c (remote_stopped_by_watchpoint_p, remote_can_async_p) (remote_is_async_p, remote_async): Add 'ops' argument. (remote_stopped_data_address): Update. * s390-nat.c (s390_stopped_by_watchpoint): Add 'ops' argument. * target.c (update_current_target) (find_default_can_async_p, find_default_is_async_p): Update. (init_dummy_target): Update. (debug_to_stopped_by_watchpoint): Add 'ops' argument. * target.h (struct target_ops) <to_stopped_by_watchpoint, to_can_async_p, to_is_async_p, to_async>: Add 'ops' argument. (target_can_async_p, target_is_async_p, target_async) (target_stopped_by_watchpoint): Update.
2013-07-30 18:36:07 +02:00
linux_nat_can_async_p (struct target_ops *ops)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
/* We're always async, unless the user explicitly prevented it with the
"maint set target-async" command. */
return target_async_permitted;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
static int
linux_nat_supports_non_stop (struct target_ops *self)
{
return 1;
}
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
/* to_always_non_stop_p implementation. */
static int
linux_nat_always_non_stop_p (struct target_ops *self)
{
return 1;
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
}
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
/* True if we want to support multi-process. To be removed when GDB
supports multi-exec. */
gdb/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * linux-nat.c (linux_child_follow_fork): If we're staying attached to the child process, enable event reporting on it. Don't handle checkpoints here. Instead, add the child fork to the lwp thread and inferior lists without clobbering the previous inferior. Let the thread_db layer learn about a new child process, even if following the parent. (linux_nat_switch_fork): Delete lwps of the current inferior only, instead of clearing the whole list. Use thread_change_ptid to give the core the illusion the new checkpoint is still the same inferior. Clear the register cache. (linux_handle_extended_wait): Handle checkpoints here. (linux_multi_process): Turn on. * linux-fork.c (struct fork_info) <pc>: Remove field. (init_fork_list): Do not delete the checkpoint from the inferior list (it is not there). (fork_load_infrun_state): Don't switch inferior_ptid here. Pass the new checkpoint's ptid to linux_nat_switch_fork. (fork_save_infrun_state): Make static. Don't stop the pc field of fork_info, it's gone. (linux_fork_mourn_inferior): Don't delete the checkpoint from the inferior list, it's not there. (linux_fork_detach): Ditto. (delete_fork_command): Replace mention of fork/checkpoint by checkpoint only. (detach_fork_command): Likewise. Don't delete the checkpoint from the inferior list. (info_forks_command): Adjust. (restore_detach_fork): Delete. (checkpointing_pid): New. (linux_fork_checkpointing_p): New. (save_detach_fork): Delete. (checkpoint_command): Delete temp_detach_fork. Don't remove breakpoints, that's a nop. Store the pid of the process we're checkpointing, and use make_cleanup_restore_integer to restore it. Don't reinsert breakpoints here. (process_command, fork_command): Delete. (restart_command): Update comments to only mention checkpoints, not forks. (_initialize_linux_fork): Delete "fork", "process", "info forks" commands. * linux-fork.h (fork_save_infrun_state, fork_list): Delete declarations. (linux_fork_checkpointing_p): Declare. * cli/cli-cmds.c (killlist): New. * cli/cli-cmds.h (killlist): Declare. * gdbcmd.h (killlist): Declare. * inferior.c: Include "gdbthread.h". (detach_inferior_command, kill_inferior_command) (inferior_command): New. (info_inferiors_command): Allow specifying a specific inferior id. (_initialize_inferiors): Register "inferior", "kill inferior" and "detach inferior" commands. * infcmd.c (_initialize_infcmd): Make "kill" a prefix command. * gdbthread.h (any_thread_of_process): Declare. * thread.c (any_thread_of_process): New. * NEWS: Mention multi-inferior debugging. Mention 'info inferiors', 'inferior', 'detach inferior' and 'kill inferior' as new commands. (Removed commands): New section, mentioning that 'info forks', 'fork', 'process', 'delete fork' and 'detach fork' are now gone. gdb/testsuite/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.base/multi-forks.exp: Only run detach-on-fork tests on linux. Adjust to use "inferior", "info inferiors", "detach inferior" and "kill inferior" instead of "restart", "info fork", "detach fork" and "delete fork". * gdb.base/ending-run.exp: Spell out "info". * gdb.base/help.exp: Adjust to use test_prefix_command_help for the "kill" command. gdb/doc/ 2009-07-02 Pedro Alves <pedro@codesourcery.com> * gdb.texinfo (Debugging multiple inferiors): Document the "inferior", "detach inferior" and "kill inferior" commands. (Debugging Programs with Multiple Processes): Adjust to mention generic "inferior" commands. Delete mention of "detach fork" and "delete fork". Cross reference to "Debugging multiple inferiors" section.
2009-07-02 23:57:28 +02:00
int linux_multi_process = 1;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
static int
linux_nat_supports_multi_process (struct target_ops *self)
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
{
return linux_multi_process;
}
* inferior.h (disable_randomization): Declare. * infrun.c (disable_randomization): New global variable. (show_disable_randomization): New function. (set_disable_randomization): Likewise. (_initialize_infrun): Install set/show disable-randomization commands. * linux-nat.c (disable_randomization): Remove. (show_disable_randomization): Likewise. (set_disable_randomization): Likewise. (_initialize_linux_nat): No longer install set/show disable-randomization commands here. (linux_nat_supports_disable_randomization): New function. (linux_nat_add_target): Install it. * remote.c (PACKET_QDisableRandomization): New enum value. (remote_protocol_packets): Support QDisableRandomization. (_initialize_remote): Likewise. (remote_supports_disable_randomization): New function. (init_remote_ops): Install it. (extended_remote_supports_disable_randomization): New function. (init_extended_remote_ops): Install it. (extended_remote_disable_randomization): New function. (extended_remote_create_inferior_1): Call it. * target.h (struct target_ops): Add to_supports_disable_randomization. (target_supports_disable_randomization): Add prototype. * target.c (target_supports_disable_randomization): New function. (find_default_supports_disable_randomization): Likewise. (init_dummy_target): Install it. doc/ * gdb.texinfo (Starting your Program): "set disable-randomization" is no longer Linux-specific. (Remote Configuration): Document "set remote disable-randomization-packet". (General Query Packets): Document "QDisableRandomization" packet and add it to "qSupported" list. gdbserver/ * configure.ac: Check support for personality routine. * configure: Regenerate. * config.in: Likewise. * linux-low.c: Include <sys/personality.h>. Define ADDR_NO_RANDOMIZE if necessary. (linux_create_inferior): Disable address space randomization when forking inferior, if requested. (linux_supports_disable_randomization): New function. (linux_target_ops): Install it. * server.h (disable_randomization): Declare. * server.c (disable_randomization): New global variable. (handle_general_set): Handle QDisableRandomization. (handle_query): Likewise for qSupported. (main): Support --disable-randomization and --no-disable-randomization command line arguments. * target.h (struct target_ops): Add supports_disable_randomization. (target_supports_disable_randomization): New macro.
2011-10-07 14:06:48 +02:00
static int
linux_nat_supports_disable_randomization (struct target_ops *self)
* inferior.h (disable_randomization): Declare. * infrun.c (disable_randomization): New global variable. (show_disable_randomization): New function. (set_disable_randomization): Likewise. (_initialize_infrun): Install set/show disable-randomization commands. * linux-nat.c (disable_randomization): Remove. (show_disable_randomization): Likewise. (set_disable_randomization): Likewise. (_initialize_linux_nat): No longer install set/show disable-randomization commands here. (linux_nat_supports_disable_randomization): New function. (linux_nat_add_target): Install it. * remote.c (PACKET_QDisableRandomization): New enum value. (remote_protocol_packets): Support QDisableRandomization. (_initialize_remote): Likewise. (remote_supports_disable_randomization): New function. (init_remote_ops): Install it. (extended_remote_supports_disable_randomization): New function. (init_extended_remote_ops): Install it. (extended_remote_disable_randomization): New function. (extended_remote_create_inferior_1): Call it. * target.h (struct target_ops): Add to_supports_disable_randomization. (target_supports_disable_randomization): Add prototype. * target.c (target_supports_disable_randomization): New function. (find_default_supports_disable_randomization): Likewise. (init_dummy_target): Install it. doc/ * gdb.texinfo (Starting your Program): "set disable-randomization" is no longer Linux-specific. (Remote Configuration): Document "set remote disable-randomization-packet". (General Query Packets): Document "QDisableRandomization" packet and add it to "qSupported" list. gdbserver/ * configure.ac: Check support for personality routine. * configure: Regenerate. * config.in: Likewise. * linux-low.c: Include <sys/personality.h>. Define ADDR_NO_RANDOMIZE if necessary. (linux_create_inferior): Disable address space randomization when forking inferior, if requested. (linux_supports_disable_randomization): New function. (linux_target_ops): Install it. * server.h (disable_randomization): Declare. * server.c (disable_randomization): New global variable. (handle_general_set): Handle QDisableRandomization. (handle_query): Likewise for qSupported. (main): Support --disable-randomization and --no-disable-randomization command line arguments. * target.h (struct target_ops): Add supports_disable_randomization. (target_supports_disable_randomization): New macro.
2011-10-07 14:06:48 +02:00
{
#ifdef HAVE_PERSONALITY
return 1;
#else
return 0;
#endif
}
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
static int async_terminal_is_ours = 1;
/* target_terminal_inferior implementation.
This is a wrapper around child_terminal_inferior to add async support. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
static void
linux_nat_terminal_inferior (struct target_ops *self)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
child_terminal_inferior (self);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* Calls to target_terminal_*() are meant to be idempotent. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
if (!async_terminal_is_ours)
return;
async_terminal_is_ours = 0;
set_sigint_trap ();
}
/* target_terminal_ours implementation.
This is a wrapper around child_terminal_ours to add async support (and
implement the target_terminal_ours vs target_terminal_ours_for_output
distinction). child_terminal_ours is currently no different than
child_terminal_ours_for_output.
We leave target_terminal_ours_for_output alone, leaving it to
child_terminal_ours_for_output. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
2008-02-21 Pedro Alves <pedro@codesorcery.com> Silence a few -Wmissing-prototypes warnings. PR build/9877: * amd64-nat.c: Include "amd64-nat.h". * fork-child.c (_initialize_fork_child): Ditto. * gcore.c (_initialize_gcore): Ditto. * inf-ptrace.c: Include "inf-ptrace.h". (inf_ptrace_store_registers): Make it static. * linux-nat.c (linux_nat_terminal_ours): Make it static. (_initialize_linux_nat): Declare before definition. * linux-tdep.c: Include "linux-tdep.h". * linux-thread-db.c (_initialize_thread_db): Declare before definition. * proc-service.c (_initialize_proc_service): Ditto. * remote.c (remote_send_printf): Make it static. * solib.c: Include "solib.h". * symfile-mem.c (_initialize_symfile_mem): Declare before definition. * ada-lang.c (ada_la_decode, ada_match_name) (ada_suppress_symbol_printing, ada_is_array_type) (ada_value_ptr_subscript, ada_array_length) (ada_to_static_fixed_value): Make them static. (_initialize_ada_language): Declare before definition. * ada-tasks.c (ada_get_task_number, ada_get_environment_task) (ada_task_list_changed, ada_new_objfile_observer): Make them static. (_initialize_tasks): Declare before definition. * addrmap.c (_initialize_addrmap): Declare before definition. * auxv.c (default_auxv_parse): Make it static. * bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make them static. * breakpoint.c (remove_sal): Add line break. (expand_line_sal_maybe): Make it static. * cp-name-parser.y: Include "cp-support.h". * cp-valprint.c (cp_find_class_member): Make it static. * eval.c (value_f90_subarray): Ditto. * exceptions.c (print_any_exception): Ditto. * findcmd.c (_initialize_mem_search): Declare before definition. * frame.c (frame_observer_target_changed): Make it static. * gnu-v3-abi.c (gnuv3_find_method_in): Make it static. * inf-child.c: Include "inf-child.h". * inferior.h (valid_inferior_id): Rename to ... (valid_gdb_inferior_id): ... this. * infrun.c (infrun_thread_stop_requested, siginfo_make_value): Make them static. * jv-lang.c (java_language_arch_info): Make it static. * m2-typeprint.c (m2_get_discrete_bounds): Ditto. * osdata.c (info_osdata_command): Make it static. * regcache.c (regcache_observer_target_changed): Make it static. * reverse.c (_initialize_reverse): Declare before definition. * stabsread.c (cleanup_undefined_types_noname) (cleanup_undefined_types_1): Make them static. * symfile.c (place_section): Make it static. * symtab.c (find_pc_sect_psymtab_closer): Make it static. * target-descriptions.c (_initialize_target_descriptions): Declare before definition. * target.c (default_get_ada_task_ptid, find_default_can_async_p) (find_default_is_async_p, find_default_supports_non_stop): Make them static. (target_supports_non_stop): Add prototype. (dummy_pid_to_str): Make it static. * utils.c (_initialize_utils): Declare before definition. * ada-exp.y (_initialize_ada_exp): Declare before definition. * solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype. * target.h (struct target_ops): Add a prototype to the to_can_execute_reverse callback. * macroscope.c (_initialize_macroscope): Declare before definition. * cp-namespace.c (_initialize_cp_namespace): Declare before definition. * python/python.c (_initialize_python): Declare before definition. * tui/tui-command.c: Include "tui/tui-command.h". * tui/tui-data.c (init_content_element, init_win_info): Make them static. * tui/tui-disasm.c: Include "tui/tui-disasm.h". * tui/tui-interp.c (_initialize_tui_interp): Declare before definition. * tui/tui-layout.c: Include "tui/tui-layout.h". (_initialize_tui_layout): Declare before definition. * tui/tui-regs.c: Include "tui/tui-regs.h". (tui_display_reg_element_at_line): Make it static. (_initialize_tui_regs): Declare before definition. * tui/tui-stack.c (_initialize_tui_stack): Declare before definition. * tui/tui-win.c: Include "tui/tui-win.h". (_initialize_tui_win): Declare before definition. (tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH. * tui/tui-win.h (tui_sigwinch_handler): Delete declaration. (tui_get_cmd_list): Add a prototype. * tui/tui-windata.c: Include tui-windata.h. * tui/tui-wingeneral.c (box_win): Make it static. * cli/cli-logging.c (show_logging_command): Make it static. (_initialize_cli_logging): Declare before definition. * mi/mi-common.c (_initialize_gdb_mi_common): Declare before definition.
2009-02-21 17:14:50 +01:00
static void
linux_nat_terminal_ours (struct target_ops *self)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
/* GDB should never give the terminal to the inferior if the
inferior is running in the background (run&, continue&, etc.),
but claiming it sure should. */
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
child_terminal_ours (self);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
if (async_terminal_is_ours)
return;
clear_sigint_trap ();
async_terminal_is_ours = 1;
}
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* SIGCHLD handler that serves two purposes: In non-stop/async mode,
so we notice when any child changes state, and notify the
event-loop; it allows us to use sigsuspend in linux_nat_wait_1
above to wait for the arrival of a SIGCHLD. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
static void
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
sigchld_handler (int signo)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
int old_errno = errno;
if (debug_linux_nat)
ui_file_write_async_safe (gdb_stdlog,
"sigchld\n", sizeof ("sigchld\n") - 1);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (signo == SIGCHLD
&& linux_nat_event_pipe[0] != -1)
async_file_mark (); /* Let the event loop know that there are
events to handle. */
errno = old_errno;
}
/* Callback registered with the target events file descriptor. */
static void
handle_target_event (int error, gdb_client_data client_data)
{
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
inferior_event_handler (INF_REG_EVENT, NULL);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
}
/* Create/destroy the target events pipe. Returns previous state. */
static int
linux_async_pipe (int enable)
{
int previous = linux_is_async_p ();
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (previous != enable)
{
sigset_t prev_mask;
linux-nat.c: no need to block child signals so aggressively. In http://sourceware.org/ml/gdb-patches/2013-08/msg00174.html , the issue of child signal handling around ptrace option support discovery being different between GDB and GDBserver came up. I recalled adding these block_child_signals calls, and the "We don't want those ptrace calls to be interrupted" comment, but not exactly why. So I looked into it. My first guess is that I got confused. The patch that added this <http://sourceware.org/ml/gdb-patches/2009-04/msg00125.html> rewrote the linux native async support completely, and the old async support code had the SIGCHLD handler itself do waitpid, so in places that we'd want a blocking waitpid, we'd have to have the signal handler blocked. That was probably the mindset I had at the time. Anyway, whatever the case, looks like I was wrong on the need for this blocking. Given GDBserver doesn't block like this, I investigated why this is currently needed on GDB but not on GDBserver. I removed the block_child_signals (and restore) calls, and hacked linux-nat.c to call linux_test_for_tracefork in a loop, like: @@ -534,7 +534,10 @@ static int linux_supports_tracefork (int pid) { if (linux_supports_tracefork_flag == -1) - linux_test_for_tracefork (pid); + { + while (1) + linux_test_for_tracefork (pid); + } return linux_supports_tracefork_flag; } Running the resulting GDB, I then saw bad things happening. Specifically, I'd end up with a bunch of zombies, and eventually, the machine would refuse to spawn new processes, claming insufficient resources. The issue is that linux_test_for_tracefork test forks, and has the child fork again. If we don't block SIGCHLD on entry to the function, the children will inherit SIGCHLD's action/disposition (meaning, SIGCHLD will be unblocked in the child). When the first child forks again a second child, and that child exits, the first child gets a SIGCHLD. Now, when we try to wrap up for the whole options test, we kill the first child, and collect the waitstatus. Here, when SIGCHLD isn't blocked, GDB will first see the child reporting a stop with SIGCHLD. gdbserver's ptrace options test does a PTRACE_KILL loop at the end, which catches the SIGCHLD, and retries the kill. The GDB version did not do that. So the GDB version would proceed, leaving the child zombie (until GDB exists), as nothing collected its final waitstatus. So this patch makes the GDB version of linux_test_for_tracefork do the exact same as the GDBserver version, removes all this unnecessary blocking throughout, and adds a couple comments at places that do need it -- namely: places where we'll use sleep with sigsuspend; and linux_async_pipe, as that destroys the pipe the signal handler touches. Tested on x86_64 Fedora 17, sync and async. gdb/ 2013-08-19 Pedro Alves <palves@redhat.com> * linux-nat.c (linux_test_for_tracefork) (linux_test_for_tracesysgood, linux_child_follow_fork) (lin_lwp_attach_lwp, linux_nat_resume): Don't block child signals. (linux_nat_wait_1): Extend comment. (linux_async_pipe): Add comment.
2013-08-19 15:44:41 +02:00
/* Block child signals while we create/destroy the pipe, as
their handler writes to it. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
block_child_signals (&prev_mask);
if (enable)
{
PR gdb/7912: * Makefile.in (SFILES): Add filestuff.c (COMMON_OBS): Add filestuff.o. (filestuff.o): New target. * auto-load.c (auto_load_objfile_script_1): Use gdb_fopen_cloexec. * auxv.c (procfs_xfer_auxv): Use gdb_open_cloexec. * cli/cli-cmds.c (shell_escape): Call close_most_fds. * cli/cli-dump.c (fopen_with_cleanup): Use gdb_fopen_cloexec. * common/agent.c (gdb_connect_sync_socket): Use gdb_socket_cloexec. * common/filestuff.c: New file. * common/filestuff.h: New file. * common/linux-osdata.c (linux_common_core_of_thread) (command_from_pid, commandline_from_pid, print_source_lines) (linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Use gdb_fopen_cloexec. * common/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_has_state): Use gdb_fopen_cloexec. * config.in, configure: Rebuild. * configure.ac: Don't check for sys/socket.h. Check for fdwalk, pipe2. * corelow.c (core_open): Use gdb_open_cloexec. * dwarf2read.c (write_psymtabs_to_index): Use gdb_fopen_cloexec. * fork-child.c (fork_inferior): Call close_most_fds. * gdb_bfd.c (gdb_bfd_open): Use gdb_open_cloexec. * inf-child.c (inf_child_fileio_readlink): Use gdb_open_cloexec. * linux-nat.c (linux_nat_thread_name, linux_proc_pending_signals): Use gdb_fopen_cloexec. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use gdb_open_cloexec. (linux_async_pipe): Use gdb_pipe_cloexec. * remote-fileio.c (remote_fileio_func_open): Use gdb_open_cloexec. * remote.c (remote_file_put, remote_file_get): Use gdb_fopen_cloexec. * ser-pipe.c (pipe_open): Use gdb_socketpair_cloexec, close_most_fds. * ser-tcp.c (net_open): Use gdb_socket_cloexec. * ser-unix.c (hardwire_open): Use gdb_open_cloexec. * solib.c (solib_find): Use gdb_open_cloexec. * source.c (openp, find_and_open_source): Use gdb_open_cloexec. * tracepoint.c (tfile_start): Use gdb_fopen_cloexec. (tfile_open): Use gdb_open_cloexec. * tui/tui-io.c (tui_initialize_io): Use gdb_pipe_cloexec. * ui-file.c (gdb_fopen): Use gdb_fopen_cloexec. * xml-support.c (xml_fetch_content_from_file): Use gdb_fopen_cloexec. * main.c (captured_main): Call notice_open_fds. gdbserver * Makefile.in (SFILES): Add filestuff.c. (OBS): Add filestuff.o. (filestuff.o): New target. * config.in, configure: Rebuild. * configure.ac: Check for fdwalk, pipe2.
2013-04-22 18:46:15 +02:00
if (gdb_pipe_cloexec (linux_nat_event_pipe) == -1)
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
internal_error (__FILE__, __LINE__,
"creating event pipe failed.");
fcntl (linux_nat_event_pipe[0], F_SETFL, O_NONBLOCK);
fcntl (linux_nat_event_pipe[1], F_SETFL, O_NONBLOCK);
}
else
{
close (linux_nat_event_pipe[0]);
close (linux_nat_event_pipe[1]);
linux_nat_event_pipe[0] = -1;
linux_nat_event_pipe[1] = -1;
}
restore_child_signals_mask (&prev_mask);
}
return previous;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
/* target_async implementation. */
static void
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
linux_nat_async (struct target_ops *ops, int enable)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
if (enable)
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
{
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
if (!linux_async_pipe (1))
{
add_file_handler (linux_nat_event_pipe[0],
handle_target_event, NULL);
/* There may be pending events to handle. Tell the event loop
to poll them. */
async_file_mark ();
}
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
else
{
delete_file_handler (linux_nat_event_pipe[0]);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
linux_async_pipe (0);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
}
return;
}
gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. gdb/gdbserver/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. include/gdb/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 * gdb/signals.def: Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/arm/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/avr/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/common/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/cr16/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/d10v/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/erc32/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/m32c/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/ppc/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rl78/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout. sim/rx/ 2012-05-24 Pedro Alves <palves@redhat.com> PR gdb/7205 Replace TARGET_SIGNAL_ with GDB_SIGNAL_ throughout.
2012-05-24 18:51:47 +02:00
/* Stop an LWP, and push a GDB_SIGNAL_0 stop status if no other
event came out. */
static int
linux_nat_stop_lwp (struct lwp_info *lwp, void *data)
{
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (!lwp->stopped)
{
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"LNSL: running -> suspending %s\n",
target_pid_to_str (lwp->ptid));
if (lwp->last_resume_kind == resume_stop)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
"linux-nat: already stopping LWP %ld at "
"GDB's request\n",
ptid_get_lwp (lwp->ptid));
return 0;
}
stop_callback (lwp, NULL);
lwp->last_resume_kind = resume_stop;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
}
else
{
/* Already known to be stopped; do nothing. */
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (debug_linux_nat)
{
if (find_thread_ptid (lwp->ptid)->stop_requested)
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
fprintf_unfiltered (gdb_stdlog,
"LNSL: already stopped/stop_requested %s\n",
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
target_pid_to_str (lwp->ptid));
else
2011-01-05 Michael Snyder <msnyder@vmware.com> * addrmap.c: Shorten lines of >= 80 columns. * arch-utils.c: Ditto. * arch-utils.h: Ditto. * ax-gdb.c: Ditto. * ax-general.c: Ditto. * bcache.c: Ditto. * blockframe.c: Ditto. * breakpoint.c: Ditto. * buildsym.c: Ditto. * c-lang.c: Ditto. * c-typeprint.c: Ditto. * charset.c: Ditto. * coffread.c: Ditto. * command.h: Ditto. * corelow.c: Ditto. * cp-abi.c: Ditto. * cp-namespace.c: Ditto. * cp-support.c: Ditto. * dbug-rom.c: Ditto. * dbxread.c: Ditto. * defs.h: Ditto. * dfp.c: Ditto. * dfp.h: Ditto. * dictionary.c: Ditto. * disasm.c: Ditto. * doublest.c: Ditto. * dwarf2-frame.c: Ditto. * dwarf2expr.c: Ditto. * dwarf2loc.c: Ditto. * dwarf2read.c: Ditto. * elfread.c: Ditto. * eval.c: Ditto. * event-loop.c: Ditto. * event-loop.h: Ditto. * exceptions.h: Ditto. * exec.c: Ditto. * expprint.c: Ditto. * expression.h: Ditto. * f-lang.c: Ditto. * f-valprint.c: Ditto. * findcmd.c: Ditto. * frame-base.c: Ditto. * frame-unwind.c: Ditto. * frame-unwind.h: Ditto. * frame.c: Ditto. * frame.h: Ditto. * gcore.c: Ditto. * gdb-stabs.h: Ditto. * gdb_assert.h: Ditto. * gdb_dirent.h: Ditto. * gdb_obstack.h: Ditto. * gdbcore.h: Ditto. * gdbtypes.c: Ditto. * gdbtypes.h: Ditto. * inf-ttrace.c: Ditto. * infcall.c: Ditto. * infcmd.c: Ditto. * inflow.c: Ditto. * infrun.c: Ditto. * inline-frame.h: Ditto. * language.c: Ditto. * language.h: Ditto. * libunwind-frame.c: Ditto. * libunwind-frame.h: Ditto. * linespec.c: Ditto. * linux-nat.c: Ditto. * linux-nat.h: Ditto. * linux-thread-db.c: Ditto. * machoread.c: Ditto. * macroexp.c: Ditto. * macrotab.c: Ditto. * main.c: Ditto. * maint.c: Ditto. * mdebugread.c: Ditto. * memattr.c: Ditto. * minsyms.c: Ditto. * monitor.c: Ditto. * monitor.h: Ditto. * objfiles.c: Ditto. * objfiles.h: Ditto. * osabi.c: Ditto. * p-typeprint.c: Ditto. * p-valprint.c: Ditto. * parse.c: Ditto. * printcmd.c: Ditto. * proc-events.c: Ditto. * procfs.c: Ditto. * progspace.c: Ditto. * progspace.h: Ditto. * psympriv.h: Ditto. * psymtab.c: Ditto. * record.c: Ditto. * regcache.c: Ditto. * regcache.h: Ditto. * remote-fileio.c: Ditto. * remote.c: Ditto. * ser-mingw.c: Ditto. * ser-tcp.c: Ditto. * ser-unix.c: Ditto. * serial.c: Ditto. * serial.h: Ditto. * solib-frv.c: Ditto. * solib-irix.c: Ditto. * solib-osf.c: Ditto. * solib-pa64.c: Ditto. * solib-som.c: Ditto. * solib-sunos.c: Ditto. * solib-svr4.c: Ditto. * solib-target.c: Ditto. * solib.c: Ditto. * somread.c: Ditto. * source.c: Ditto. * stabsread.c: Ditto. * stabsread.c: Ditto. * stack.c: Ditto. * stack.h: Ditto. * symfile-mem.c: Ditto. * symfile.c: Ditto. * symfile.h: Ditto. * symmisc.c: Ditto. * symtab.c: Ditto. * symtab.h: Ditto. * target-descriptions.c: Ditto. * target-memory.c: Ditto. * target.c: Ditto. * target.h: Ditto. * terminal.h: Ditto. * thread.c: Ditto. * top.c: Ditto. * tracepoint.c: Ditto. * tracepoint.h: Ditto. * ui-file.c: Ditto. * ui-file.h: Ditto. * ui-out.h: Ditto. * user-regs.c: Ditto. * user-regs.h: Ditto. * utils.c: Ditto. * valarith.c: Ditto. * valops.c: Ditto. * valprint.c: Ditto. * valprint.h: Ditto. * value.c: Ditto. * varobj.c: Ditto. * varobj.h: Ditto. * vec.h: Ditto. * xcoffread.c: Ditto. * xcoffsolib.c: Ditto. * xcoffsolib.h: Ditto. * xml-syscall.c: Ditto. * xml-tdesc.c: Ditto.
2011-01-05 23:22:53 +01:00
fprintf_unfiltered (gdb_stdlog,
"LNSL: already stopped/no "
"stop_requested yet %s\n",
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
target_pid_to_str (lwp->ptid));
}
}
return 0;
}
static void
linux_nat_stop (struct target_ops *self, ptid_t ptid)
{
Fix interrupt-noterm.exp on targets always in non-stop With "maint set target-non-stop on" we get: @@ -66,13 +66,16 @@ Continuing. interrupt (gdb) PASS: gdb.base/interrupt-noterm.exp: interrupt -Program received signal SIGINT, Interrupt. -PASS: gdb.base/interrupt-noterm.exp: inferior received SIGINT -testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 0 seconds +[process 12119] #1 stopped. +0x0000003615ebc6d0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:81 +81 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS) +FAIL: gdb.base/interrupt-noterm.exp: inferior received SIGINT (timeout) +testcase src/gdb/testsuite/gdb.base/interrupt-noterm.exp completed in 10 seconds That is, we get "[$thread] #1 stopped" instead of SIGINT. The issue is that we don't currently distinguish send "interrupt/ctrl-c" to target terminal vs "stop/pause" thread well; both cases go through "target_stop". And then, the native Linux backend (linux-nat.c) implements target_stop with SIGSTOP in non-stop mode, and SIGINT in all-stop mode. Since "maint set target-non-stop on" forces the backend to be always running in non-stop mode, even though the user-visible behavior is "set non-stop" is "off", "interrupt" causes a SIGSTOP instead of the SIGINT the test expects. Fix this by introducing a target_interrupt method to use in the "interrupt/ctrl-c" case, so "set non-stop off" can always work the same irrespective of "maint set target-non-stop on/off". I'm explictly considering changing the "set non-stop on" behavior as out of scope here. Most of the patch is an across-the-board rename of to_stop hook implementations to to_interrupt. The only targets where something more than a rename is being done are linux-nat.c and remote.c, which are the only targets that support async, and thus are the only ones the core side calls target_stop on. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * darwin-nat.c (darwin_stop): Rename to ... (darwin_interrupt): ... this. (_initialize_darwin_inferior): Adjust. * gnu-nat.c (gnu_stop): Delete. (gnu_target): Don't install gnu_stop. * inf-ptrace.c (inf_ptrace_stop): Rename to ... (inf_ptrace_interrupt): ... this. (inf_ptrace_target): Adjust. * infcmd.c (interrupt_target_1): Use target_interrupt instead of target_stop. * linux-nat (linux_nat_stop): Rename to ... (linux_nat_interrupt): ... this. (linux_nat_stop): Reimplement. (linux_nat_add_target): Install linux_nat_interrupt. * nto-procfs.c (nto_interrupt_twice): Rename to ... (nto_handle_sigint_twice): ... this. (nto_interrupt): Rename to ... (nto_handle_sigint): ... this. Call target_interrupt instead of target_stop. (procfs_wait): Adjust. (procfs_stop): Rename to ... (procfs_interrupt): ... this. (init_procfs_targets): Adjust. * procfs.c (procfs_stop): Rename to ... (procfs_interrupt): ... this. (procfs_target): Adjust. * remote-m32r-sdi.c (m32r_stop): Rename to ... (m32r_interrupt): ... this. (init_m32r_ops): Adjust. * remote-sim.c (gdbsim_stop_inferior): Rename to ... (gdbsim_interrupt_inferior): ... this. (gdbsim_stop): Rename to ... (gdbsim_interrupt): ... this. (gdbsim_cntrl_c): Adjust. (init_gdbsim_ops): Adjust. * remote.c (sync_remote_interrupt): Adjust comments. (remote_stop_as): Rename to ... (remote_interrupt_as): ... this. (remote_stop): Adjust comment. (remote_interrupt): New function. (init_remote_ops): Install remote_interrupt. * target.c (target_interrupt): New function. * target.h (struct target_ops) <to_interrupt>: New field. (target_interrupt): New declaration. * windows-nat.c (windows_stop): Rename to ... (windows_interrupt): ... this. * target-delegates.c: Regenerate.
2015-08-06 19:22:58 +02:00
iterate_over_lwps (ptid, linux_nat_stop_lwp, NULL);
}
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
static void
linux_nat_close (struct target_ops *self)
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
{
/* Unregister from the event loop. */
if (linux_nat_is_async_p (self))
Simplify target_async hook interface All callers of target_async pass it the same callback (inferior_event_handler). Since both common code and target backends need to be able to put the target in and out of target async mode at any given time, there's really no way that a different callback could be passed. This commit simplifies things, and removes the indirection altogether. Bonus: with this, gdb's target_async method ends up with the same signature as gdbserver's. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2015-03-25 Pedro Alves <palves@redhat.com> * target.h <to_async>: Replace 'callback' and 'context' parameters with boolean 'enable' parameter. (target_async): Replace CALLBACK and CONTEXT parameters with boolean ENABLE parameter. * inf-loop.c (inferior_event_handler): Adjust. * linux-nat.c (linux_nat_attach, linux_nat_resume) (linux_nat_resume): Adjust. (async_client_callback, async_client_context): Delete. (handle_target_event): Call inferior_event_handler directly. (linux_nat_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. Remove references to async_client_callback and async_client_context. (linux_nat_close): Adjust. * record-btrace.c (record_btrace_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_btrace_resume): Adjust. * record-full.c (record_full_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. (record_full_resume, record_full_core_resume): Adjust. * remote.c (struct remote_state) <async_client_callback, async_client_context>: Delete fields. (remote_start_remote, extended_remote_attach_1, remote_resume) (extended_remote_create_inferior): Adjust. (remote_async_serial_handler): Call inferior_event_handler directly. (remote_async): Replace 'callback' and 'context' parameters with boolean 'enable' parameter. Adjust. * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper): Adjust. * target-delegates.c: Regenerate.
2015-03-25 12:28:31 +01:00
linux_nat_async (self, 0);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
if (linux_ops->to_close)
linux_ops->to_close (linux_ops);
Allow making GDB not automatically connect to the native target. Sometimes it's useful to be able to disable the automatic connection to the native target. E.g., sometimes GDB disconnects from the extended-remote target I was debugging, without me noticing it, and then I do "run". That starts the program locally, and only after a little head scratch session do I figure out the program is running locally instead of remotely as intended. Same thing with "attach", "info os", etc. With the patch, we now can have this instead: (gdb) set auto-connect-native-target off (gdb) target extended-remote :9999 ... *gdb disconnects* (gdb) run Don't know how to run. Try "help target". To still be able to connect to the native target with auto-connect-native-target set to off, I've made "target native" work instead of erroring out as today. Before: (gdb) target native Use the "run" command to start a native process. After: (gdb) target native Done. Use the "run" command to start a process. (gdb) maint print target-stack The current target stack is: - native (Native process) - exec (Local exec file) - None (None) (gdb) run Starting program: ./a.out ... I've also wanted this for the testsuite, when running against the native-extended-gdbserver.exp board (runs against gdbserver in extended-remote mode). With a non-native-target board, it's always a bug to launch a program with the native target. Turns out we still have one such case this patch catches: (gdb) break main Breakpoint 1 at 0x4009e5: file ../../../src/gdb/testsuite/gdb.base/coremaker.c, line 138. (gdb) run Don't know how to run. Try "help target". (gdb) FAIL: gdb.base/corefile.exp: run: with core On the patch itself, probably the least obvious bit is the need to go through all targets, and move the unpush_target call to after the generic_mourn_inferior call instead of before. This is what inf-ptrace.c does too, ever since multi-process support was added. The reason inf-ptrace.c does things in that order is that in the current multi-process/single-target model, we shouldn't unpush the target if there are still other live inferiors being debugged. The check for that is "have_inferiors ()" (a misnomer nowadays...), which does: have_inferiors (void) { for (inf = inferior_list; inf; inf = inf->next) if (inf->pid != 0) return 1; It's generic_mourn_inferior that ends up clearing inf->pid, so we need to call it before the have_inferiors check. To make all native targets behave the same WRT to explicit "target native", I've added an inf_child_maybe_unpush_target function that targets call instead of calling unpush_target directly, and as that includes the have_inferiors check, I needed to adjust the targets. Tested on x86_64 Fedora 20, native, and also with the extended-gdbserver board. Confirmed a cross build of djgpp gdb still builds. Smoke tested a cross build of Windows gdb under Wine. Untested otherwise. gdb/ 2014-05-21 Pedro Alves <palves@redhat.com> * inf-child.c (inf_child_ops, inf_child_explicitly_opened): New globals. (inf_child_open_target): New function. (inf_child_open): Use inf_child_open_target to push the target instead of erroring out. (inf_child_disconnect, inf_child_close) (inf_child_maybe_unpush_target): New functions. (inf_child_target): Install inf_child_disconnect and inf_child_close. Store a pointer to the returned object. * inf-child.h (inf_child_open_target, inf_child_maybe_unpush): New declarations. * target.c (auto_connect_native_target): New global. (show_default_run_target): New function. (find_default_run_target): Return NULL if automatically connecting to the native target is disabled. (_initialize_target): Install set/show auto-connect-native-target. * NEWS: Mention "set auto-connect-native-target", and "target native". * linux-nat.c (super_close): New global. (linux_nat_close): Call super_close. (linux_nat_add_target): Store a pointer to the base class's to_close method. * inf-ptrace.c (inf_ptrace_mourn_inferior, inf_ptrace_detach): Use inf_child_maybe_unpush. * inf-ttrace.c (inf_ttrace_him): Don't push the target if it is already pushed. (inf_ttrace_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (inf_ttrace_attach): Don't push the target if it is already pushed. (inf_ttrace_detach): Use inf_child_maybe_unpush_target. * darwin-nat.c (darwin_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (darwin_attach_pid): Don't push the target if it is already pushed. * gnu-nat.c (gnu_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (gnu_detach): Use inf_child_maybe_unpush_target. * go32-nat.c (go32_create_inferior): Don't push the target if it is already pushed. (go32_mourn_inferior): Use inf_child_maybe_unpush_target. * nto-procfs.c (procfs_is_nto_target): Adjust comment. (procfs_open): Rename to ... (procfs_open_1): ... this. Add target_ops parameter. Adjust comments. Can target_preopen before changing node. Call inf_child_open_target to push the target explicitly. (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_create_inferior): Don't push the target if it is already pushed. (nto_native_ops): New global. (procfs_open): Reimplement. (procfs_native_open): New function. (init_procfs_targets): Install procfs_native_open as to_open of "target native". Store a pointer to the "native" target in nto_native_ops. * procfs.c (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (procfs_init_inferior): Don't push the target if it is already pushed. * windows-nat.c (do_initial_windows_stuff): Don't push the target if it is already pushed. (windows_detach): Use inf_child_maybe_unpush_target. (windows_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. gdb/doc/ 2014-05-21 Pedro Alves <palves@redhat.com> * gdb.texinfo (Starting): Document "set/show auto-connect-native-target". (Target Commands): Document "target native". gdb/testsuite/ 2014-05-21 Pedro Alves <palves@redhat.com> * boards/gdbserver-base.exp (GDBFLAGS): Set to "set auto-connect-native-target off". * gdb.base/auto-connect-native-target.c: New file. * gdb.base/auto-connect-native-target.exp: New file.
2014-05-21 19:30:47 +02:00
super_close (self);
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
}
/* When requests are passed down from the linux-nat layer to the
single threaded inf-ptrace layer, ptids of (lwpid,0,0) form are
used. The address space pointer is stored in the inferior object,
but the common code that is passed such ptid can't tell whether
lwpid is a "main" process id or not (it assumes so). We reverse
look up the "main" process id from the lwp here. */
2012-03-01 Pedro Alves <palves@redhat.com> * amd64-linux-tdep.c (amd64_linux_record_signal): Make static. * breakpoint.c (create_exception_master_breakpoint, trace_command) (ftrace_command, strace_command): Make static. * d-lang.c (_initialize_d_language): Declare. * dwarf2expr.c (_initialize_dwarf2expr): Declare. * dwarf2loc.c (_initialize_dwarf2loc): * dwarf2read.c (process_psymtab_comp_unit): Make static. * exec.c (exec_get_section_table): Make static. * i386-linux-tdep.c (i386_linux_record_signal): Make static. * infcmd.c (ensure_valid_thread, ensure_not_tfind_mode): Make static. * inferior.c (remove_inferior_command, add_inferior_command) (clone_inferior_command): Make static. * linux-nat.c (linux_nat_thread_address_space) (linux_nat_core_of_thread): Make static. * linux-tdep.c (_initialize_linux_tdep): Declare. * objc-lang.c (_initialize_objc_lang): Declare. * opencl-lang.c (builtin_opencl_type, opencl_language_arch_info): Make static. (_initialize_opencl_language): Declare. * record.c (_initialize_record): Declare. * remote.c (demand_private_info, remote_get_tib_address) (remote_supports_cond_tracepoints) (remote_supports_fast_tracepoints, remote_get_tracepoint_status): Make static. * skip.c (_initialize_step_skip): Declare. * symtab.c (skip_prologue_using_lineinfo): Make static. * tracepoint.c (delete_trace_state_variable) (trace_variable_command, delete_trace_variable_command) (get_uploaded_tsv, find_matching_tracepoint_location) (find_matching_tsv, create_tsv_from_upload, get_traceframe_info): Make static. * value.c (pack_unsigned_long): Make static. * varobj.c (varobj_ensure_python_env): Make static. * windows-tdep.c (_initialize_windows_tdep): Declare. * xml-syscall.c (make_cleanup_free_syscalls_info): Make static.
2012-03-01 22:14:00 +01:00
static struct address_space *
linux_nat_thread_address_space (struct target_ops *t, ptid_t ptid)
{
struct lwp_info *lwp;
struct inferior *inf;
int pid;
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
if (ptid_get_lwp (ptid) == 0)
{
/* An (lwpid,0,0) ptid. Look up the lwp object to get at the
tgid. */
lwp = find_lwp_pid (ptid);
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_pid (lwp->ptid);
}
else
{
/* A (pid,lwpid,0) ptid. */
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_pid (ptid);
}
inf = find_inferior_pid (pid);
gdb_assert (inf != NULL);
return inf->aspace;
}
Implement core awareness. * bcache.c (compare_ints): Remove (print_percentage): Use compare_positive_ints. * defs.h (compare_positive_ints): Declare. * linux-nat.h (struct lin_lwp): New field core. (linux_nat_core_of_thread_1): Declare. * linux-nat.c (add_lwp): Init the 'core' field. (linux_nat_wait_1): Record the core. (linux_nat_core_of_thread_1, linux_nat_core_of_thread): New. (linux_nat_add_target): Register the above. * linux-thread-db.c (update_thread_core): New. (thread_db_find_new_threads): Update core information for every thread. * remote.c (struct private_thread_info): New. (free_private_thread_info, demand_private_info): New. (PACKET_qXfer_threads, use_osdata_threads): New. (struct thread_item, threads_parsing_context (start_thread, end_thread, thread_attributes) (thread_children, threads_children, threads_elements): New. (remote_threads_info): Try qXfer:threads before anything else. (remote_protocol_packets): Register qXfer:threads. (remote_open_1): Init use_osdata_threads. (struct stop_reply): New field 'core'. (remote_parse_stop_reply): Parse core number. (process_stop_reply): Record core number. (remote_xfer_partial): Handle qXfer:threads. (remote_core_of_thread): New. (init_remote_ops): Register remote_core_of_thread. (_initialize_remote): Register qXfer:read. * target.c (target_core_of_thread): New * target.h (enum target_object): New value TARGET_OBJECT_THREADS. (struct target_ops): New field to_core_of_threads. (target_core_of_thread): Declare. * gdbthread.h (struct thread_info): New field private_dtor. * thread.c (print_thread_info): Report the core. * ui-out.c (MAX_UI_OUT_LEVELS): Increase. * utils.c (compare_positive_ints): New. * features/threads.dtd: New. * mi/mi-interp.c (mi_on_normal_stop): Report the core. * mi/mi-main.c (struct collect_cores_data, collect_cores) (do_nothing, free_vector_of_osdata_items) (splay_tree_int_comparator, free_splay_tree): New. (print_one_inferior_data): Implemented printing of selected inferiors. Collect and print cores. (output_cores): New. (mi_cmd_list_thread_groups): Support --recurse. Permit specifying thread groups together with --available.
2010-01-12 22:40:25 +01:00
/* Return the cached value of the processor core for thread PTID. */
2012-03-01 Pedro Alves <palves@redhat.com> * amd64-linux-tdep.c (amd64_linux_record_signal): Make static. * breakpoint.c (create_exception_master_breakpoint, trace_command) (ftrace_command, strace_command): Make static. * d-lang.c (_initialize_d_language): Declare. * dwarf2expr.c (_initialize_dwarf2expr): Declare. * dwarf2loc.c (_initialize_dwarf2loc): * dwarf2read.c (process_psymtab_comp_unit): Make static. * exec.c (exec_get_section_table): Make static. * i386-linux-tdep.c (i386_linux_record_signal): Make static. * infcmd.c (ensure_valid_thread, ensure_not_tfind_mode): Make static. * inferior.c (remove_inferior_command, add_inferior_command) (clone_inferior_command): Make static. * linux-nat.c (linux_nat_thread_address_space) (linux_nat_core_of_thread): Make static. * linux-tdep.c (_initialize_linux_tdep): Declare. * objc-lang.c (_initialize_objc_lang): Declare. * opencl-lang.c (builtin_opencl_type, opencl_language_arch_info): Make static. (_initialize_opencl_language): Declare. * record.c (_initialize_record): Declare. * remote.c (demand_private_info, remote_get_tib_address) (remote_supports_cond_tracepoints) (remote_supports_fast_tracepoints, remote_get_tracepoint_status): Make static. * skip.c (_initialize_step_skip): Declare. * symtab.c (skip_prologue_using_lineinfo): Make static. * tracepoint.c (delete_trace_state_variable) (trace_variable_command, delete_trace_variable_command) (get_uploaded_tsv, find_matching_tracepoint_location) (find_matching_tsv, create_tsv_from_upload, get_traceframe_info): Make static. * value.c (pack_unsigned_long): Make static. * varobj.c (varobj_ensure_python_env): Make static. * windows-tdep.c (_initialize_windows_tdep): Declare. * xml-syscall.c (make_cleanup_free_syscalls_info): Make static.
2012-03-01 22:14:00 +01:00
static int
Implement core awareness. * bcache.c (compare_ints): Remove (print_percentage): Use compare_positive_ints. * defs.h (compare_positive_ints): Declare. * linux-nat.h (struct lin_lwp): New field core. (linux_nat_core_of_thread_1): Declare. * linux-nat.c (add_lwp): Init the 'core' field. (linux_nat_wait_1): Record the core. (linux_nat_core_of_thread_1, linux_nat_core_of_thread): New. (linux_nat_add_target): Register the above. * linux-thread-db.c (update_thread_core): New. (thread_db_find_new_threads): Update core information for every thread. * remote.c (struct private_thread_info): New. (free_private_thread_info, demand_private_info): New. (PACKET_qXfer_threads, use_osdata_threads): New. (struct thread_item, threads_parsing_context (start_thread, end_thread, thread_attributes) (thread_children, threads_children, threads_elements): New. (remote_threads_info): Try qXfer:threads before anything else. (remote_protocol_packets): Register qXfer:threads. (remote_open_1): Init use_osdata_threads. (struct stop_reply): New field 'core'. (remote_parse_stop_reply): Parse core number. (process_stop_reply): Record core number. (remote_xfer_partial): Handle qXfer:threads. (remote_core_of_thread): New. (init_remote_ops): Register remote_core_of_thread. (_initialize_remote): Register qXfer:read. * target.c (target_core_of_thread): New * target.h (enum target_object): New value TARGET_OBJECT_THREADS. (struct target_ops): New field to_core_of_threads. (target_core_of_thread): Declare. * gdbthread.h (struct thread_info): New field private_dtor. * thread.c (print_thread_info): Report the core. * ui-out.c (MAX_UI_OUT_LEVELS): Increase. * utils.c (compare_positive_ints): New. * features/threads.dtd: New. * mi/mi-interp.c (mi_on_normal_stop): Report the core. * mi/mi-main.c (struct collect_cores_data, collect_cores) (do_nothing, free_vector_of_osdata_items) (splay_tree_int_comparator, free_splay_tree): New. (print_one_inferior_data): Implemented printing of selected inferiors. Collect and print cores. (output_cores): New. (mi_cmd_list_thread_groups): Support --recurse. Permit specifying thread groups together with --available.
2010-01-12 22:40:25 +01:00
linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid)
{
struct lwp_info *info = find_lwp_pid (ptid);
Implement core awareness. * bcache.c (compare_ints): Remove (print_percentage): Use compare_positive_ints. * defs.h (compare_positive_ints): Declare. * linux-nat.h (struct lin_lwp): New field core. (linux_nat_core_of_thread_1): Declare. * linux-nat.c (add_lwp): Init the 'core' field. (linux_nat_wait_1): Record the core. (linux_nat_core_of_thread_1, linux_nat_core_of_thread): New. (linux_nat_add_target): Register the above. * linux-thread-db.c (update_thread_core): New. (thread_db_find_new_threads): Update core information for every thread. * remote.c (struct private_thread_info): New. (free_private_thread_info, demand_private_info): New. (PACKET_qXfer_threads, use_osdata_threads): New. (struct thread_item, threads_parsing_context (start_thread, end_thread, thread_attributes) (thread_children, threads_children, threads_elements): New. (remote_threads_info): Try qXfer:threads before anything else. (remote_protocol_packets): Register qXfer:threads. (remote_open_1): Init use_osdata_threads. (struct stop_reply): New field 'core'. (remote_parse_stop_reply): Parse core number. (process_stop_reply): Record core number. (remote_xfer_partial): Handle qXfer:threads. (remote_core_of_thread): New. (init_remote_ops): Register remote_core_of_thread. (_initialize_remote): Register qXfer:read. * target.c (target_core_of_thread): New * target.h (enum target_object): New value TARGET_OBJECT_THREADS. (struct target_ops): New field to_core_of_threads. (target_core_of_thread): Declare. * gdbthread.h (struct thread_info): New field private_dtor. * thread.c (print_thread_info): Report the core. * ui-out.c (MAX_UI_OUT_LEVELS): Increase. * utils.c (compare_positive_ints): New. * features/threads.dtd: New. * mi/mi-interp.c (mi_on_normal_stop): Report the core. * mi/mi-main.c (struct collect_cores_data, collect_cores) (do_nothing, free_vector_of_osdata_items) (splay_tree_int_comparator, free_splay_tree): New. (print_one_inferior_data): Implemented printing of selected inferiors. Collect and print cores. (output_cores): New. (mi_cmd_list_thread_groups): Support --recurse. Permit specifying thread groups together with --available.
2010-01-12 22:40:25 +01:00
if (info)
return info->core;
return -1;
}
/* Implementation of to_filesystem_is_local. */
static int
linux_nat_filesystem_is_local (struct target_ops *ops)
{
struct inferior *inf = current_inferior ();
if (inf->fake_pid_p || inf->pid == 0)
return 1;
return linux_ns_same (inf->pid, LINUX_NS_MNT);
}
/* Convert the INF argument passed to a to_fileio_* method
to a process ID suitable for passing to its corresponding
linux_mntns_* function. If INF is non-NULL then the
caller is requesting the filesystem seen by INF. If INF
is NULL then the caller is requesting the filesystem seen
by the GDB. We fall back to GDB's filesystem in the case
that INF is non-NULL but its PID is unknown. */
static pid_t
linux_nat_fileio_pid_of (struct inferior *inf)
{
if (inf == NULL || inf->fake_pid_p || inf->pid == 0)
return getpid ();
else
return inf->pid;
}
/* Implementation of to_fileio_open. */
static int
linux_nat_fileio_open (struct target_ops *self,
struct inferior *inf, const char *filename,
int flags, int mode, int warn_if_slow,
int *target_errno)
{
int nat_flags;
mode_t nat_mode;
int fd;
if (fileio_to_host_openflags (flags, &nat_flags) == -1
|| fileio_to_host_mode (mode, &nat_mode) == -1)
{
*target_errno = FILEIO_EINVAL;
return -1;
}
fd = linux_mntns_open_cloexec (linux_nat_fileio_pid_of (inf),
filename, nat_flags, nat_mode);
if (fd == -1)
*target_errno = host_to_fileio_error (errno);
return fd;
}
/* Implementation of to_fileio_readlink. */
static char *
linux_nat_fileio_readlink (struct target_ops *self,
struct inferior *inf, const char *filename,
int *target_errno)
{
char buf[PATH_MAX];
int len;
char *ret;
len = linux_mntns_readlink (linux_nat_fileio_pid_of (inf),
filename, buf, sizeof (buf));
if (len < 0)
{
*target_errno = host_to_fileio_error (errno);
return NULL;
}
Add casts to memory allocation related calls Most allocation functions (if not all) return a void* pointing to the allocated memory. In C++, we need to add an explicit cast when assigning the result to a pointer to another type (which is the case more often than not). The content of this patch is taken from Pedro's branch, from commit "(mostly) auto-generated patch to insert casts needed for C++". I validated that the changes make sense and manually reflowed the code to make it respect the coding style. I also found multiple places where I could use XNEW/XNEWVEC/XRESIZEVEC/etc. Thanks a lot to whoever did that automated script to insert casts, doing it completely by hand would have taken a ridiculous amount of time. Only files built on x86 with --enable-targets=all are modified. This means that all other -nat.c files are untouched and will have to be dealt with later by using appropiate compilers. Or maybe we can try to build them with a regular g++ just to know where to add casts, I don't know. I built-tested this with --enable-targets=all and reg-tested. Here's the changelog entry, which was not too bad to make despite the size, thanks to David Malcom's script. I fixed some bits by hand, but there might be some wrong parts left (hopefully not). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_stap_parse_special_token): Add cast to allocation result assignment. * ada-exp.y (write_object_renaming): Likewise. (write_ambiguous_var): Likewise. (ada_nget_field_index): Likewise. (write_var_or_type): Likewise. * ada-lang.c (ada_decode_symbol): Likewise. (ada_value_assign): Likewise. (value_pointer): Likewise. (cache_symbol): Likewise. (add_nonlocal_symbols): Likewise. (ada_name_for_lookup): Likewise. (symbol_completion_add): Likewise. (ada_to_fixed_type_1): Likewise. (ada_get_next_arg): Likewise. (defns_collected): Likewise. * ada-lex.l (processId): Likewise. (processString): Likewise. * ada-tasks.c (read_known_tasks_array): Likewise. (read_known_tasks_list): Likewise. * ada-typeprint.c (decoded_type_name): Likewise. * addrmap.c (addrmap_mutable_create_fixed): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_displaced_step_copy_insn): Likewise. (amd64_classify_insn_at): Likewise. (amd64_relocate_instruction): Likewise. * amd64obsd-tdep.c (amd64obsd_sigtramp_p): Likewise. * arch-utils.c (simple_displaced_step_copy_insn): Likewise. (initialize_current_architecture): Likewise. * arm-linux-tdep.c (arm_stap_parse_special_token): Likewise. * arm-symbian-tdep.c (arm_symbian_osabi_sniffer): Likewise. * arm-tdep.c (arm_exidx_new_objfile): Likewise. (arm_push_dummy_call): Likewise. (extend_buffer_earlier): Likewise. (arm_adjust_breakpoint_address): Likewise. (arm_skip_stub): Likewise. * auto-load.c (filename_is_in_pattern): Likewise. (maybe_add_script_file): Likewise. (maybe_add_script_text): Likewise. (auto_load_objfile_script_1): Likewise. * auxv.c (ld_so_xfer_auxv): Likewise. * ax-general.c (new_agent_expr): Likewise. (grow_expr): Likewise. (ax_reg_mask): Likewise. * bcache.c (bcache_full): Likewise. * breakpoint.c (program_breakpoint_here_p): Likewise. * btrace.c (parse_xml_raw): Likewise. * build-id.c (build_id_to_debug_bfd): Likewise. * buildsym.c (end_symtab_with_blockvector): Likewise. * c-exp.y (string_exp): Likewise. (qualified_name): Likewise. (write_destructor_name): Likewise. (operator_stoken): Likewise. (parse_number): Likewise. (scan_macro_expansion): Likewise. (yylex): Likewise. (c_print_token): Likewise. * c-lang.c (c_get_string): Likewise. (emit_numeric_character): Likewise. * charset.c (wchar_iterate): Likewise. * cli/cli-cmds.c (complete_command): Likewise. (make_command): Likewise. * cli/cli-dump.c (restore_section_callback): Likewise. (restore_binary_file): Likewise. * cli/cli-interp.c (cli_interpreter_exec): Likewise. * cli/cli-script.c (execute_control_command): Likewise. * cli/cli-setshow.c (do_set_command): Likewise. * coff-pe-read.c (add_pe_forwarded_sym): Likewise. (read_pe_exported_syms): Likewise. * coffread.c (coff_read_struct_type): Likewise. (coff_read_enum_type): Likewise. * common/btrace-common.c (btrace_data_append): Likewise. * common/buffer.c (buffer_grow): Likewise. * common/filestuff.c (gdb_fopen_cloexec): Likewise. * common/format.c (parse_format_string): Likewise. * common/gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. * common/xml-utils.c (xml_escape_text): Likewise. * compile/compile-object-load.c (copy_sections): Likewise. (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * completer.c (filename_completer): Likewise. * corefile.c (read_memory_typed_address): Likewise. (write_memory_unsigned_integer): Likewise. (write_memory_signed_integer): Likewise. (complete_set_gnutarget): Likewise. * corelow.c (get_core_register_section): Likewise. * cp-name-parser.y (d_grab): Likewise. (allocate_info): Likewise. (cp_new_demangle_parse_info): Likewise. * cp-namespace.c (cp_scan_for_anonymous_namespaces): Likewise. (cp_lookup_symbol_in_namespace): Likewise. (lookup_namespace_scope): Likewise. (find_symbol_in_baseclass): Likewise. (cp_lookup_nested_symbol): Likewise. (cp_lookup_transparent_type_loop): Likewise. * cp-support.c (copy_string_to_obstack): Likewise. (make_symbol_overload_list): Likewise. (make_symbol_overload_list_namespace): Likewise. (make_symbol_overload_list_adl_namespace): Likewise. (first_component_command): Likewise. * cp-valprint.c (cp_print_value): Likewise. * ctf.c (ctf_xfer_partial): Likewise. * d-exp.y (StringExp): Likewise. * d-namespace.c (d_lookup_symbol_in_module): Likewise. (lookup_module_scope): Likewise. (find_symbol_in_baseclass): Likewise. (d_lookup_nested_symbol): Likewise. * dbxread.c (find_stab_function_addr): Likewise. (read_dbx_symtab): Likewise. (dbx_end_psymtab): Likewise. (cp_set_block_scope): Likewise. * dcache.c (dcache_alloc): Likewise. * demangle.c (_initialize_demangler): Likewise. * dicos-tdep.c (dicos_load_module_p): Likewise. * dictionary.c (dict_create_hashed_expandable): Likewise. (dict_create_linear_expandable): Likewise. (expand_hashtable): Likewise. (add_symbol_linear_expandable): Likewise. * dwarf2-frame.c (add_cie): Likewise. (add_fde): Likewise. (dwarf2_build_frame_info): Likewise. * dwarf2expr.c (dwarf_expr_grow_stack): Likewise. (dwarf_expr_fetch_address): Likewise. (add_piece): Likewise. (execute_stack_op): Likewise. * dwarf2loc.c (chain_candidate): Likewise. (dwarf_entry_parameter_to_value): Likewise. (read_pieced_value): Likewise. (write_pieced_value): Likewise. * dwarf2read.c (dwarf2_read_section): Likewise. (add_type_unit): Likewise. (read_comp_units_from_section): Likewise. (fixup_go_packaging): Likewise. (dwarf2_compute_name): Likewise. (dwarf2_physname): Likewise. (create_dwo_unit_in_dwp_v1): Likewise. (create_dwo_unit_in_dwp_v2): Likewise. (read_func_scope): Likewise. (read_call_site_scope): Likewise. (dwarf2_attach_fields_to_type): Likewise. (process_structure_scope): Likewise. (mark_common_block_symbol_computed): Likewise. (read_common_block): Likewise. (abbrev_table_read_table): Likewise. (guess_partial_die_structure_name): Likewise. (fixup_partial_die): Likewise. (add_file_name): Likewise. (dwarf2_const_value_data): Likewise. (dwarf2_const_value_attr): Likewise. (build_error_marker_type): Likewise. (guess_full_die_structure_name): Likewise. (anonymous_struct_prefix): Likewise. (typename_concat): Likewise. (dwarf2_canonicalize_name): Likewise. (dwarf2_name): Likewise. (write_constant_as_bytes): Likewise. (dwarf2_fetch_constant_bytes): Likewise. (copy_string): Likewise. (parse_macro_definition): Likewise. * elfread.c (elf_symfile_segments): Likewise. (elf_rel_plt_read): Likewise. (elf_gnu_ifunc_resolve_by_cache): Likewise. (elf_gnu_ifunc_resolve_by_got): Likewise. (elf_read_minimal_symbols): Likewise. (elf_gnu_ifunc_record_cache): Likewise. * event-top.c (top_level_prompt): Likewise. (command_line_handler): Likewise. * exec.c (resize_section_table): Likewise. * expprint.c (print_subexp_standard): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * findcmd.c (parse_find_args): Likewise. * findvar.c (address_from_register): Likewise. * frame.c (get_prev_frame_always): Likewise. * gdb_bfd.c (gdb_bfd_ref): Likewise. (get_section_descriptor): Likewise. * gdb_obstack.c (obconcat): Likewise. (obstack_strdup): Likewise. * gdbtypes.c (lookup_function_type_with_arguments): Likewise. (create_set_type): Likewise. (lookup_unsigned_typename): Likewise. (lookup_signed_typename): Likewise. (resolve_dynamic_union): Likewise. (resolve_dynamic_struct): Likewise. (add_dyn_prop): Likewise. (copy_dynamic_prop_list): Likewise. (arch_flags_type): Likewise. (append_composite_type_field_raw): Likewise. * gdbtypes.h (INIT_FUNC_SPECIFIC): Likewise. * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. * go-exp.y (string_exp): Likewise. * go-lang.c (go_demangle): Likewise. * guile/guile.c (compute_scheme_string): Likewise. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. (gdbscm_canonicalize_command_name): Likewise. * guile/scm-ports.c (ioscm_init_stdio_buffers): Likewise. (ioscm_init_memory_port): Likewise. (ioscm_reinit_memory_port): Likewise. * guile/scm-utils.c (gdbscm_gc_xstrdup): Likewise. (gdbscm_gc_dup_argv): Likewise. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (internalize_unwinds): Likewise. (read_unwind_info): Likewise. * i386-cygwin-tdep.c (core_process_module_section): Likewise. (windows_core_xfer_shared_libraries): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. (i386_stap_parse_special_token_triplet): Likewise. (i386_stap_parse_special_token_three_arg_disp): Likewise. * i386obsd-tdep.c (i386obsd_sigtramp_p): Likewise. * inf-child.c (inf_child_fileio_readlink): Likewise. * inf-ptrace.c (inf_ptrace_fetch_register): Likewise. (inf_ptrace_store_register): Likewise. * infrun.c (follow_exec): Likewise. (displaced_step_prepare_throw): Likewise. (save_stop_context): Likewise. (save_infcall_suspend_state): Likewise. * jit.c (jit_read_descriptor): Likewise. (jit_read_code_entry): Likewise. (jit_symtab_line_mapping_add_impl): Likewise. (finalize_symtab): Likewise. (jit_unwind_reg_get_impl): Likewise. * jv-exp.y (QualifiedName): Likewise. * jv-lang.c (get_java_utf8_name): Likewise. (type_from_class): Likewise. (java_demangle_type_signature): Likewise. (java_class_name_from_physname): Likewise. * jv-typeprint.c (java_type_print_base): Likewise. * jv-valprint.c (java_value_print): Likewise. * language.c (add_language): Likewise. * linespec.c (add_sal_to_sals_basic): Likewise. (add_sal_to_sals): Likewise. (decode_objc): Likewise. (find_linespec_symbols): Likewise. * linux-fork.c (fork_save_infrun_state): Likewise. * linux-nat.c (linux_nat_detach): Likewise. (linux_nat_fileio_readlink): Likewise. * linux-record.c (record_linux_sockaddr): Likewise. (record_linux_msghdr): Likewise. (Do): Likewise. * linux-tdep.c (linux_core_info_proc_mappings): Likewise. (linux_collect_regset_section_cb): Likewise. (linux_get_siginfo_data): Likewise. * linux-thread-db.c (try_thread_db_load_from_pdir_1): Likewise. (try_thread_db_load_from_dir): Likewise. (thread_db_load_search): Likewise. (info_auto_load_libthread_db): Likewise. * m32c-tdep.c (m32c_m16c_address_to_pointer): Likewise. (m32c_m16c_pointer_to_address): Likewise. * m68hc11-tdep.c (m68hc11_pseudo_register_write): Likewise. * m68k-tdep.c (m68k_get_longjmp_target): Likewise. * machoread.c (macho_check_dsym): Likewise. * macroexp.c (resize_buffer): Likewise. (gather_arguments): Likewise. (maybe_expand): Likewise. * macrotab.c (new_macro_key): Likewise. (new_source_file): Likewise. (new_macro_definition): Likewise. * mdebugread.c (parse_symbol): Likewise. (parse_type): Likewise. (parse_partial_symbols): Likewise. (psymtab_to_symtab_1): Likewise. * mem-break.c (default_memory_insert_breakpoint): Likewise. * mi/mi-cmd-break.c (mi_argv_to_format): Likewise. * mi/mi-main.c (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_data_write_memory_bytes): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-parse.c (mi_parse_argv): Likewise. (mi_parse): Likewise. * minidebug.c (lzma_open): Likewise. (lzma_pread): Likewise. * mips-tdep.c (mips_read_fp_register_single): Likewise. (mips_print_fp_register): Likewise. * mipsnbsd-tdep.c (mipsnbsd_get_longjmp_target): Likewise. * mipsread.c (read_alphacoff_dynamic_symtab): Likewise. * mt-tdep.c (mt_register_name): Likewise. (mt_registers_info): Likewise. (mt_push_dummy_call): Likewise. * namespace.c (add_using_directive): Likewise. * nat/linux-btrace.c (perf_event_read): Likewise. (linux_enable_bts): Likewise. * nat/linux-osdata.c (linux_common_core_of_thread): Likewise. * nat/linux-ptrace.c (linux_ptrace_test_ret_to_nx): Likewise. * nto-tdep.c (nto_find_and_open_solib): Likewise. (nto_parse_redirection): Likewise. * objc-lang.c (objc_demangle): Likewise. (find_methods): Likewise. * objfiles.c (get_objfile_bfd_data): Likewise. (set_objfile_main_name): Likewise. (allocate_objfile): Likewise. (objfile_relocate): Likewise. (update_section_map): Likewise. * osabi.c (generic_elf_osabi_sniff_abi_tag_sections): Likewise. * p-exp.y (exp): Likewise. (yylex): Likewise. * p-valprint.c (pascal_object_print_value): Likewise. * parse.c (initialize_expout): Likewise. (mark_completion_tag): Likewise. (copy_name): Likewise. (parse_float): Likewise. (type_stack_reserve): Likewise. * ppc-linux-tdep.c (ppc_stap_parse_special_token): Likewise. (ppu2spu_prev_register): Likewise. * ppc-ravenscar-thread.c (supply_register_at_address): Likewise. * printcmd.c (printf_wide_c_string): Likewise. (printf_pointer): Likewise. * probe.c (parse_probes): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. (cmdpy_init): Likewise. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Likewise. * python/py-symtab.c (set_sal): Likewise. * python/py-unwind.c (pyuw_sniffer): Likewise. * python/python.c (python_interactive_command): Likewise. (compute_python_string): Likewise. * ravenscar-thread.c (get_running_thread_id): Likewise. * record-full.c (record_full_exec_insn): Likewise. (record_full_core_open_1): Likewise. * regcache.c (regcache_raw_read_signed): Likewise. (regcache_raw_read_unsigned): Likewise. (regcache_cooked_read_signed): Likewise. (regcache_cooked_read_unsigned): Likewise. * remote-fileio.c (remote_fileio_func_open): Likewise. (remote_fileio_func_rename): Likewise. (remote_fileio_func_unlink): Likewise. (remote_fileio_func_stat): Likewise. (remote_fileio_func_system): Likewise. * remote-mips.c (mips_xfer_memory): Likewise. (mips_load_srec): Likewise. (pmon_end_download): Likewise. * remote.c (new_remote_state): Likewise. (map_regcache_remote_table): Likewise. (remote_register_number_and_offset): Likewise. (init_remote_state): Likewise. (get_memory_packet_size): Likewise. (remote_pass_signals): Likewise. (remote_program_signals): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (remote_query_supported): Likewise. (extended_remote_attach): Likewise. (process_g_packet): Likewise. (store_registers_using_G): Likewise. (putpkt_binary): Likewise. (read_frame): Likewise. (compare_sections_command): Likewise. (remote_hostio_pread): Likewise. (remote_hostio_readlink): Likewise. (remote_file_put): Likewise. (remote_file_get): Likewise. (remote_pid_to_exec_file): Likewise. (_initialize_remote): Likewise. * rs6000-aix-tdep.c (rs6000_aix_ld_info_to_xml): Likewise. (rs6000_aix_core_xfer_shared_libraries_aix): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. (bfd_uses_spe_extensions): Likewise. * s390-linux-tdep.c (s390_displaced_step_copy_insn): Likewise. * score-tdep.c (score7_malloc_and_get_memblock): Likewise. * solib-dsbt.c (decode_loadmap): Likewise. (fetch_loadmap): Likewise. (scan_dyntag): Likewise. (enable_break): Likewise. (dsbt_relocate_main_executable): Likewise. * solib-frv.c (fetch_loadmap): Likewise. (enable_break2): Likewise. (frv_relocate_main_executable): Likewise. * solib-spu.c (spu_relocate_main_executable): Likewise. (spu_bfd_open): Likewise. * solib-svr4.c (lm_info_read): Likewise. (read_program_header): Likewise. (find_program_interpreter): Likewise. (scan_dyntag): Likewise. (elf_locate_base): Likewise. (open_symbol_file_object): Likewise. (read_program_headers_from_bfd): Likewise. (svr4_relocate_main_executable): Likewise. * solib-target.c (solib_target_relocate_section_addresses): Likewise. * solib.c (solib_find_1): Likewise. (exec_file_find): Likewise. (solib_find): Likewise. * source.c (openp): Likewise. (print_source_lines_base): Likewise. (forward_search_command): Likewise. * sparc-ravenscar-thread.c (supply_register_at_address): Likewise. * spu-tdep.c (spu2ppu_prev_register): Likewise. (spu_get_overlay_table): Likewise. * stabsread.c (patch_block_stabs): Likewise. (define_symbol): Likewise. (again:): Likewise. (read_member_functions): Likewise. (read_one_struct_field): Likewise. (read_enum_type): Likewise. (common_block_start): Likewise. * stack.c (read_frame_arg): Likewise. (backtrace_command): Likewise. * stap-probe.c (stap_parse_register_operand): Likewise. * symfile.c (syms_from_objfile_1): Likewise. (find_separate_debug_file): Likewise. (load_command): Likewise. (load_progress): Likewise. (load_section_callback): Likewise. (reread_symbols): Likewise. (add_filename_language): Likewise. (allocate_compunit_symtab): Likewise. (read_target_long_array): Likewise. (simple_read_overlay_table): Likewise. * symtab.c (symbol_set_names): Likewise. (resize_symbol_cache): Likewise. (rbreak_command): Likewise. (completion_list_add_name): Likewise. (completion_list_objc_symbol): Likewise. (add_filename_to_list): Likewise. * target-descriptions.c (maint_print_c_tdesc_cmd): Likewise. * target-memory.c (target_write_memory_blocks): Likewise. * target.c (target_read_string): Likewise. (read_whatever_is_readable): Likewise. (target_read_alloc_1): Likewise. (simple_search_memory): Likewise. (target_fileio_read_alloc_1): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * top.c (command_line_input): Likewise. * tracefile-tfile.c (tfile_fetch_registers): Likewise. * tracefile.c (tracefile_fetch_registers): Likewise. * tracepoint.c (add_memrange): Likewise. (init_collection_list): Likewise. (add_aexpr): Likewise. (trace_dump_actions): Likewise. (parse_trace_status): Likewise. (parse_tracepoint_definition): Likewise. (parse_tsv_definition): Likewise. (parse_static_tracepoint_marker_definition): Likewise. * tui/tui-file.c (tui_sfileopen): Likewise. (tui_file_adjust_strbuf): Likewise. * tui/tui-io.c (tui_expand_tabs): Likewise. * tui/tui-source.c (tui_set_source_content): Likewise. * typeprint.c (find_global_typedef): Likewise. * ui-file.c (do_ui_file_xstrdup): Likewise. (ui_file_obsavestring): Likewise. (mem_file_write): Likewise. * utils.c (make_hex_string): Likewise. (get_regcomp_error): Likewise. (puts_filtered_tabular): Likewise. (gdb_realpath_keepfile): Likewise. (ldirname): Likewise. (gdb_bfd_errmsg): Likewise. (substitute_path_component): Likewise. * valops.c (search_struct_method): Likewise. (find_oload_champ_namespace_loop): Likewise. * valprint.c (print_decimal_chars): Likewise. (read_string): Likewise. (generic_emit_char): Likewise. * varobj.c (varobj_delete): Likewise. (varobj_value_get_print_value): Likewise. * vaxobsd-tdep.c (vaxobsd_sigtramp_sniffer): Likewise. * windows-tdep.c (display_one_tib): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. (process_xcoff_symbol): Likewise. (swap_sym): Likewise. (scan_xcoff_symtab): Likewise. (xcoff_initial_scan): Likewise. * xml-support.c (gdb_xml_end_element): Likewise. (xml_process_xincludes): Likewise. (xml_fetch_content_from_file): Likewise. * xml-syscall.c (xml_list_of_syscalls): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. gdb/gdbserver/ChangeLog: * ax.c (gdb_parse_agent_expr): Add cast to allocation result assignment. (gdb_unparse_agent_expr): Likewise. * hostio.c (require_data): Likewise. (handle_pread): Likewise. * linux-low.c (disable_regset): Likewise. (fetch_register): Likewise. (store_register): Likewise. (get_dynamic): Likewise. (linux_qxfer_libraries_svr4): Likewise. * mem-break.c (delete_fast_tracepoint_jump): Likewise. (set_fast_tracepoint_jump): Likewise. (uninsert_fast_tracepoint_jumps_at): Likewise. (reinsert_fast_tracepoint_jumps_at): Likewise. (validate_inserted_breakpoint): Likewise. (clone_agent_expr): Likewise. * regcache.c (init_register_cache): Likewise. * remote-utils.c (putpkt_binary_1): Likewise. (decode_M_packet): Likewise. (decode_X_packet): Likewise. (look_up_one_symbol): Likewise. (relocate_instruction): Likewise. (monitor_output): Likewise. * server.c (handle_search_memory): Likewise. (handle_qxfer_exec_file): Likewise. (handle_qxfer_libraries): Likewise. (handle_qxfer): Likewise. (handle_query): Likewise. (handle_v_cont): Likewise. (handle_v_run): Likewise. (captured_main): Likewise. * target.c (write_inferior_memory): Likewise. * thread-db.c (try_thread_db_load_from_dir): Likewise. * tracepoint.c (init_trace_buffer): Likewise. (add_tracepoint_action): Likewise. (add_traceframe): Likewise. (add_traceframe_block): Likewise. (cmd_qtdpsrc): Likewise. (cmd_qtdv): Likewise. (cmd_qtstatus): Likewise. (response_source): Likewise. (response_tsv): Likewise. (cmd_qtnotes): Likewise. (gdb_collect): Likewise. (initialize_tracepoint): Likewise.
2015-09-25 20:08:06 +02:00
ret = (char *) xmalloc (len + 1);
memcpy (ret, buf, len);
ret[len] = '\0';
return ret;
}
/* Implementation of to_fileio_unlink. */
static int
linux_nat_fileio_unlink (struct target_ops *self,
struct inferior *inf, const char *filename,
int *target_errno)
{
int ret;
ret = linux_mntns_unlink (linux_nat_fileio_pid_of (inf),
filename);
if (ret == -1)
*target_errno = host_to_fileio_error (errno);
return ret;
}
/* Implementation of the to_thread_events method. */
static void
linux_nat_thread_events (struct target_ops *ops, int enable)
{
report_thread_events = enable;
}
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
void
linux_nat_add_target (struct target_ops *t)
{
/* Save the provided single-threaded target. We save this in a separate
variable because another target we've inherited from (e.g. inf-ptrace)
may have saved a pointer to T; we want to use it for the final
process stratum target. */
linux_ops_saved = *t;
linux_ops = &linux_ops_saved;
/* Override some methods for multithreading. */
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
t->to_create_inferior = linux_nat_create_inferior;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
t->to_attach = linux_nat_attach;
t->to_detach = linux_nat_detach;
t->to_resume = linux_nat_resume;
t->to_wait = linux_nat_wait;
* target.h (struct target_ops): Remove to_notice_signals; add to_pass_signals. (target_notice_signals): Remove. (target_pass_signals): Add prototype. * target.c (update_current_target): Remove to_notice_signals; mention to_pass_signals. (target_pass_signals): New function. (debug_to_notice_signals): Remove. (setup_target_debug): Do not install debug_to_notice_signals. * infrun.c (signal_pass): New global. (resume): Call target_pass_signals. (handle_inferior_event): Report all signals while stepping over non-steppable watchpoint. Reset trap_expected to ensure breakpoints are re-inserted when stepping over a signal handler. (signal_cache_update): New function. (signal_stop_update): Call it. (signal_print_update): Likewise. (signal_pass_update): Likewise. (handle_command): Call signal_cache_update and target_pass_signals instead of target_notice_signals. (_initialize_infrun): Initialize signal_pass. * linux-nat.c (pass_mask): New global. (linux_nat_pass_signals): New function. (linux_nat_create_inferior): Report all signals initially. (linux_nat_attach): Likewise. (linux_nat_resume): Use pass_mask to decide whether to directly handle an inferior signal. (linux_nat_wait_1): Likewise. (linux_nat_add_target): Install to_pass_signals callback. * nto-procfs.c (notice_signals): Remove. (procfs_resume): Do not call notice_signals. (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (init_procfs_ops): Install to_pass_signals callback instead of to_notice_signals callback. (_initialize_procfs): Report all signals initially. * procfs.c (procfs_notice_signals): Remove. (procfs_pass_signals): New function. (procfs_target): Install to_pass_signals callback instead of to_notice_signals callback. (register_gdb_signals): Remove. (procfs_debug_inferior): Report all signals initially. (procfs_init_inferior): Remove redundant register_gdb_signals call. * remote.c (remote_pass_signals): Add numsigs and pass_signals parameters; use them instead of calling signal_..._state routines. (remote_notice_signals): Remove. (remote_start_remote): Report all signals initially. (remote_resume): Do not call remote_pass_signals. (_initialize_remote): Install to_pass_signals callback instead of to_notice_signals callback.
2011-04-27 15:29:15 +02:00
t->to_pass_signals = linux_nat_pass_signals;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
t->to_xfer_partial = linux_nat_xfer_partial;
t->to_kill = linux_nat_kill;
t->to_mourn_inferior = linux_nat_mourn_inferior;
t->to_thread_alive = linux_nat_thread_alive;
update thread list, delete exited threads On GNU/Linux, if the running kernel supports clone events, then linux-thread-db.c defers thread listing to the target beneath: static void thread_db_update_thread_list (struct target_ops *ops) { ... if (target_has_execution && !thread_db_use_events ()) ops->beneath->to_update_thread_list (ops->beneath); else thread_db_update_thread_list_td_ta_thr_iter (ops); ... } However, when live debugging, the target beneath, linux-nat.c, does not implement the to_update_thread_list method. The result is that if a thread is marked exited (because it can't be deleted right now, e.g., it was the selected thread), then it won't ever be deleted, until the process exits or is killed/detached. A similar thing happens with the remote.c target. Because its target_update_thread_list implementation skips exited threads when it walks the current thread list looking for threads that no longer exits on the target side, using ALL_NON_EXITED_THREADS_SAFE, stale exited threads are never deleted. This is not a big deal -- I can't think of any way this might be user visible, other than gdb's memory growing a tiny bit whenever a thread gets stuck in exited state. Still, might as well clean things up properly. All other targets use prune_threads, so are unaffected. The fix adds a ALL_THREADS_SAFE macro, that like ALL_NON_EXITED_THREADS_SAFE, walks the thread list and allows deleting the iterated thread, and uses that in places that are walking the thread list in order to delete threads. Actually, after converting linux-nat.c and remote.c to use this, we find the only other user of ALL_NON_EXITED_THREADS_SAFE is also walking the list to delete threads. So we convert that too, and end up deleting ALL_NON_EXITED_THREADS_SAFE. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog 2015-04-07 Pedro Alves <palves@redhat.com> * gdbthread.h (ALL_NON_EXITED_THREADS_SAFE): Rename to ... (ALL_THREADS_SAFE): ... this, and don't skip exited threads. (delete_exited_threads): New declaration. * infrun.c (follow_exec): Use ALL_THREADS_SAFE. * linux-nat.c (linux_nat_update_thread_list): New function. (linux_nat_add_target): Install it. * remote.c (remote_update_thread_list): Use ALL_THREADS_SAFE. * thread.c (prune_threads): Use ALL_THREADS_SAFE. (delete_exited_threads): New function.
2015-04-07 16:47:22 +02:00
t->to_update_thread_list = linux_nat_update_thread_list;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
t->to_pid_to_str = linux_nat_pid_to_str;
t->to_thread_name = linux_nat_thread_name;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
t->to_has_thread_control = tc_schedlock;
t->to_thread_address_space = linux_nat_thread_address_space;
t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint;
t->to_stopped_data_address = linux_nat_stopped_data_address;
t->to_stopped_by_sw_breakpoint = linux_nat_stopped_by_sw_breakpoint;
t->to_supports_stopped_by_sw_breakpoint = linux_nat_supports_stopped_by_sw_breakpoint;
t->to_stopped_by_hw_breakpoint = linux_nat_stopped_by_hw_breakpoint;
t->to_supports_stopped_by_hw_breakpoint = linux_nat_supports_stopped_by_hw_breakpoint;
t->to_thread_events = linux_nat_thread_events;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
t->to_can_async_p = linux_nat_can_async_p;
t->to_is_async_p = linux_nat_is_async_p;
t->to_supports_non_stop = linux_nat_supports_non_stop;
Implement all-stop on top of a target running non-stop mode This finally implements user-visible all-stop mode running with the target_ops backend always in non-stop mode. This is a stepping stone towards finer-grained control of threads, being able to do interesting things like thread groups, associating groups with breakpoints, etc. From the user's perspective, all-stop mode is really just a special case of being able to stop and resume specific sets of threads, so it makes sense to do this step first. With this, even in all-stop, the target is no longer in charge of stopping all threads before reporting an event to the core -- the core takes care of it when it sees fit. For example, when "next"- or "step"-ing, we can avoid stopping and resuming all threads at each internal single-step, and instead only stop all threads when we're about to present the stop to the user. The implementation is almost straight forward, as the heavy lifting has been done already in previous patches. Basically, we replace checks for "set non-stop on/off" (the non_stop global), with calls to a new target_is_non_stop_p function. In a few places, if "set non-stop off", we stop all threads explicitly, and in a few other places we resume all threads explicitly, making use of existing methods that were added for teaching non-stop to step over breakpoints without displaced stepping. This adds a new "maint set target-non-stop on/off/auto" knob that allows both disabling the feature if we find problems, and force-enable it for development (useful when teaching a target about this. The default is "auto", which means the feature is enabled if a new target method says it should be enabled. The patch implements the method in linux-nat.c, just for illustration, because it still returns false. We'll need a few follow up fixes before turning it on by default. This is a separate target method from indicating regular non-stop support, because e.g., while e.g., native linux-nat.c is close to regression free with all-stop-non-stop (with following patches will fixing the remaining regressions), remote.c+gdbserver will still need more fixing, even though it supports "set non-stop on". Tested on x86_64 Fedora 20, native, with and without "set displaced off", and with and without "maint set target-non-stop on"; and also against gdbserver. gdb/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * NEWS: Mention "maint set/show target-non-stop". * breakpoint.c (update_global_location_list): Check target_is_non_stop_p instead of non_stop. * infcmd.c (attach_command_post_wait, attach_command): Likewise. * infrun.c (show_can_use_displaced_stepping) (can_use_displaced_stepping_p, start_step_over_inferior): Likewise. (internal_resume_ptid): New function. (resume): Use it. (proceed): Check target_is_non_stop_p instead of non_stop. If in all-stop mode but the target is always in non-stop mode, start all the other threads that are implicitly resumed too. (for_each_just_stopped_thread, fetch_inferior_event) (adjust_pc_after_break, stop_all_threads): Check target_is_non_stop_p instead of non_stop. (handle_inferior_event): Likewise. Handle detach-fork in all-stop with the target always in non-stop mode. (handle_signal_stop) <random signal>: Check target_is_non_stop_p instead of non_stop. (switch_back_to_stepped_thread): Check target_is_non_stop_p instead of non_stop. (keep_going_stepped_thread): Use internal_resume_ptid. (stop_waiting): If in all-stop mode, and the target is in non-stop mode, stop all threads. (keep_going_pass): Likewise, when starting a new in-line step-over sequence. * linux-nat.c (get_pending_status, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1, linux_nat_wait): Check target_is_non_stop_p instead of non_stop. (linux_nat_always_non_stop_p): New function. (linux_nat_stop): Check target_is_non_stop_p instead of non_stop. (linux_nat_add_target): Install linux_nat_always_non_stop_p. * target-delegates.c: Regenerate. * target.c (target_is_non_stop_p): New function. (target_non_stop_enabled, target_non_stop_enabled_1): New globals. (maint_set_target_non_stop_command) (maint_show_target_non_stop_command): New functions. (_initilize_target): Install "maint set/show target-non-stop" commands. * target.h (struct target_ops) <to_always_non_stop_p>: New field. (target_non_stop_enabled): New declaration. (target_is_non_stop_p): New declaration. gdb/doc/ChangeLog: 2015-08-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Maintenance Commands): Document "maint set/show target-non-stop".
2015-08-07 18:24:01 +02:00
t->to_always_non_stop_p = linux_nat_always_non_stop_p;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
t->to_async = linux_nat_async;
t->to_terminal_inferior = linux_nat_terminal_inferior;
t->to_terminal_ours = linux_nat_terminal_ours;
Allow making GDB not automatically connect to the native target. Sometimes it's useful to be able to disable the automatic connection to the native target. E.g., sometimes GDB disconnects from the extended-remote target I was debugging, without me noticing it, and then I do "run". That starts the program locally, and only after a little head scratch session do I figure out the program is running locally instead of remotely as intended. Same thing with "attach", "info os", etc. With the patch, we now can have this instead: (gdb) set auto-connect-native-target off (gdb) target extended-remote :9999 ... *gdb disconnects* (gdb) run Don't know how to run. Try "help target". To still be able to connect to the native target with auto-connect-native-target set to off, I've made "target native" work instead of erroring out as today. Before: (gdb) target native Use the "run" command to start a native process. After: (gdb) target native Done. Use the "run" command to start a process. (gdb) maint print target-stack The current target stack is: - native (Native process) - exec (Local exec file) - None (None) (gdb) run Starting program: ./a.out ... I've also wanted this for the testsuite, when running against the native-extended-gdbserver.exp board (runs against gdbserver in extended-remote mode). With a non-native-target board, it's always a bug to launch a program with the native target. Turns out we still have one such case this patch catches: (gdb) break main Breakpoint 1 at 0x4009e5: file ../../../src/gdb/testsuite/gdb.base/coremaker.c, line 138. (gdb) run Don't know how to run. Try "help target". (gdb) FAIL: gdb.base/corefile.exp: run: with core On the patch itself, probably the least obvious bit is the need to go through all targets, and move the unpush_target call to after the generic_mourn_inferior call instead of before. This is what inf-ptrace.c does too, ever since multi-process support was added. The reason inf-ptrace.c does things in that order is that in the current multi-process/single-target model, we shouldn't unpush the target if there are still other live inferiors being debugged. The check for that is "have_inferiors ()" (a misnomer nowadays...), which does: have_inferiors (void) { for (inf = inferior_list; inf; inf = inf->next) if (inf->pid != 0) return 1; It's generic_mourn_inferior that ends up clearing inf->pid, so we need to call it before the have_inferiors check. To make all native targets behave the same WRT to explicit "target native", I've added an inf_child_maybe_unpush_target function that targets call instead of calling unpush_target directly, and as that includes the have_inferiors check, I needed to adjust the targets. Tested on x86_64 Fedora 20, native, and also with the extended-gdbserver board. Confirmed a cross build of djgpp gdb still builds. Smoke tested a cross build of Windows gdb under Wine. Untested otherwise. gdb/ 2014-05-21 Pedro Alves <palves@redhat.com> * inf-child.c (inf_child_ops, inf_child_explicitly_opened): New globals. (inf_child_open_target): New function. (inf_child_open): Use inf_child_open_target to push the target instead of erroring out. (inf_child_disconnect, inf_child_close) (inf_child_maybe_unpush_target): New functions. (inf_child_target): Install inf_child_disconnect and inf_child_close. Store a pointer to the returned object. * inf-child.h (inf_child_open_target, inf_child_maybe_unpush): New declarations. * target.c (auto_connect_native_target): New global. (show_default_run_target): New function. (find_default_run_target): Return NULL if automatically connecting to the native target is disabled. (_initialize_target): Install set/show auto-connect-native-target. * NEWS: Mention "set auto-connect-native-target", and "target native". * linux-nat.c (super_close): New global. (linux_nat_close): Call super_close. (linux_nat_add_target): Store a pointer to the base class's to_close method. * inf-ptrace.c (inf_ptrace_mourn_inferior, inf_ptrace_detach): Use inf_child_maybe_unpush. * inf-ttrace.c (inf_ttrace_him): Don't push the target if it is already pushed. (inf_ttrace_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (inf_ttrace_attach): Don't push the target if it is already pushed. (inf_ttrace_detach): Use inf_child_maybe_unpush_target. * darwin-nat.c (darwin_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (darwin_attach_pid): Don't push the target if it is already pushed. * gnu-nat.c (gnu_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (gnu_detach): Use inf_child_maybe_unpush_target. * go32-nat.c (go32_create_inferior): Don't push the target if it is already pushed. (go32_mourn_inferior): Use inf_child_maybe_unpush_target. * nto-procfs.c (procfs_is_nto_target): Adjust comment. (procfs_open): Rename to ... (procfs_open_1): ... this. Add target_ops parameter. Adjust comments. Can target_preopen before changing node. Call inf_child_open_target to push the target explicitly. (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_create_inferior): Don't push the target if it is already pushed. (nto_native_ops): New global. (procfs_open): Reimplement. (procfs_native_open): New function. (init_procfs_targets): Install procfs_native_open as to_open of "target native". Store a pointer to the "native" target in nto_native_ops. * procfs.c (procfs_attach): Don't push the target if it is already pushed. (procfs_detach): Use inf_child_maybe_unpush_target. (procfs_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. (procfs_init_inferior): Don't push the target if it is already pushed. * windows-nat.c (do_initial_windows_stuff): Don't push the target if it is already pushed. (windows_detach): Use inf_child_maybe_unpush_target. (windows_mourn_inferior): Only unpush the target after mourning the inferior. Use inf_child_maybe_unpush_target. gdb/doc/ 2014-05-21 Pedro Alves <palves@redhat.com> * gdb.texinfo (Starting): Document "set/show auto-connect-native-target". (Target Commands): Document "target native". gdb/testsuite/ 2014-05-21 Pedro Alves <palves@redhat.com> * boards/gdbserver-base.exp (GDBFLAGS): Set to "set auto-connect-native-target off". * gdb.base/auto-connect-native-target.c: New file. * gdb.base/auto-connect-native-target.exp: New file.
2014-05-21 19:30:47 +02:00
super_close = t->to_close;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
t->to_close = linux_nat_close;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
t->to_stop = linux_nat_stop;
* fork-child.c (fork_inferior): Only reset the thread list if this is the first inferior. (startup_inferior): If the target support multi-process, tell it to resume only the new process. * linux-nat.c (num_lwps): Delete global. (purge_lwp_list): New function. (num_lwps): New function. (add_lwp, delete_lwp): Adjust. (ptid_match): New. (iterate_over_lwps): Add filter argument. Handle it. (linux_nat_attach): Remove FIXME note. (linux_nat_detach): Adjust to iterate over threads of the inferior we're detaching from. Adjust to num_lwps being a function. Don't assume the head of the lwp list is the main thread of the process we're detaching from. Don't destroy the LWP list. (resume_callback): Add debug output. (linux_nat_resume): Handle resuming a single inferior. Allow a wildcard resume in non-stop mode. (linux_handle_extended_wait): Don't assume inferior_ptid is the correct inferior of the parent LWP. (status_callback): Also check lp->waitstatus. (select_event_lwp): Add new filter parameter. Handle it. (linux_nat_filter_event): Adjust to num_lwps being a function. (linux_nat_wait_1): When adding the first lwp of the inferior, use an is_lwp check instead of checking for the number of lwps. (linux_nat_wait_1): Handle waiting for a specific tgid. Handle pending process exit statuses. (linux_nat_mourn_inferior): Don't destroy all the LWP info. Instead delete LWPs of the inferior that we're mourning. Don't unregister from the event loop here. (linux_nat_pid_to_str): Use `num_lwps'. (linux_nat_make_corefile_notes): Adjust to walk over lwps of a single inferior. (linux_nat_is_async_p): Check if async was masked out. (linux_multi_process): New global. (linux_nat_supports_multi_process): New. (linux_nat_stop_lwp): Remove LWP filtering. It is done by the caller. (linux_nat_stop): Adjust to make iterate_over_lwps itself do the LWP filtering. (linux_nat_close): New. (linux_nat_add_target): Register linux_nat_close and linux_nat_supports_multi_process. * linux-nat.h (iterate_over_lwps): Add filter argument. * linux-thread-db.c (thread_db_handle): Delete. (proc_handle, thread_agent, td_init_p, td_ta_new_p) (td_ta_map_id2thr_p, td_ta_map_lwp2thr_p, td_ta_thr_iter_p) (td_ta_event_addr_p, td_ta_set_event_p, td_ta_event_getmsg_p) (td_thr_validate_p, td_thr_get_info_p, td_thr_event_enable_p) (td_thr_tls_get_addr_p, td_create_bp_addr, td_death_bp_addr): No longer globals, moved to... (struct thread_db_info): ... this new structure. (thread_db_list): New. (add_thread_db_info, get_thread_db_info, delete_thread_db_info): New. (have_threads_callback): Filter out threads of all inferiors but the one specified by the ARGS argument. (have_threads): Add ptid argument specifying the inferior we're interested in. Handle it. (struct thread_get_info_inout): New. (thread_get_info_callback, thread_from_lwp): Adjust to use it. (thread_db_attach_lwp): Check that inferior of the passed in thread is using thread-db. Adjust. (enable_thread_event): Remove thread_agent parameter. Instead, get it from the per-inferior thread-db info. (dladdr_to_soname): Move higher up. (enable_thread_event_reporting): Adjust to use per-inferior thread-db info. (try_thread_db_load_1): Replace `handle' parameter by a thread_db_info parameter. Adjust to use per-inferior thread-db info. (try_thread_db_load): Adjust to use per-inferior thread-db info. (thread_db_load, disable_thread_event_reporting): Ditto. (check_for_thread_db): Remove conditional reporting of which libthread_db is in use. (thread_db_new_objfile): Add comment about inferior_ptid. (attach_thread): Adjust to use per-inferior thread-db info. (thread_db_detach): Adjust to use per-inferior thread-db info. Remove thread event breakpoints of the current inferior. Only unpush the thread-db target if there are no more processes using it. (check_event): Adjust to use per-inferior thread-db info. (thread_db_wait): Adjust to use per-inferior thread-db info. Only unpush the thread-db target if there are no more processes using it. (thread_db_mourn_inferior): Adjust to use per-inferior thread-db info. Mark breakpoints of the current inferior out before deleting them. Only unpush the thread-db target if there are no more processes using it. (find_new_threads_callback): Adjust to use per-inferior thread_db info. (thread_db_find_new_threads_1): Add new ptid argument. Adjust to use per-inferior thread-db info. (thread_db_find_new_threads): Adjust to use per-inferior thread-db info. (thread_db_get_thread_local_address): Adjust. (thread_db_get_ada_task_ptid): Adjust. * inf-ptrace.c (inf_ptrace_mourn_inferior): Only unpush the target if there no more processes left to debug. * thread.c (set_running, set_executing): Handle resuming all threads of a single inferior. * mi/mi-interp.c (mi_output_running_pid): New. (mi_inferior_count): New. (mi_on_resume): For backwards compatibility, if resuming all threads of an inferior, and there is only one inferior, output "all".
2009-05-18 16:07:18 +02:00
t->to_supports_multi_process = linux_nat_supports_multi_process;
* inferior.h (disable_randomization): Declare. * infrun.c (disable_randomization): New global variable. (show_disable_randomization): New function. (set_disable_randomization): Likewise. (_initialize_infrun): Install set/show disable-randomization commands. * linux-nat.c (disable_randomization): Remove. (show_disable_randomization): Likewise. (set_disable_randomization): Likewise. (_initialize_linux_nat): No longer install set/show disable-randomization commands here. (linux_nat_supports_disable_randomization): New function. (linux_nat_add_target): Install it. * remote.c (PACKET_QDisableRandomization): New enum value. (remote_protocol_packets): Support QDisableRandomization. (_initialize_remote): Likewise. (remote_supports_disable_randomization): New function. (init_remote_ops): Install it. (extended_remote_supports_disable_randomization): New function. (init_extended_remote_ops): Install it. (extended_remote_disable_randomization): New function. (extended_remote_create_inferior_1): Call it. * target.h (struct target_ops): Add to_supports_disable_randomization. (target_supports_disable_randomization): Add prototype. * target.c (target_supports_disable_randomization): New function. (find_default_supports_disable_randomization): Likewise. (init_dummy_target): Install it. doc/ * gdb.texinfo (Starting your Program): "set disable-randomization" is no longer Linux-specific. (Remote Configuration): Document "set remote disable-randomization-packet". (General Query Packets): Document "QDisableRandomization" packet and add it to "qSupported" list. gdbserver/ * configure.ac: Check support for personality routine. * configure: Regenerate. * config.in: Likewise. * linux-low.c: Include <sys/personality.h>. Define ADDR_NO_RANDOMIZE if necessary. (linux_create_inferior): Disable address space randomization when forking inferior, if requested. (linux_supports_disable_randomization): New function. (linux_target_ops): Install it. * server.h (disable_randomization): Declare. * server.c (disable_randomization): New global variable. (handle_general_set): Handle QDisableRandomization. (handle_query): Likewise for qSupported. (main): Support --disable-randomization and --no-disable-randomization command line arguments. * target.h (struct target_ops): Add supports_disable_randomization. (target_supports_disable_randomization): New macro.
2011-10-07 14:06:48 +02:00
t->to_supports_disable_randomization
= linux_nat_supports_disable_randomization;
Implement core awareness. * bcache.c (compare_ints): Remove (print_percentage): Use compare_positive_ints. * defs.h (compare_positive_ints): Declare. * linux-nat.h (struct lin_lwp): New field core. (linux_nat_core_of_thread_1): Declare. * linux-nat.c (add_lwp): Init the 'core' field. (linux_nat_wait_1): Record the core. (linux_nat_core_of_thread_1, linux_nat_core_of_thread): New. (linux_nat_add_target): Register the above. * linux-thread-db.c (update_thread_core): New. (thread_db_find_new_threads): Update core information for every thread. * remote.c (struct private_thread_info): New. (free_private_thread_info, demand_private_info): New. (PACKET_qXfer_threads, use_osdata_threads): New. (struct thread_item, threads_parsing_context (start_thread, end_thread, thread_attributes) (thread_children, threads_children, threads_elements): New. (remote_threads_info): Try qXfer:threads before anything else. (remote_protocol_packets): Register qXfer:threads. (remote_open_1): Init use_osdata_threads. (struct stop_reply): New field 'core'. (remote_parse_stop_reply): Parse core number. (process_stop_reply): Record core number. (remote_xfer_partial): Handle qXfer:threads. (remote_core_of_thread): New. (init_remote_ops): Register remote_core_of_thread. (_initialize_remote): Register qXfer:read. * target.c (target_core_of_thread): New * target.h (enum target_object): New value TARGET_OBJECT_THREADS. (struct target_ops): New field to_core_of_threads. (target_core_of_thread): Declare. * gdbthread.h (struct thread_info): New field private_dtor. * thread.c (print_thread_info): Report the core. * ui-out.c (MAX_UI_OUT_LEVELS): Increase. * utils.c (compare_positive_ints): New. * features/threads.dtd: New. * mi/mi-interp.c (mi_on_normal_stop): Report the core. * mi/mi-main.c (struct collect_cores_data, collect_cores) (do_nothing, free_vector_of_osdata_items) (splay_tree_int_comparator, free_splay_tree): New. (print_one_inferior_data): Implemented printing of selected inferiors. Collect and print cores. (output_cores): New. (mi_cmd_list_thread_groups): Support --recurse. Permit specifying thread groups together with --available.
2010-01-12 22:40:25 +01:00
t->to_core_of_thread = linux_nat_core_of_thread;
t->to_filesystem_is_local = linux_nat_filesystem_is_local;
t->to_fileio_open = linux_nat_fileio_open;
t->to_fileio_readlink = linux_nat_fileio_readlink;
t->to_fileio_unlink = linux_nat_fileio_unlink;
* linux-nat.c (linux_ops_saved): New. (super_mourn_inferior, kill_inferior, threaded, linux_nat_ops) (child_mourn_inferior, child_wait, linux_nat_create_inferior) (linux_nat_fetch_registers, linux_nat_store_registers) (linux_nat_child_post_startup_inferior, init_linux_nat_ops): Delete. (init_lwp_list): Don't set threaded. (add_lwp): Don't modify threaded. (delete_lwp): Don't mention non-threaded mode. (linux_nat_switch_fork): New. (linux_nat_attach): Update inferior_ptid. (linux_nat_wait): Handle num_lwps == 0 at entry. Don't check threaded flag. (linux_nat_kill): Handle pending forks and saved forks. (linux_nat_mourn_inferior): Handle saved forks. (linux_nat_pid_to_str): Don't use the LWP form when there is only one thread. (linux_target): Don't set to_wait, to_kill, or to_mourn_inferior. (linux_nat_add_target): New. (_initialize_linux_nat): Don't initialize the linux native target here. * linux-nat.h (linux_nat_add_target, linux_nat_switch_fork): New prototypes. * linux-fork.c: Include "linux-nat.h". (add_fork): Update initial PID. (fork_load_infrun_state): Call linux_nat_switch_fork. * Makefile.in (linux-fork.o): Update. * alpha-linux-nat.c (_initialize_alpha_linux_nat): Use linux_nat_add_target instead of add_target. * amd64-linux-nat.c (_initialize_amd64_linux_nat): Likewise. * arm-linux-nat.c (_initialize_arm_linux_nat): Likewise. * hppa-linux-nat.c (_initialize_hppa_linux_nat): Likewise. * ia64-linux-nat.c (_initialize_ia64_linux_nat): Likewise. * i386-linux-nat.c (_initialize_i386_linux_nat): Likewise. * m32r-linux-nat.c (_initialize_m32r_linux_nat): Likewise. * m68klinux-nat.c (_initialize_m68k_linux_nat): Likewise. * mips-linux-nat.c (_initialize_mips_linux_nat): Likewise. * ppc-linux-nat.c (_initialize_ppc_linux_nat): Likewise. * s390-nat.c (_initialize_s390_nat): Likewise. * sparc-linux-nat.c (_initialize_sparc_linux_nat): Likewise. * sparc64-linux-nat.c (_initialize_sparc64_linux_nat): Likewise.
2006-03-25 00:08:16 +01:00
/* We don't change the stratum; this target will sit at
process_stratum and thread_db will set at thread_stratum. This
is a little strange, since this is a multi-threaded-capable
target, but we want to be on the stack below thread_db, and we
also want to be used for single-threaded processes. */
add_target (t);
}
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
/* Register a method to call whenever a new thread is attached. */
void
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
linux_nat_set_new_thread (struct target_ops *t,
void (*new_thread) (struct lwp_info *))
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
{
/* Save the pointer. We only support a single registered instance
of the GNU/Linux native target, so we do not need to map this to
T. */
linux_nat_new_thread = new_thread;
}
[native x86 GNU/Linux] Access debug register mirror from the corresponding process. While reviewing the native AArch64 patch, I noticed a problem: On 02/06/2013 08:46 PM, Pedro Alves wrote: > >> > +static void >> > +aarch64_linux_prepare_to_resume (struct lwp_info *lwp) >> > +{ >> > + struct arch_lwp_info *info = lwp->arch_private; >> > + >> > + /* NULL means this is the main thread still going through the shell, >> > + or, no watchpoint has been set yet. In that case, there's >> > + nothing to do. */ >> > + if (info == NULL) >> > + return; >> > + >> > + if (DR_HAS_CHANGED (info->dr_changed_bp) >> > + || DR_HAS_CHANGED (info->dr_changed_wp)) >> > + { >> > + int tid = GET_LWP (lwp->ptid); >> > + struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state (); > Hmm. This is always fetching the debug_reg_state of > the current inferior, but may not be the inferior of lwp. > I see the same bug on x86. Sorry about that. I'll fix it. A natural fix would be to make xxx_get_debug_reg_state take an inferior argument, but that doesn't work because of the case where we detach breakpoints/watchpoints from the child fork, at a time there's no inferior for the child fork at all. We do a nasty hack in i386_inferior_data_get, but that relies on all callers pointing the current inferior to the correct inferior, which isn't actually being done by all callers, and I don't think we want to enforce that -- deep in the bowls of linux-nat.c, there are many cases we resume lwps behind the scenes, and it's be better to not have that code rely on global state (as it doesn't today). The fix is to decouple the watchpoints code from inferiors, making it track target processes instead. This way, we can freely keep track of the watchpoint mirrors for these processes behind the core's back. Checkpoints also play dirty tricks with swapping the process behind the inferior, so they get special treatment too in the patch (which just amounts to calling a new hook). Instead of the old hack in i386_inferior_data_get, where we returned a copy of the current inferior's debug registers mirror, as soon as we detect a fork in the target, we copy the debug register mirror from the parent to the child process. I don't have an old kernel handy to test, but I stepped through gdb doing the watchpoint removal in the fork child in the watchpoint-fork test seeing that the debug registers end up cleared in the child. I didn't find the need for linux_nat_iterate_watchpoint_lwps. If we use plain iterate_over_lwps instead, what happens is that when removing watchpoints, that iterate_over_lwps doesn't actually iterate over anything, since the fork child is not added to the lwp list until later, at detach time, in linux_child_follow_fork. And if we don't iterate over that lwp, we don't mark its debug registers as needing update. But linux_child_follow_fork takes care of doing that explicitly: child_lp = add_lwp (inferior_ptid); child_lp->stopped = 1; child_lp->last_resume_kind = resume_stop; make_cleanup (delete_lwp_cleanup, child_lp); /* CHILD_LP has new PID, therefore linux_nat_new_thread is not called for it. See i386_inferior_data_get for the Linux kernel specifics. Ensure linux_nat_prepare_to_resume will reset the hardware debug registers. It is done by the linux_nat_new_thread call, which is being skipped in add_lwp above for the first lwp of a pid. */ gdb_assert (num_lwps (GET_PID (child_lp->ptid)) == 1); if (linux_nat_new_thread != NULL) linux_nat_new_thread (child_lp); if (linux_nat_prepare_to_resume != NULL) linux_nat_prepare_to_resume (child_lp); ptrace (PTRACE_DETACH, child_pid, 0, 0); so unless I'm missing something (quite possible) it ends up all the same. But, the !detach-on-fork, and the "follow-fork child" paths should also call linux_nat_new_thread, and they don't presently. It seems to me in those cases we're not clearing debug regs correctly when that's needed. Instead of copying that bit that works around add_lwp bypassing the linux_nat_new_thread call, I thought it'd be better to add an add_initial_lwp call to be used in the case we really need to bypass linux_nat_new_thread, and make add_lwp always call linux_nat_new_thread. i386_cleanup_dregs is rewritten to forget about the current process debug mirrors, which takes cares of other i386 ports. Only a couple of extra tweaks here and there were needed, as some targets wheren't actually calling i386_cleanup_dregs. Tested on Fedora 17 x86_64 -m64/-m32. GDBserver already fetches the i386_debug_reg_state from the right process, and, it doesn't handle forks at all, so no fix is needed over there. gdb/ 2013-02-13 Pedro Alves <palves@redhat.com> * amd64-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (amd64_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (amd64_linux_new_fork): New function. (_initialize_amd64_linux_nat): Install amd64_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-linux-nat.c (update_debug_registers_callback): Update comment. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use iterate_over_lwps. (i386_linux_prepare_to_resume): Pass the lwp's pid to i386_debug_reg_state. (i386_linux_new_fork): New function. (_initialize_i386_linux_nat): Install i386_linux_new_fork as linux_nat_new_fork hook, and i386_forget_process as linux_nat_forget_process hook. * i386-nat.c (i386_init_dregs): Delete. (i386_inferior_data, struct i386_inferior_data): Delete. (struct i386_process_info): New. (i386_process_list): New global. (i386_find_process_pid, i386_add_process, i386_process_info_get): New functions. (i386_inferior_data_get): Delete. (i386_process_info_get): New function. (i386_debug_reg_state): New parameter 'pid'. Reimplement. (i386_forget_process): New function. (i386_cleanup_dregs): Rewrite. (i386_update_inferior_debug_regs, i386_insert_watchpoint) (i386_remove_watchpoint, i386_region_ok_for_watchpoint) (i386_stopped_data_address, i386_insert_hw_breakpoint) (i386_remove_hw_breakpoint): Adjust to pass the current process id to i386_debug_reg_state. (i386_use_watchpoints): Don't register inferior data. * i386-nat.h (i386_debug_reg_state): Add new 'pid' parameter, and adjust comment. (i386_forget_process): Declare. * linux-fork.c (delete_fork): Call linux_nat_forget_process. * linux-nat.c (linux_nat_new_fork, linux_nat_forget_process_hook): New static globals. (linux_child_follow_fork): Don't call linux_nat_new_thread here. (add_initial_lwp): New, factored out from ... (add_lwp): ... this. Don't check the number of lwps before calling linux_nat_new_thread. (linux_nat_iterate_watchpoint_lwps): Delete. (linux_nat_attach): Use add_initial_lwp instead of add_lwp. (linux_handle_extended_wait): Call the linux_nat_new_fork hook on forks and vforks. (linux_nat_wait_1): Use add_initial_lwp instead of add_lwp for the initial lwp. (linux_nat_kill, linux_nat_mourn_inferior): Call linux_nat_forget_process. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New functions. * linux-nat.h (linux_nat_iterate_watchpoint_lwps_ftype): Delete type. (linux_nat_iterate_watchpoint_lwps): Delete declaration. (linux_nat_new_fork_ftype, linux_nat_forget_process_ftype): New types. (linux_nat_set_new_fork, linux_nat_set_forget_process) (linux_nat_forget_process): New declarations. * amd64fbsd-nat.c (super_mourn_inferior): New global. (amd64fbsd_mourn_inferior): New function. (_initialize_amd64fbsd_nat): Override to_mourn_inferior. * windows-nat.c (windows_detach): Call i386_cleanup_dregs.
2013-02-13 15:59:49 +01:00
/* See declaration in linux-nat.h. */
void
linux_nat_set_new_fork (struct target_ops *t,
linux_nat_new_fork_ftype *new_fork)
{
/* Save the pointer. */
linux_nat_new_fork = new_fork;
}
/* See declaration in linux-nat.h. */
void
linux_nat_set_forget_process (struct target_ops *t,
linux_nat_forget_process_ftype *fn)
{
/* Save the pointer. */
linux_nat_forget_process_hook = fn;
}
/* See declaration in linux-nat.h. */
void
linux_nat_forget_process (pid_t pid)
{
if (linux_nat_forget_process_hook != NULL)
linux_nat_forget_process_hook (pid);
}
/* Register a method that converts a siginfo object between the layout
that ptrace returns, and the layout in the architecture of the
inferior. */
void
linux_nat_set_siginfo_fixup (struct target_ops *t,
int (*siginfo_fixup) (siginfo_t *,
gdb_byte *,
int))
{
/* Save the pointer. */
linux_nat_siginfo_fixup = siginfo_fixup;
}
gdb/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * linux-nat.c (linux_nat_new_thread): Change parameter to an lwp pointer. (linux_nat_prepare_to_resume): New global. (lwp_free): New. (purge_lwp_list): Use it. (add_lwp): Call linux_nat_new_thread even on the first LWP. Adjust to interface change. (delete_lwp): Call lwp_free instead of xfree. (detach_callback, linux_nat_detach, resume_lwp, linux_nat_resume) (linux_handle_syscall_trap, linux_handle_extended_wait) (linux_nat_filter_event, resume_stopped_resumed_lwps): Call linux_nat_prepare_to_resume before resuming. (linux_stop_lwp): New. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * linux-nat.h (struct arch_lwp_info): Forward declare. (struct lwp_info) <arch_private>: New field. (linux_stop_lwp): Declare. (linux_nat_set_new_thread): Adjust. (linux_nat_set_prepare_to_resume): New. * i386-nat.c (DR_NADDR, DR_STATUS, DR_CONTROL) (struct i386_debug_reg_state): Move to i386-nat.h. (dr_mirror): Comment. (i386_debug_reg_state): New. (i386_update_inferior_debug_regs): Simplify. (i386_stopped_data_address): Use the debug register state from the inferior, not from the local cache. * i386-nat.h (struct i386_dr_low_type): Delete reset_addr and unset_status fields. New get_addr and get_control fields. (DR_FIRSTADDR, DR_LASTADDR, DR_CONTROL): Moved from i386-nat.c. (DR_NADDR, DR_STATUS): New. (struct i386_debug_reg_state): Moved from i386-nat.c. * amd64-linux-nat.c (struct arch_lwp_info): New. (amd64_linux_dr): Delete global. (amd64_linux_dr_get_addr): New. (amd64_linux_dr_get_control): New. (amd64_linux_dr_unset_status): Delete. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_dr_reset_addr): Delete. (update_debug_registers_callback): New. (amd64_linux_dr_set_control): Reimplement. (amd64_linux_dr_set_addr): Reimplement. (amd64_linux_prepare_to_resume): New. (amd64_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_amd64_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install amd64_linux_dr_get_control as i386_dr_low.get_control. Install amd64_linux_dr_get_addr as i386_dr_low.get_addr. Install amd64_linux_prepare_to_resume. * i386-linux-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (struct arch_lwp_info): New. (i386_linux_dr): Delete global. (i386_linux_dr_set_control): Reimplement. (i386_linux_dr_get_addr): New. (i386_linux_dr_set_addr): Reimplement. (i386_linux_dr_get_control): New. (update_debug_registers_callback): New. (i386_linux_dr_unset_status): Delete. (i386_linux_dr_set_addr): Reimplement. (i386_linux_prepare_to_resume): New. (i386_linux_new_thread): Change parameter to an lwp pointer. Reimplement. (_initialize_i386_linux_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386_linux_dr_get_control as i386_dr_low.get_control. Install i386_linux_dr_get_addr as i386_dr_low.get_addr. Install i386_linux_prepare_to_resume. * arm-linux-nat.c (arm_linux_new_thread): Change parameter to an lwp pointer. Adjust. * ia64-linux-nat.c (ia64_linux_new_thread): Likewise. * mips-linux-nat.c (mips_linux_new_thread): Likewise. * ppc-linux-nat.c (ppc_linux_new_thread): Likewise. * s390-nat.c (s390_fix_watch_points): Likewise. * i386-darwin-nat.c (DR_FIRSTADDR, DR_LASTADDR, DR_STATUS) (DR_CONTROL): Delete. (i386_darwin_dr_reset_addr): Delete. (i386_darwin_dr_get_addr): New. (i386_darwin_dr_get_control): New. * go32-nat.c (go32_get_dr7, go32_get_dr): New. (init_go32_ops): No longer install i386_dr_low.reset_addr. Install go32_get_dr7 as i386_dr_low.get_control. Install go32_get_dr as i386_dr_low.get_addr. * i386bsd-nat.c (i386bsd_dr_get): New. (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_status): Use i386bsd_dr_get. (i386bsd_dr_get_control): New. * i386bsd-nat.h (i386bsd_dr_reset_addr): Delete. (i386bsd_dr_get_addr): New. (i386bsd_dr_get_control): New. * i386fbsd-nat.c (_initialize_i386fbsd_nat): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install i386bsd_dr_get_control as i386_dr_low.get_control. Install i386bsd_dr_get_addr as i386_dr_low.get_addr. * windows-nat.c (init_windows_ops): No longer install i386_dr_low.reset_addr and i386_dr_low.unset_status. Install cygwin_get_dr7 as i386_dr_low.get_control. Install cygwin_get_dr as i386_dr_low.get_addr. (cygwin_get_dr): New. (cygwin_get_dr7): New. gdb/testsuite/ 2011-12-14 Pedro Alves <pedro@codesourcery.com> PR threads/10729 * gdb.mi/watch-nonstop.c: New file. * gdb.mi/mi-watch-nonstop.exp: New file.
2011-12-14 18:20:32 +01:00
/* Register a method to call prior to resuming a thread. */
void
linux_nat_set_prepare_to_resume (struct target_ops *t,
void (*prepare_to_resume) (struct lwp_info *))
{
/* Save the pointer. */
linux_nat_prepare_to_resume = prepare_to_resume;
}
/* See linux-nat.h. */
int
linux_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo)
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
{
int pid;
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_lwp (ptid);
if (pid == 0)
* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * aix-thread.c (BUILD_THREAD, BUILD_LWP): Remove. Replace BUILD_THREAD with ptid_build. Replace BUILD_LWP with ptid_build. Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * alphabsd-nat.c: Replace PIDGET with ptid_get_pid. * amd64-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * amd64bsd-nat.c: Replace PIDGET with ptid_get_pid. * arm-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. Replace GET_LWP with ptid_get_lwp. * armnbsd-nat.c: Replace PIDGET with ptid_get_pid. * auxv.c: Likewise. * breakpoint.c: Likewise. * common/ptid.c (ptid_is_pid): Condense check for null_ptid and minus_one_ptid. (ptid_lwp_p): New function. (ptid_tid_p): New function. * common/ptid.h: Update comments for accessors. (ptid_lwp_p): New prototype. (ptid_tid_p): New prototype. * defs.h (PIDGET, TIDGET, MERGEPID): Do not define. * gcore.c: Replace PIDGET with ptid_get_pid. * gdbthread.h: Likewise. * gnu-nat.c: Likewise. * hppa-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * hppabsd-nat.c: Replace PIDGET with ptid_get_pid. * hppanbsd-nat.c: Likewise. * i386-linux-nat.c: Replace PIDGET with ptid_get_pid. Replace TIDGET with ptid_get_lwp. * i386bsd-nat.c: Replace PIDGET with ptid_get_pid. * ia64-linux-nat.c: Replace PIDGET with ptid_get_pid. * infcmd.c: Likewise. * inferior.h: Likewise. * inflow.c: Likewise. * infrun.c: Likewise. * linux-fork.c: Likewise. * linux-nat.c: Replace PIDGET with ptid_get_pid. Replace GET_PID with ptid_get_pid. Replace is_lwp with ptid_lwp_p. Replace GET_LWP with ptid_get_lwp. Replace BUILD_LWP with ptid_build.
2013-09-30 13:50:12 +02:00
pid = ptid_get_pid (ptid);
errno = 0;
ptrace (PTRACE_GETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, siginfo);
if (errno != 0)
{
memset (siginfo, 0, sizeof (*siginfo));
return 0;
}
return 1;
* linux-nat.c (linux_nat_new_thread): New variable. (linux_child_follow_fork): Set inferior_ptid to include LWP ID. Use linux_nat_switch_fork. (lwp_list): Make public. (add_lwp): Call linux_nat_new_thread. (lin_lwp_attach_lwp, linux_nat_attach): Call add_lwp after stopping the new thread. (resume_callback): Clear lp->siginfo. Remove unused variable. (linux_nat_resume): Assert that the LWP list is already initialized. Clear lp->siginfo. (save_siginfo): New. (stop_wait_callback, linux_nat_wait): Call it. (linux_nat_set_new_thread, linux_nat_get_siginfo): New. * linux-nat.h (struct lwp_info): Add siginfo. (lwp_list, linux_nat_set_new_thread, linux_nat_get_siginfo): Declare. (ALL_LWPS): Define. * amd64-linux-nat.c (amd64_linux_dr): New. (amd64_linux_dr_get): Take a PTID argument. Correct typo. (amd64_linux_dr_set): Take a PTID argument. (amd64_linux_dr_set_control, amd64_linux_dr_set_addr): Use ALL_LWPS. (amd64_linux_dr_reset_addr): Use amd64_linux_dr_set_addr. (amd64_linux_dr_get_status): Pass inferior_ptid to amd64_linux_dr_get. (amd64_linux_new_thread): New. (_initialize_amd64_linux_nat): Call linux_nat_set_new_thread. * i386-linux-nat.c (i386_linux_dr): New. (i386_linux_dr_get, i386_linux_dr_set): Take a PTID argument. (i386_linux_dr_set_control, i386_linux_dr_set_addr): Use ALL_LWPS. (i386_linux_dr_reset_addr): Use i386_linux_dr_set_addr. (i386_linux_dr_get_status): Pass inferior_ptid to i386_linux_dr_get. (i386_linux_new_thread): New. (i386_linux_resume): Remove unnecessary PID check. (_initialize_i386_linux_nat): Call linux_nat_set_new_thread. * ia64-linux-nat.c (enable_watchpoints_in_psr): Take PTID argument. (fetch_debug_register, fetch_debug_register_pair): Delete. (debug_registers): New. (ia64_linux_insert_watchpoint, ia64_linux_remove_watchpoint): Use ALL_LWPS and debug_registers. (ia64_linux_new_thread): New. (ia64_linux_stopped_data_address): Use linux_nat_get_siginfo. (_initialize_ia64_linux_nat): Call linux_nat_set_new_thread. * ppc-linux-nat.c (last_stopped_data_address): Delete. (saved_dabr_value): New. (ppc_linux_insert_watchpoint, ppc_linux_remove_watchpoint): Use ALL_LWPS. (ppc_linux_new_thread): New. (ppc_linux_stopped_data_address): Use linux_nat_get_siginfo. (ppc_linux_stopped_by_watchpoint): Call ppc_linux_stopped_data_address. (_initialize_ppc_linux_nat): Call linux_nat_set_new_thread. * s390-nat.c (s390_stopped_by_watchpoint): Clear the watchpoint status after reading it. (s390_fix_watch_points): Take a PTID argument. (s390_insert_watchpoint, s390_remove_watchpoint): Use ALL_LWPS. (_initialize_s390_nat): Call linux_nat_set_new_thread.
2007-10-01 02:22:50 +02:00
}
/* See nat/linux-nat.h. */
ptid_t
current_lwp_ptid (void)
{
gdb_assert (ptid_lwp_p (inferior_ptid));
return inferior_ptid;
}
2008-02-21 Pedro Alves <pedro@codesorcery.com> Silence a few -Wmissing-prototypes warnings. PR build/9877: * amd64-nat.c: Include "amd64-nat.h". * fork-child.c (_initialize_fork_child): Ditto. * gcore.c (_initialize_gcore): Ditto. * inf-ptrace.c: Include "inf-ptrace.h". (inf_ptrace_store_registers): Make it static. * linux-nat.c (linux_nat_terminal_ours): Make it static. (_initialize_linux_nat): Declare before definition. * linux-tdep.c: Include "linux-tdep.h". * linux-thread-db.c (_initialize_thread_db): Declare before definition. * proc-service.c (_initialize_proc_service): Ditto. * remote.c (remote_send_printf): Make it static. * solib.c: Include "solib.h". * symfile-mem.c (_initialize_symfile_mem): Declare before definition. * ada-lang.c (ada_la_decode, ada_match_name) (ada_suppress_symbol_printing, ada_is_array_type) (ada_value_ptr_subscript, ada_array_length) (ada_to_static_fixed_value): Make them static. (_initialize_ada_language): Declare before definition. * ada-tasks.c (ada_get_task_number, ada_get_environment_task) (ada_task_list_changed, ada_new_objfile_observer): Make them static. (_initialize_tasks): Declare before definition. * addrmap.c (_initialize_addrmap): Declare before definition. * auxv.c (default_auxv_parse): Make it static. * bfd-target.c (target_bfd_xfer_partial, target_bfd_xclose): Make them static. * breakpoint.c (remove_sal): Add line break. (expand_line_sal_maybe): Make it static. * cp-name-parser.y: Include "cp-support.h". * cp-valprint.c (cp_find_class_member): Make it static. * eval.c (value_f90_subarray): Ditto. * exceptions.c (print_any_exception): Ditto. * findcmd.c (_initialize_mem_search): Declare before definition. * frame.c (frame_observer_target_changed): Make it static. * gnu-v3-abi.c (gnuv3_find_method_in): Make it static. * inf-child.c: Include "inf-child.h". * inferior.h (valid_inferior_id): Rename to ... (valid_gdb_inferior_id): ... this. * infrun.c (infrun_thread_stop_requested, siginfo_make_value): Make them static. * jv-lang.c (java_language_arch_info): Make it static. * m2-typeprint.c (m2_get_discrete_bounds): Ditto. * osdata.c (info_osdata_command): Make it static. * regcache.c (regcache_observer_target_changed): Make it static. * reverse.c (_initialize_reverse): Declare before definition. * stabsread.c (cleanup_undefined_types_noname) (cleanup_undefined_types_1): Make them static. * symfile.c (place_section): Make it static. * symtab.c (find_pc_sect_psymtab_closer): Make it static. * target-descriptions.c (_initialize_target_descriptions): Declare before definition. * target.c (default_get_ada_task_ptid, find_default_can_async_p) (find_default_is_async_p, find_default_supports_non_stop): Make them static. (target_supports_non_stop): Add prototype. (dummy_pid_to_str): Make it static. * utils.c (_initialize_utils): Declare before definition. * ada-exp.y (_initialize_ada_exp): Declare before definition. * solib-svr4.c (HAS_LM_DYNAMIC_FROM_LINK_MAP): Add a prototype. * target.h (struct target_ops): Add a prototype to the to_can_execute_reverse callback. * macroscope.c (_initialize_macroscope): Declare before definition. * cp-namespace.c (_initialize_cp_namespace): Declare before definition. * python/python.c (_initialize_python): Declare before definition. * tui/tui-command.c: Include "tui/tui-command.h". * tui/tui-data.c (init_content_element, init_win_info): Make them static. * tui/tui-disasm.c: Include "tui/tui-disasm.h". * tui/tui-interp.c (_initialize_tui_interp): Declare before definition. * tui/tui-layout.c: Include "tui/tui-layout.h". (_initialize_tui_layout): Declare before definition. * tui/tui-regs.c: Include "tui/tui-regs.h". (tui_display_reg_element_at_line): Make it static. (_initialize_tui_regs): Declare before definition. * tui/tui-stack.c (_initialize_tui_stack): Declare before definition. * tui/tui-win.c: Include "tui/tui-win.h". (_initialize_tui_win): Declare before definition. (tui_sigwinch_handler): Make it static. Wrap in ifdef SIGWINCH. * tui/tui-win.h (tui_sigwinch_handler): Delete declaration. (tui_get_cmd_list): Add a prototype. * tui/tui-windata.c: Include tui-windata.h. * tui/tui-wingeneral.c (box_win): Make it static. * cli/cli-logging.c (show_logging_command): Make it static. (_initialize_cli_logging): Declare before definition. * mi/mi-common.c (_initialize_gdb_mi_common): Declare before definition.
2009-02-21 17:14:50 +01:00
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_linux_nat;
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
void
_initialize_linux_nat (void)
{
gdb/ * dwarf2loc.c (entry_values_debug): Add 'unsigned'. (_initialize_dwarf2loc): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * dwarf2loc.h: Update the declaration of 'entry_values_debug'. * dwarf2read.c (dwarf2_die_debug): Add 'unsigned'. (_initialize_dwarf2_read): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * darwin-nat.c (dwarwin_debug_flag): Add 'unsigned'. (_initialize_darwin_inferior): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.c (frame_debug): Add 'unsigned'. (_intialize_frame): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.h: Update the declaration of 'frame_debug'. * gdbtypes.c (overload_debug): Add 'unsigned'. (_initialize_gdbtypes): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * inferior.h: Update declaration of 'debug_infrun'. * infrun.c (debug_infrun): Add 'unsigned'. (_initialize_infrun): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * jit.c (jit_debug): Add 'unsigned'. (_initialize_jit): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-nat.c (debug_linux_nat): Add 'unsigned'. (_initialize_linux_nat): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-thread-db.c (libthread_db_debug): Add 'unsigned'. (_initialize_thread_db): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * machoread.c (mach_o_debug_level): Add 'unsigned'. (_initialize_machoread): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * mi/mi-cmd-var.c: Update the declaration of 'varobjdebug'. * microblaze-tdep.c (microblaze_debug_flag): Add 'unsigned'. (_initialize_microblaze_tdep): Call add_setshow_zuinteger_cmd intead of add_setshow_zinteger_cmd. * mips-tdep.c (mips_debug): Add 'unsigned'. (_initialize_mips_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * monitor.c (monitor_debug): Add 'unsigned'. (_initialize_remote_monitors): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * observer.c (observer_debug): Add 'unsigned'. (_initialize_observer): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * parse.c (expressiondebug): Add 'unsigned'. (_initialize_parse): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.c (record_debug): Add 'unsigned'. (_initialize_record): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.h: Update the declaration of 'record_debug'. * stap-probe.c (stap_expression_debug): Add 'unsigned'. (_initialize_stap_probe): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * serial.c (global_serial_debug_p): Add 'unsigned'. (_initialize_serial): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-dsbt.c (solib_dsbt_debug): Add 'unsigned'. (_initialize_dsbt_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-frv.c (solib_frv_debug): Add 'unsigned'. (_initialize_frv_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * target.c (targetdebug): Add 'unsigned'. (initialize_targets): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * valops.c (overload_debug): Add 'unsigned'. * varobj.c (varobjdebug): Add 'unsigned'. (_initialize_varobj): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * xtensa-tdep.c (xtensa_debug_level): Add 'unsigned'. (_initialize_xtensa_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * arch-utils.h: Remove the declaration of 'gdbarch_debug'. * gdbarch.sh (gdbarch_debug): Add 'unsigned'. (extern void _initialize_gdbarch): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * gdbarch.c, gdbarch.h: Re-generated.
2012-08-02 11:36:40 +02:00
add_setshow_zuinteger_cmd ("lin-lwp", class_maintenance,
&debug_linux_nat, _("\
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
Set debugging of GNU/Linux lwp module."), _("\
Show debugging of GNU/Linux lwp module."), _("\
Enables printf debugging output."),
gdb/ * dwarf2loc.c (entry_values_debug): Add 'unsigned'. (_initialize_dwarf2loc): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * dwarf2loc.h: Update the declaration of 'entry_values_debug'. * dwarf2read.c (dwarf2_die_debug): Add 'unsigned'. (_initialize_dwarf2_read): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * darwin-nat.c (dwarwin_debug_flag): Add 'unsigned'. (_initialize_darwin_inferior): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.c (frame_debug): Add 'unsigned'. (_intialize_frame): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * frame.h: Update the declaration of 'frame_debug'. * gdbtypes.c (overload_debug): Add 'unsigned'. (_initialize_gdbtypes): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * inferior.h: Update declaration of 'debug_infrun'. * infrun.c (debug_infrun): Add 'unsigned'. (_initialize_infrun): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * jit.c (jit_debug): Add 'unsigned'. (_initialize_jit): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-nat.c (debug_linux_nat): Add 'unsigned'. (_initialize_linux_nat): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * linux-thread-db.c (libthread_db_debug): Add 'unsigned'. (_initialize_thread_db): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * machoread.c (mach_o_debug_level): Add 'unsigned'. (_initialize_machoread): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * mi/mi-cmd-var.c: Update the declaration of 'varobjdebug'. * microblaze-tdep.c (microblaze_debug_flag): Add 'unsigned'. (_initialize_microblaze_tdep): Call add_setshow_zuinteger_cmd intead of add_setshow_zinteger_cmd. * mips-tdep.c (mips_debug): Add 'unsigned'. (_initialize_mips_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * monitor.c (monitor_debug): Add 'unsigned'. (_initialize_remote_monitors): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * observer.c (observer_debug): Add 'unsigned'. (_initialize_observer): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * parse.c (expressiondebug): Add 'unsigned'. (_initialize_parse): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.c (record_debug): Add 'unsigned'. (_initialize_record): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * record.h: Update the declaration of 'record_debug'. * stap-probe.c (stap_expression_debug): Add 'unsigned'. (_initialize_stap_probe): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * serial.c (global_serial_debug_p): Add 'unsigned'. (_initialize_serial): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-dsbt.c (solib_dsbt_debug): Add 'unsigned'. (_initialize_dsbt_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * solib-frv.c (solib_frv_debug): Add 'unsigned'. (_initialize_frv_solib): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * target.c (targetdebug): Add 'unsigned'. (initialize_targets): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * valops.c (overload_debug): Add 'unsigned'. * varobj.c (varobjdebug): Add 'unsigned'. (_initialize_varobj): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * xtensa-tdep.c (xtensa_debug_level): Add 'unsigned'. (_initialize_xtensa_tdep): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * arch-utils.h: Remove the declaration of 'gdbarch_debug'. * gdbarch.sh (gdbarch_debug): Add 'unsigned'. (extern void _initialize_gdbarch): Call add_setshow_zuinteger_cmd instead of add_setshow_zinteger_cmd. * gdbarch.c, gdbarch.h: Re-generated.
2012-08-02 11:36:40 +02:00
NULL,
show_debug_linux_nat,
&setdebuglist, &showdebuglist);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
add_setshow_boolean_cmd ("linux-namespaces", class_maintenance,
&debug_linux_namespaces, _("\
Set debugging of GNU/Linux namespaces module."), _("\
Show debugging of GNU/Linux namespaces module."), _("\
Enables printf debugging output."),
NULL,
NULL,
&setdebuglist, &showdebuglist);
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* Save this mask as the default. */
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
sigprocmask (SIG_SETMASK, NULL, &normal_mask);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
/* Install a SIGCHLD handler. */
sigchld_action.sa_handler = sigchld_handler;
sigemptyset (&sigchld_action.sa_mask);
sigchld_action.sa_flags = SA_RESTART;
gdb/ * target.h (struct target_ops): Delete to_async_mask_value and add to_async_mask. (target_is_async_p, target_async): Formatting. (target_async_mask_value): Delete. (target_async_mask): Delete function declaration, and add new target macro with the same name. * target.c (update_current_target): Replace to_async_mask_value by to_async_mask. Default to_async_mask to return_one. (target_async_mask): Delete. (find_default_can_async_p, find_default_is_async_p): New. (init_dummy_target): register find_default_can_async_p and find_default_is_async_p on the dummy target. * linux-nat.c: Include inf-loop.h, event-loop.h and event-top.h. (debug_linux_nat_async): New global. (show_debug_linux_nat_async): New function. (linux_nat_async_enabled, linux_nat_async_mask_value) (linux_nat_event_pipe, linux_nat_num_queued_events) (linux_nat_async_events_enabled): New globals. (struct waitpid_result): New struct. (waitpid_queue): New global. (queued_waitpid, push_waitpid, drain_queued_events): New. (my_waitpid): Call queued_waitpid. (linux_child_follow_fork): Disable async events during the call. (blocked_mask): Delete. (sync_sigchld_action, async_sigchld_action): New globals. (lin_lwp_attach_lwp): In sync mode, don't reblock SIGCHLD. In async mode, block events during the call. (linux_nat_create_inferior): New. (linux_nat_attach): In sync mode, restore the mask states. In async mode, wake the event loop immediatelly. (detach_callback): Drain all queued events of the lwp we're detaching from. (linux_nat_detach): Block async mode, and drain events of the main process. (linux_nat_resume): If in async mode, mask async events during the call. If short circuiting, force event loop to wake up. If resuming, set target_executing, and register target events in the event loop. (pipe_to_local_event_queue, local_event_queue_to_pipe): New. (linux_nat_wait): In async mode, block events during the call. Only enable/disable passing SIGINT to the inferior in sync mode. Get events from local waitpid queue. If no interesting events was found, return to events loop. Reregister target events in the event loop on exit. In sync mode, no need to reblock SIGCHLD. (linux_nat_kill): Disable events on entry. (linux_nat_mourn_inferior): In sync mode, don't restore the masks here. Detach async mode from the event loop if there are no more forks available, otherwise leave it on. (sigchld_handler): Assure this is called only in sync mode. (linux_async_permitted, linux_async_permitted_1): New globals. (set_maintenance_linux_async_permitted) (show_maintenance_linux_async_permitted): New functions. (linux_nat_is_async_p, linux_nat_can_async_p) (linux_nat_async_mask): New. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push): New. (get_pending_events, async_sigchld_handler): New. (linux_nat_async_events): New. (async_terminal_is_ours): New global. (linux_nat_terminal_inferior, linux_nat_terminal_ours): New. (async_client_callback, async_client_context): New. (linux_nat_async_file_handler, linux_nat_async) (linux_nat_disable_async, linux_nat_enable_async): New. (linux_nat_add_target): Register linux_nat_create_inferior, linux_nat_can_async_p, linux_nat_is_async_p, linux_nat_async, linux_nat_async_mask, linux_nat_terminal_inferior and linux_nat_terminal_ours. (_initialize_linux_nat): Remove local action variable, and update code that used it to use sync_sigchld_action. Add new "lin-lwp-async" debug set/show command. Put the "lin-lwp" debug set/show command in the maintenance class. Add new "linux-async" maintenance set/show command. Block SIGCHLD by default. Setup async_sichld_action, and sync_sigchld_action. Install the default async mode. (lin_thread_get_thread_signals): Use a local sigset_t for blocking the cancel signals. * linux-thread-db.c (re_check_for_thread_db): New. (clear_lwpid_callback): Handle TARGET_WAITKIND_IGNORE. (thread_db_can_async_p, thread_db_is_async_p, thread_db_async) (thread_db_async_mask): New. (init_thread_db_ops): Register thread_db_can_async_p, thread_db_is_async_p, thread_db_async and thread_db_async_mask. * remote.c (remote_async_mask_value): New. (remote_return_zero): New. (init_remote_ops): Register remote_return_zero as callbacks of to_can_async_p and to_is_async_p. (remote_can_async_p, remote_is_async_p, remote_async): Update to use remote_async_mask_value. (remote_async_mask): New. (init_remote_async_ops): Remove to_async_mask_value setting and register remote_async_mask as to_async_mask callback in remote_async_ops. * Makefile.in (linux-nat.o): Update. gdb/doc/ * gdb.texinfo (Debugging Output): Document "set/show debug lin-lwp-async". (Maintenance Commands): Document "maint set/show linux-async".
2008-03-21 18:09:35 +01:00
/* Make it the default. */
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
sigaction (SIGCHLD, &sigchld_action, NULL);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
/* Make sure we don't block SIGCHLD during a sigsuspend. */
sigprocmask (SIG_SETMASK, NULL, &suspend_mask);
sigdelset (&suspend_mask, SIGCHLD);
* linux-nat.c (enum sigchld_state): Delete. (linux_nat_async_events_state): Delete. (struct waitpid_result): Delete. (waitpid_queue): Delete. (queued_waitpid_1): Delete. (async_file_flush): New. (queued_waitpid, push_waitpid): Delete. (async_file_mark): New. (drain_queued_events): Delete. (my_waitpid): Remove locally queued events handling. (linux_test_for_tracefork): Upjust. (linux_child_follow_fork): Ditto. (sync_sigchld_action): Delete. (blocked_mask): Reinstate. (async_sigchld_action): Rename to... (sigchld_action): ... this. (block_child_signals): New. (restore_child_signals_mask): New. (lin_lwp_attach_lwp): Adjust. (linux_nat_create_inferior): Ditto. (linux_nat_attach): Also use lp->status in async mode. (get_pending_status): Don't use queued_waitpid. (linux_nat_detach): Don't drain locally queued events. (linux_nat_resume): Allow pending wait statuses stored lp->status in async mode. If returning early due to a pending event, re-register the event source. (stop_wait_callback): Allow pending wait statuses stored lp->status in async mode. (pipe_to_local_event_queue, local_event_queue_to_pipe): Delete. (linux_nat_wait): Rename to ... (linux_nat_wait_1): ... this. Allow pending wait statuses stored lp->status in async mode. Always add WNOHANG to the waitpid options in async mode. (linux_nat_wait): New. (kill_callback): Don't drain locally queued events. (sigchld_handler): Rewrite. (linux_nat_is_async_p, linux_nat_can_async_p): Fix comments to refer to "set target-async". (linux_nat_async_mask): If in non-stop, and re-enabling async mode, re-register the target event source in the event loop. (linux_nat_event_pipe_pop, linux_nat_event_pipe_push) (get_pending_events, async_sigchld_handler) (linux_nat_async_events): Delete. (handle_target_event): New. (linux_nat_async_file_handler): Delete. (linux_async_pipe): New. (linux_nat_async): Only re-register in the event loop if not registered yet. Always notify the event-loop once if enabling the event source. (linux_nat_stop_lwp): Rewrite to handle pending events stored in lp->status, not in the locally queued event list. (linux_nat_stop): Don't mask out async event handling. (linux_nat_setup_async): Delete. (_initialize_linux_nat): Adjust. (lin_thread_get_thread_signals): blocked_mask is global again. Adjust.
2009-05-11 14:08:03 +02:00
sigemptyset (&blocked_mask);
[Linux] Optimize PID -> struct lwp_info lookup Hacking the gdb.threads/attach-many-short-lived-threads.exp test to spawn thousands of threads instead of dozens, and running gdb under perf, I saw that GDB was spending most of the time in find_lwp_pid: - captured_main - 93.61% catch_command_errors - 87.41% attach_command - 87.40% linux_nat_attach - 87.40% linux_proc_attach_tgid_threads - 82.38% attach_proc_task_lwp_callback - 81.01% find_lwp_pid 5.30% ptid_get_lwp + 0.10% ptid_lwp_p + 0.64% add_thread + 0.26% set_running + 0.24% set_executing 0.12% ptid_get_lwp + 0.01% ptrace + 0.01% add_lwp attach_proc_task_lwp_callback is called once for each LWP that we attach to, found by listing the /proc/PID/task/ directory. In turn, attach_proc_task_lwp_callback calls find_lwp_pid to check whether the LWP we're about to try to attach to is already known. Since find_lwp_pid does a linear walk over the whole LWP list, this becomes quadratic. We do the /proc/PID/task/ listing until we get two iterations in a row where we found no new threads. So the second and following times we walk the /proc/PID/task/ dir, we're going to take an even worse find_lwp_pid hit. Fix this by adding a hash table keyed by LWP PID, for fast lookup. The linked list embedded in the LWP structure itself is kept, and made a double-linked list, so that removals from that list are O(1). An earlier version of this patch got rid of this list altogether, but that revealed hidden dependencies / assumptions on how the list is sorted. For example, killing a process and then waiting for all the LWPs status using iterate_over_lwps only works as is because the leader LWP is always last in the list. So I thought it better to take an incremental approach and make this patch concern itself _only_ with the PID lookup optimization. gdb/ChangeLog: 2016-05-24 Pedro Alves <palves@redhat.com> PR gdb/19828 * linux-nat.c (lwp_lwpid_htab): New htab. (lwp_info_hash, lwp_lwpid_htab_eq, lwp_lwpid_htab_create) (lwp_lwpid_htab_add_lwp): New functions. (lwp_list): Tweak comment. (lwp_list_add, lwp_list_remove, lwp_lwpid_htab_remove_pid): New functions. (purge_lwp_list): Rewrite, using htab_traverse_noresize. (add_initial_lwp): Add lwp to htab too. Use lwp_list_add. (delete_lwp): Use lwp_list_remove. Remove htab too. (find_lwp_pid): Search in htab. (_initialize_linux_nat): Call lwp_lwpid_htab_create. * linux-nat.h (struct lwp_info) <prev>: New field.
2016-05-24 15:47:57 +02:00
lwp_lwpid_htab_create ();
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}
/* FIXME: kettenis/2000-08-26: The stuff on this page is specific to
the GNU/Linux Threads library and therefore doesn't really belong
here. */
/* Return the set of signals used by the threads library in *SET. */
void
lin_thread_get_thread_signals (sigset_t *set)
{
sigemptyset (set);
Remove support for LinuxThreads and vendor 2.4 kernels w/ backported NPTL Since we now rely on PTRACE_EVENT_CLONE being available (added in Linux 2.5.46), we're relying on NPTL. This commit removes the support for older LinuxThreads, as well as the workarounds for vendor 2.4 kernels with NPTL backported. - Rely on tkill being available. - Assume gdb doesn't get cancel signals. - Remove code that checks the LinuxThreads restart and cancel signals in the inferior. - Assume that __WALL is available. - Assume that non-leader threads report WIFEXITED. - Thus, no longer need to send signal 0 to check whether threads are still alive. - Update comments throughout. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ChangeLog: * configure.ac: Remove tkill checks. * configure, config.in: Regenerate. * linux-nat.c: Remove HAVE_TKILL_SYSCALL check. Update top level comments. (linux_nat_post_attach_wait): Remove 'cloned' parameter. Use __WALL. (attach_proc_task_lwp_callback): Don't set the cloned flag. (linux_nat_attach): Adjust. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_handle_extended_wait): Use __WALL. Don't set the cloned flag. (wait_lwp): Use __WALL. Update comments. (running_callback, stop_and_resume_callback): Delete. (linux_nat_filter_event): Don't stop and resume all lwps. Don't check if the event LWP has previously exited. (check_zombie_leaders): Update comments. (linux_nat_wait_1): Use __WALL. (kill_wait_callback): Don't handle clone processes separately. Use __WALL instead. (linux_thread_alive): Delete. (linux_nat_thread_alive): Return true as long as the LWP is in the LWP list. (linux_nat_update_thread_list): Assume the kernel supports PTRACE_EVENT_CLONE. (get_signo): Delete. (lin_thread_get_thread_signals): Remove LinuxThreads references. No longer check __pthread_sig_restart / __pthread_sig_cancel in the inferior. * linux-nat.h (struct lwp_info) <cloned>: Delete field. * linux-thread-db.c: Update comments. (_initialize_thread_db): Remove LinuxThreads references. * nat/linux-waitpid.c (my_waitpid): No longer emulate __WALL. Pass down flags unmodified. * linux-waitpid.h (my_waitpid): Update documentation. gdb/gdbserver/ChangeLog: * linux-low.c (linux_kill_one_lwp): Remove references to LinuxThreads. (kill_lwp): Remove HAVE_TKILL_SYSCALL check. No longer fall back to 'kill'. (linux_init_signals): Delete. (initialize_low): Adjust. * thread-db.c (thread_db_init): Remove LinuxThreads reference.
2015-12-17 15:20:51 +01:00
/* NPTL reserves the first two RT signals, but does not provide any
way for the debugger to query the signal numbers - fortunately
they don't change. */
sigaddset (set, __SIGRTMIN);
sigaddset (set, __SIGRTMIN + 1);
2004-09-16 Andrew Cagney <cagney@gnu.org> * lin-lwp.c: Delete file. * linux-nat.c: Include "gdb_assert.h", "gdb_string.h", <unistd.h>, <sys/syscall.h>, "gdbthread.h", "gdbcmd.h", "regcache.h". (status_to_str, init_lwp_list, add_lwp, delete_lwp) (find_lwp_pid, iterate_over_lwps, lin_lwp_attach_lwp) (linux_nat_attach, detach_callback, linux_nat_detach) (resume_callback, resume_clear_callback, linux_nat_resume) (kill_lwp, linux_nat_handle_extended, wait_lwp, stop_callback) (stop_wait_callback, linux_nat_has_pending, flush_callback) (status_callback, running_callback, count_events_callback) (select_singlestep_lwp_callback, select_event_lwp_callback) (cancel_breakpoints_callback, select_event_lwp, resumed_callback) (child_wait, stop_and_resume_callback, linux_nat_wait) (kill_callback, kill_wait_callback, linux_nat_kill) (linux_nat_create_inferior, linux_nat_mourn_inferior) (linux_nat_xfer_memory, linux_nat_thread_alive) (linux_nat_pid_to_str, init_linux_nat_ops, sigchld_handler) (_initialize_linux_nat): New functions. * Makefile.in: Update all dependencies. * config/sparc/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/sparc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/s390/s390.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/ppc64-linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/powerpc/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/pa/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/mips/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/m68k/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/ia64/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux64.mh (NATDEPFILES): Remove lin-lwp.o. * config/i386/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/arm/linux.mh (NATDEPFILES): Remove lin-lwp.o. * config/alpha/alpha-linux.mh (NATDEPFILES): Remove lin-lwp.o.
2004-09-27 21:55:18 +02:00
}