aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
AgeCommit message (Collapse)AuthorFilesLines
2016-11-08Use ui_file_as_string in gdb/remote.cPedro Alves1-38/+16
gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * remote.c (escape_buffer): Use ui_file_as_string and return std::string. (putpkt_binary, read_frame): Adjust to use std::string.
2016-11-08'struct expression *' -> gdb::unique_xmalloc_ptr<expression>Pedro Alves1-1/+1
This patch makes parse_expression and friends return a unique_ptr instead of raw pointer [1]: typedef gdb::unique_malloc_ptr<expression> expression_up; and then adjusts the codebase throughout to stop using cleanups to manage lifetime of expression pointers. Whenever I found a structure owning an expression pointer, I made it store a unique_ptr instead of a raw pointer, which then requires using new/delete of the holding structure, instead of XNEW/xfree. [1] - I'd like to set the rule that types named with an "_up" suffix are unique_ptr typedefs. Note I used gdb::unique_xmalloc_ptr instead of gdb::unique_ptr, simply because we still use xmalloc instead of new to allocate expression objects. Once that's changed, all we need to do is change the expression_up typedef and the smart pointer will then call delete instead of xfree. gdb/ChangeLog: 2016-11-08 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_read_renaming_var_value): Use expression_up. (struct ada_catchpoint_location) <excep_cond_expr>: Now an expression_up. (ada_catchpoint_location_dtor): Reset excep_cond_expr instead of using xfree. (create_excep_cond_exprs): Use expression_up and gdb::move. (allocate_location_exception): Use new instead of XNEW. (should_stop_exception): Likewise. Adjust to use expression_up. (create_ada_exception_catchpoint): Use new instead of XNEW. * ax-gdb.c (agent_eval_command_one): Use expression_up instead of cleanups. (maint_agent_printf_command): Use expression_up. * break-catch-sig.c (create_signal_catchpoint): Use new instead of XNEW. * break-catch-syscall.c (create_syscall_event_catchpoint): Likewise. * break-catch-throw.c (handle_gnu_v3_exceptions): Use new instead of XCNEW. Use gdb::unique_ptr instead of cleanups. * breakpoint.c (set_breakpoint_condition, update_watchpoint) (parse_cmd_to_aexpr, watchpoint_check) (bpstat_check_breakpoint_conditions, watchpoint_locations_match): Adjust to use expression_up. (init_bp_location): Adjust. (free_bp_location): Use delete instead of xfree. (set_raw_breakpoint_without_location, set_raw_breakpoint) (add_solib_catchpoint, create_fork_vfork_event_catchpoint) (new_single_step_breakpoint, create_breakpoint_sal): Use new instead of XNEW. (find_condition_and_thread): Adjust to use expression_up. (create_breakpoint): Use new instead of XNEW. (dtor_watchpoint): Don't xfree expression pointers, they're unique_ptr's now. (insert_watchpoint, remove_watchpoint): Adjust. (watch_command_1): Use expression_up. Use new instead of XCNEW. (catch_exec_command_1): Use new instead of XNEW. (bp_location_dtor): Don't xfree expression pointers, they're unique_ptr's now. (base_breakpoint_allocate_location) (strace_marker_create_breakpoints_sal): Use new instead of XNEW. (delete_breakpoint): Use delete instead of xfree. * breakpoint.h (struct bp_location) <cond>: Now an unique_ptr<expression> instead of a raw pointer. (struct watchpoint) <exp, cond_exp>: Likewise. * cli/cli-script.c (execute_control_command): Use expression_up instead of cleanups. * dtrace-probe.c (dtrace_process_dof_probe): Use expression_up. * eval.c (parse_and_eval_address, parse_and_eval_long) (parse_and_eval, parse_to_comma_and_eval, parse_and_eval_type): Use expression_up instead of cleanups. * expression.h (expression_up): New typedef. (parse_expression, parse_expression_with_language, parse_exp_1): Change return type to expression_up. * mi/mi-main.c (mi_cmd_data_evaluate_expression) (print_variable_or_computed): Use expression_up. * objc-lang.c (print_object_command): Use expression_up instead of cleanups. * parse.c (parse_exp_1, parse_exp_in_context) (parse_exp_in_context_1, parse_expression) (parse_expression_with_language): Return an expression_up instead of a raw pointer. (parse_expression_for_completion): Use expression_up. * printcmd.c (struct display) <exp>: Now an expression_up instead of a raw pointer. (print_command_1, output_command_const, set_command, x_command): Use expression_up instead of cleanups. (display_command): Likewise. Use new instead of XNEW. (free_display): Use delete instead of xfree. (do_one_display): Adjust to use expression_up. * remote.c (remote_download_tracepoint): Likewise. * stack.c (return_command): Likewise. * tracepoint.c (validate_actionline, encode_actions_1): Use expression_up instead of cleanups. * typeprint.c (whatis_exp, maintenance_print_type): Likewise. * value.c (init_if_undefined_command): Likewise. * varobj.c (struct varobj_root) <exp>: Now an expression_up instead of a raw pointer. (varobj_create): Adjust. (varobj_set_value): Use an expression_up instead of cleanups. (new_root_variable): Use new instead of XNEW. (free_variable): Use delete instead of xfree. (value_of_root_1): Use std::swap.
2016-11-08Check for truncated registers in process_g_packetLionel Flandrin1-3/+17
While investigating an unrelated issue in remote.c I noticed that the bound checking for 'g' packets was bogus: The previous code would only check that the first byte of the register was within bounds before passing the buffer to regcache_raw_supply. If it turned out that the register in the 'g' packet was incomplete then regcache_raw_supply would proceed to memcpy out-of-bounds. Since the buffer is allocated with alloca it's relatively unlikely to crash (you just end up dumping gdb's stack into the cache) but it's still a bit messy. I changed this logic to check for truncated registers and raise an error if one is encountered. Hopefully it should make debugging remote stubs a bit easier. gdb/ChangeLog: 2016-11-08 Lionel Flandrin <lionel@svkt.org> * remote.c (process_g_packet): Detect truncated registers in 'g' packets and raise an error.
2016-11-03Rename placed_size to kindYao Qi1-4/+4
This patch renames placed_size to kind. gdb: 2016-11-03 Yao Qi <yao.qi@linaro.org> * breakpoint.h (struct bp_target_info) <placed_size>: Remove. <kind>: New field. Update all users.
2016-11-03New gdbarch methods breakpoint_kind_from_pc and sw_breakpoint_from_kindYao Qi1-14/+2
This patch adds two gdbarch methods breakpoint_kind_from_pc and sw_breakpoint_from_kind, and uses target_info.placed_size as "kind" of the breakpoint. This patch updates the usages of target_info.placed_size. The "kind" of a breakpoint is determined by gdbarch rather than target, so we have gdbarch method breakpoint_kind_from_pc, and we should set target_info.placed_size out of each implementation of target to_insert_breakpoint. In this way, each target doesn't have to set target_info.placed_size any more. This patch also sets target_info.placed_address before target_insert_breakpoint too, so that target to_insert_breakpoint can use it, see record_full_insert_breakpoint. Before we call target_insert_breakpoint, we set target_info.placed_address and target_info.placed_size like this, CORE_ADDR addr = bl->target_info.reqstd_address; bl->target_info.placed_size = gdbarch_breakpoint_kind_from_pc (bl->gdbarch, &addr); bl->target_info.placed_address = addr; return target_insert_breakpoint (bl->gdbarch, &bl->target_info); target_insert_breakpoint may fail, but it doesn't matter to the "kind" and "placed_address" of a breakpoint. They should be determined by gdbarch. gdb: 2016-11-03 Yao Qi <yao.qi@linaro.org> * arch-utils.h (GDBARCH_BREAKPOINT_MANIPULATION): Define breakpoint_kind_from_pc and sw_breakpoint_from_kind. (GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): Likewise. (SET_GDBARCH_BREAKPOINT_MANIPULATION): Call set_gdbarch_breakpoint_kind_from_pc and set_gdbarch_sw_breakpoint_from_kind. * arm-tdep.c: Add comments. * bfin-tdep.c: Likewise. * breakpoint.c (breakpoint_kind): New function. (insert_bp_location): Set target_info.placed_size and target_info.placed_address. (bkpt_insert_location): Likewise. * cris-tdep.c: Add comments. * gdbarch.sh (breakpoint_kind_from_pc): New. (sw_breakpoint_from_kind): New. * gdbarch.c, gdbarch.h: Regenerated. * ia64-tdep.c (ia64_memory_insert_breakpoint): Don't set bp_tgt->placed_size. (ia64_memory_remove_breakpoint): Don't assert bp_tgt->placed_size. (ia64_breakpoint_kind_from_pc): New function. (ia64_gdbarch_init): Install ia64_breakpoint_kind_from_pc. * m32r-tdep.c (m32r_memory_insert_breakpoint): Don't set bp_tgt->placed_size. * mem-break.c (default_memory_insert_breakpoint): Don't set bp_tgt->placed_size. Call gdbarch_sw_breakpoint_from_kind. (default_memory_remove_breakpoint): Call gdbarch_sw_breakpoint_from_kind. (memory_validate_breakpoint): Don't check bp_tgt->placed_size. * mips-tdep.c: Add comments. * mt-tdep.c: Likewise. * nios2-tdep.c: Likewise. * record-full.c (record_full_insert_breakpoint): Don't call gdbarch_breakpoint_from_pc. Don't set bp_tgt->placed_address and bp_tgt->placed_size. * remote.c (remote_insert_breakpoint): Don't call gdbarch_remote_breakpoint_from_pc. Use bp_tgt->placed_size. Don't set bp_tgt->placed_address and bp_tgt->placed_size. (remote_insert_hw_breakpoint): Likewise. * score-tdep.c: Likewise. * sh-tdep.c: Likewise. * tic6x-tdep.c: Likewise. * v850-tdep.c: Likewise. * xtensa-tdep.c: Likewise.
2016-10-26gdb: Coalesce/aggregate (async) vCont packets/actionsPedro Alves1-23/+429
Currently, with "maint set target-non-stop on", that is, when gdb connects with the non-stop/asynchronous variant of the remote protocol, even with "set non-stop off", GDB always sends one vCont packet per thread resumed. This patch makes GDB aggregate and coalesce vCont packets, so we send vCont packets like "vCont;s:p1.1;c" in non-stop mode too. Basically, this is done by: - Adding a new target method target_commit_resume that is called after calling target_resume one or more times. When resuming a batch of threads, we'll only call target_commit_resume once after calling target_resume for all threads. - Making the remote target defer sending the actual vCont packet to target_commit_resume. Special care must be taken to avoid sending a vCont action with a "wildcard" thread-id (all threads of process / all threads) when that would resume threads/processes that should not be resumed. See remote_commit_resume comments for details. Unlike all-stop's remote_resume implementation, this handles the case of too many actions resulting in a too-big vCont packet, by flushing the vCont packet and starting a new one. E.g., imagining that the "c" action in: vCont;s:1;c overflows the packet buffer, we split the actions like: vCont;s:1 vCont;c Tested on x86_64 Fedora 20, with and without "maint set target-non-stop on". Also tested with a hack that makes remote_commit_resume flush the vCont packet after every action appended (which caught a few bugs). gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * inferior.h (ALL_NON_EXITED_INFERIORS): New macro. * infrun.c (do_target_resume): Call target_commit_resume. (proceed): Defer target_commit_resume while looping over threads, resuming them. Call target_commit_resume at the end. * record-btrace.c (record_btrace_commit_resume): New function. (init_record_btrace_ops): Install it as to_commit_resume method. * record-full.c (record_full_commit_resume): New function. (record_full_wait_1): Call the beneath target's to_commit_resume method. (init_record_full_ops): Install record_full_commit_resume as to_commit_resume method. * remote.c (struct private_thread_info) <last_resume_step, last_resume_sig, vcont_resumed>: New fields. (remote_add_thread): Set the new thread's vcont_resumed flag. (demand_private_info): Delete. (get_private_info_thread, get_private_info_ptid): New functions. (remote_update_thread_list): Adjust. (process_initial_stop_replies): Clear the thread's vcont_resumed flag. (remote_resume): If connected in non-stop mode, record the resume request and return early. (struct private_inferior): New. (struct vcont_builder): New. (vcont_builder_restart, vcont_builder_flush) (vcont_builder_push_action): New functions. (MAX_ACTION_SIZE): New macro. (remote_commit_resume): New function. (thread_pending_fork_status, is_pending_fork_parent_thread): New functions. (check_pending_event_prevents_wildcard_vcont_callback) (check_pending_events_prevent_wildcard_vcont): New functions. (process_stop_reply): Adjust. Clear the thread's vcont_resumed flag. (init_remote_ops): Install remote_commit_resume. * target-delegates.c: Regenerate. * target.c (defer_target_commit_resume): New global. (target_commit_resume, make_cleanup_defer_target_commit_resume): New functions. * target.h (struct target_ops) <to_commit_resume>: New field. (target_resume): Update comments. (target_commit_resume): New declaration.
2016-10-26gdb: Clean up remote.c:remote_resumePedro Alves1-51/+62
Just some refactoring / TLC. Mainly split the old c/s/C/S packet handling to a separate function. gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * remote.c (remote_resume_with_hc): New function, factored out from ... (remote_resume): ... this. Always try vCont first. (remote_vcont_resume): Rename to ... (remote_resume_with_vcont): ... this. Bail out if execution direction is reverse.
2016-09-29PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regressionJan Kratochvil1-1/+1
Regression: gdb --pid $(pidof qemu-system-x86_64) stopped working with gdb 7.11.1 https://sourceware.org/bugzilla/show_bug.cgi?id=20609 It was reported for qemu-system-x86_64 but it happens for any multithreaded inferior with a JIT debugging hook. 136613ef0c6850427317e57be1b644080ff6decb is the first bad commit Author: Pedro Alves <palves@redhat.com> Fix PR gdb/19828: gdb -p <process from a container>: internal error Message-ID: <cbdf2e04-4fa8-872a-2a23-08c9c1b26e00@redhat.com> https://sourceware.org/ml/gdb-patches/2016-05/msg00450.html jit_breakpoint_re_set() is specific by trying to insert a breakpoint into the main executable, not into a shared library. During attachment GDB thinks it needs to use 'breakpoint always-inserted' from breakpoints_should_be_inserted_now() as a newly attached thread is 'thread_info->executing' due to 'lwp_info->must_set_ptrace_flags' enabled and the task not yet stopped. This did not happen before the 'bad commit' above which adds tracking of such thread. GDB then fails to insert the breakpoints to invalid address as PIE executable gets properly relocated during later phase of attachment. One can see in the backtraces below: -> jit_breakpoint_re_set_internal() later: -> svr4_exec_displacement() One can suppress the initial breakpoint_re_set() call as there will be another breakpoint_re_set() done from the final post_create_inferior() call in setup_inferior(). BTW additionally 'threads_executing' cache bool is somehow stale (somewhere is missing update_threads_executing()). I was trying to deal with that in my first/second attempt below but in my final third attempt (attached) I have left it as it is. First attempt trying not to falsely require 'breakpoint always-inserted': https://people.redhat.com/jkratoch/rhbz1375553-fix1.patch Reduced first attempt: https://people.redhat.com/jkratoch/rhbz1375553-fix2.patch The third attempt suppresses breakpoint insertion until PIE executable gets relocated by svr4_exec_displacement(). Applied. gdb/ChangeLog 2016-09-29 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression * exec.c (exec_file_locate_attach): Add parameter defer_bp_reset. Use it. * gdbcore.h (exec_file_locate_attach): Add parameter defer_bp_reset. * infcmd.c (setup_inferior): Update caller. * remote.c (remote_add_inferior): Likewise. gdb/testsuite/ChangeLog 2016-09-29 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/20609 - attach of JIT-debug-enabled inf 7.11.1 regression * gdb.base/jit-attach-pie.c: New file. * gdb.base/jit-attach-pie.exp: New file.
2016-09-19Consolidate target_mourn_inferior between GDB and gdbserverSergio Durigan Junior1-3/+3
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-18gdb: Fix std::{min, max}-related build breakage on 32-bit hostsPedro Alves1-1/+1
Building on a 32-bit host fails currently with errors like: .../src/gdb/exec.c: In function ‘target_xfer_status section_table_read_available_memory(gdb_byte*, ULONGEST, ULONGEST, ULONGEST*)’: .../src/gdb/exec.c:801:54: error: no matching function for call to ‘min(ULONGEST, long unsigned int)’ end = std::min (offset + len, r->start + r->length); ^ In file included from /usr/include/c++/5.3.1/algorithm:61:0, from .../src/gdb/exec.c:46: /usr/include/c++/5.3.1/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&) min(const _Tp& __a, const _Tp& __b) ^ /usr/include/c++/5.3.1/bits/stl_algobase.h:195:5: note: template argument deduction/substitution failed: .../src/gdb/exec.c:801:54: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long unsigned int’ and ‘long unsigned int’) end = std::min (offset + len, r->start + r->length); ^ In file included from /usr/include/c++/5.3.1/algorithm:61:0, from .../src/gdb/exec.c:46: /usr/include/c++/5.3.1/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare) min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ The problem is that the std::min/std::max function templates use the same type for both parameters. When the argument types are different, the compiler can't automatically deduce which template specialization to pick from the arguments' types. Fix that by specifying the specialization we want explicitly. gdb/ChangeLog: 2016-09-18 Pedro Alves <palves@redhat.com> * breakpoint.c (hardware_watchpoint_inserted_in_range): Explicitly specify the std:min/std::max specialization. * exec.c (section_table_read_available_memory): Likewise. * remote.c (remote_read_qxfer): Likewise. * target.c (simple_verify_memory): Likewise.
2016-09-16gdb: Use std::min and std::max throughoutPedro Alves1-8/+14
Otherwise including <string> or some other C++ header is broken. E.g.: In file included from /opt/gcc/include/c++/7.0.0/bits/char_traits.h:39:0, from /opt/gcc/include/c++/7.0.0/string:40, from /home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:68: /opt/gcc/include/c++/7.0.0/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2 min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ /opt/gcc/include/c++/7.0.0/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2 max(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ In file included from .../src/gdb/infrun.c:21:0: To the best of my grepping abilities, I believe I adjusted all min/max calls. gdb/ChangeLog: 2016-09-16 Pedro Alves <palves@redhat.com> * defs.h (min, max): Delete. * aarch64-tdep.c: Include <algorithm> and use std::min and std::max throughout. * aarch64-tdep.c: Likewise. * alpha-tdep.c: Likewise. * amd64-tdep.c: Likewise. * amd64-windows-tdep.c: Likewise. * arm-tdep.c: Likewise. * avr-tdep.c: Likewise. * breakpoint.c: Likewise. * btrace.c: Likewise. * ctf.c: Likewise. * disasm.c: Likewise. * doublest.c: Likewise. * dwarf2loc.c: Likewise. * dwarf2read.c: Likewise. * environ.c: Likewise. * exec.c: Likewise. * f-exp.y: Likewise. * findcmd.c: Likewise. * ft32-tdep.c: Likewise. * gcore.c: Likewise. * hppa-tdep.c: Likewise. * i386-darwin-tdep.c: Likewise. * i386-tdep.c: Likewise. * linux-thread-db.c: Likewise. * lm32-tdep.c: Likewise. * m32r-tdep.c: Likewise. * m88k-tdep.c: Likewise. * memrange.c: Likewise. * minidebug.c: Likewise. * mips-tdep.c: Likewise. * moxie-tdep.c: Likewise. * nds32-tdep.c: Likewise. * nios2-tdep.c: Likewise. * nto-procfs.c: Likewise. * parse.c: Likewise. * ppc-sysv-tdep.c: Likewise. * probe.c: Likewise. * record-btrace.c: Likewise. * remote.c: Likewise. * rs6000-tdep.c: Likewise. * rx-tdep.c: Likewise. * s390-linux-nat.c: Likewise. * s390-linux-tdep.c: Likewise. * ser-tcp.c: Likewise. * sh-tdep.c: Likewise. * sh64-tdep.c: Likewise. * source.c: Likewise. * sparc-tdep.c: Likewise. * symfile.c: Likewise. * target-memory.c: Likewise. * target.c: Likewise. * tic6x-tdep.c: Likewise. * tilegx-tdep.c: Likewise. * tracefile-tfile.c: Likewise. * tracepoint.c: Likewise. * valprint.c: Likewise. * value.c: Likewise. * xtensa-tdep.c: Likewise. * cli/cli-cmds.c: Likewise. * compile/compile-object-load.c: Likewise.
2016-09-08Remove some unneeded casts from remote.cTom Tromey1-4/+4
I happened to notice a few unneeded casts in remote.c. In some cases these are no-ops, and in others these cast away const, but in a context where this is not needed. I'm checking this in under the obvious rule. Tested by rebuilding on x86-64 Fedora 24. 2016-09-08 Tom Tromey <tom@tromey.com> * remote.c (remote_notif_stop_ack, remote_wait_as) (show_remote_cmd): Remove unneeded casts.
2016-08-10Plumb enum remove_bp_reason all the way to target_remove_breakpointPedro Alves1-2/+3
So the target knows whether we're detaching breakpoints. Nothing uses the parameter in this patch yet. gdb/ChangeLog: 2016-08-10 Pedro Alves <palves@redhat.com> PR gdb/19187 * break-catch-sig.c (signal_catchpoint_remove_location): Adjust interface. * break-catch-syscall.c (remove_catch_syscall): * breakpoint.c (enum remove_bp_reason): Moved to breakpoint.h. (remove_breakpoint_1): Pass 'reason' down. (remove_catch_fork, remove_catch_vfork, remove_catch_solib) (remove_catch_exec, remove_watchpoint, remove_masked_watchpoint) (base_breakpoint_remove_location, bkpt_remove_location) (bkpt_probe_remove_location, bkpt_probe_remove_location): Adjust interface. * breakpoint.h (enum remove_bp_reason): Moved here from breakpoint.c. (struct breakpoint_ops) <remove_location>: Add 'reason' parameter. * corelow.c (core_remove_breakpoint): New function. (init_core_ops): Install it as to_remove_breakpoint method. * exec.c (exec_remove_breakpoint): New function. (init_exec_ops): Install it as to_remove_breakpoint method. * mem-break.c (memory_remove_breakpoint): Adjust interface. * record-btrace.c (record_btrace_remove_breakpoint): Adjust interface. * record-full.c (record_full_remove_breakpoint) (record_full_core_remove_breakpoint): Adjust interface. * remote.c (remote_remove_breakpoint): Adjust interface. * target-debug.h (target_debug_print_enum_remove_bp_reason): New macro. * target-delegates.c: Regenerate. * target.c (target_remove_breakpoint): Add 'reason' parameter. * target.h (struct target_ops) <to_remove_breakpoint>: Add 'reason' parameter. (target_remove_breakpoint, memory_remove_breakpoint): Add 'reason' parameter.
2016-07-25btrace: Resume recording after disconnect.Tim Wiederhake1-0/+61
This patch allows gdbserver to continue recording after disconnect. On reconnect, the recorded data is accessible to gdb as if no disconnect happened. A possible application for this feature is remotely examine bugs that occur at irregular intervals, where maintaining a gdb connection is inconvenient. This also fixes the issue mentioned here: https://sourceware.org/ml/gdb-patches/2015-11/msg00424.html Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com> gdb/ChangeLog: * NEWS: Resume btrace on reconnect. * record-btrace.c: Added record-btrace.h include. (record_btrace_open): Split into this and ... (record_btrace_push_target): ... this. (record_btrace_disconnect): New function. (init_record_btrace_ops): Use record_btrace_disconnect. * record-btrace.h: New file. * remote.c: Added record-btrace.h include. (remote_start_remote): Check recording status. (remote_btrace_maybe_reopen): New function. gdb/doc/ChangeLog: * gdb.texinfo: Resume btrace on reconnect. gdb/testsuite/ChangeLog: * gdb.btrace/reconnect.c: New file. * gdb.btrace/reconnect.exp: New file. Change-Id: I95e8b0ab8a89e58591aba0e63818cee82fd211bc
2016-07-01Optimize memory_xfer_partial for remoteDon Breazeal1-0/+9
Some analysis we did here showed that increasing the cap on the transfer size in target.c:memory_xfer_partial could give 20% or more improvement in remote load across JTAG. Transfer sizes were capped to 4K bytes because of performance problems encountered with the restore command, documented here: https://sourceware.org/ml/gdb-patches/2013-07/msg00611.html and in commit 67c059c29e1f ("Improve performance of large restore commands"). The 4K cap was introduced because in a case where the restore command requested a 100MB transfer, memory_xfer_partial would repeatedy allocate and copy an entire 100MB buffer in order to properly handle breakpoint shadow instructions, even though memory_xfer_partial would actually only write a small portion of the buffer contents. A couple of alternative solutions were suggested: * change the algorithm for handling the breakpoint shadow instructions * throttle the transfer size up or down based on the previous actual transfer size I tried implementing the throttling approach, and my implementation reduced the performance in some cases. This patch implements a new target function that returns that target's limit on memory transfer size. It defaults to ULONGEST_MAX bytes, because for native targets there is no marshaling and thus no limit is needed. For remote targets it uses get_memory_write_packet_size. gdb/ChangeLog: * remote.c (remote_get_memory_xfer_limit): New function. * target-delegates.c: Regenerate. * target.c (memory_xfer_partial): Call target_ops.to_get_memory_xfer_limit. * target.h (struct target_ops) <to_get_memory_xfer_limit>: New member.
2016-07-01Factor out "Detaching from program" message printingPedro Alves1-9/+1
Several targets have a copy of the same code that prints "Detaching from program ..." in their target_detach implementation. Factor that out to a common function. (For now, I left the couple targets that print this a bit differently alone. Maybe this could be further pulled out into infcmd.c. If we did that, and those targets want to continue printing differently, this new function could be converted to a target method.) gdb/ChangeLog: 2016-07-01 Pedro Alves <palves@redhat.com> * darwin-nat.c (darwin_detach): Use target_announce_detach. * inf-ptrace.c (inf_ptrace_detach): Likewise. * nto-procfs.c (procfs_detach): Likewise. * remote.c (remote_detach_1): Likewise. * target.c (target_announce_detach): New function. * target.h (target_announce_detach): New declaration.
2016-06-21Make input_fd be per UIPedro Alves1-2/+0
And with that, we can switch the current UI to the UI whose input descriptor woke up the event loop. IOW, if the user types in UI 2, the event loop wakes up, switches to UI 2, and processes the input. Next the user types in UI 3, the event loop wakes up and switches to UI 3, etc. gdb/ChangeLog: 2016-06-21 Pedro Alves <palves@redhat.com> * event-top.c (input_fd): Delete. (stdin_event_handler): Switch to the UI whose input descriptor got the event. Adjust to per-UI input_fd. (gdb_setup_readline): Don't set the input_fd global. Adjust to per-UI input_fd. (gdb_disable_readline): Adjust to per-UI input_fd. * event-top.h (input_fd): Delete declaration. * linux-nat.c (linux_nat_terminal_inferior): Don't remove input_fd from the event-loop here. (linux_nat_terminal_ours): Don't register input_fd in the event-loop here. * main.c (captured_main): Adjust to per-UI input_fd. * remote.c (remote_terminal_inferior): Don't remove input_fd from the event-loop here. (remote_terminal_ours): Don't register input_fd in the event-loop here. * target.c: Include top.h and event-top.h. (target_terminal_inferior): Remove input_fd from the event-loop here. (target_terminal_ours): Register input_fd in the event-loop. * top.h (struct ui) <input_fd>: New field.
2016-04-27Workaround gdbserver<7.7 for setfsJan Kratochvil1-0/+19
With current FSF GDB HEAD and old FSF gdbserver I expected I could do: gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234' (supplying that unsupported qXfer:exec-file:read by "file") But that does not work because: Sending packet: $vFile:setfs:0#bf...Packet received: OK Packet vFile:setfs (hostio-setfs) is supported ... Sending packet: $vFile:setfs:104#24...Packet received: OK "target:/root/redhat/threadit": could not open as an executable file: Invalid argument GDB documentation says: The valid responses to Host I/O packets are: An empty response indicates that this operation is not recognized. This "empty response" vs. "OK" was a bug in gdbserver < 7.7. It was fixed by: commit e7f0d979dd5cc4f8b658df892e93db69d6d660b7 Author: Yao Qi <yao@codesourcery.com> Date: Tue Dec 10 21:59:20 2013 +0800 Fix a bug in matching notifications. Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com> https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html 2013-12-10 Yao Qi <yao@codesourcery.com> * notif.c (handle_notif_ack): Return 0 if no notification matches. with unpatched old FSF gdbserver and patched FSF GDB HEAD: gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234' Sending packet: $vFile:setfs:0#bf...Packet received: OK Packet vFile:setfs (hostio-setfs) is NOT supported ... (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x00007ffff7ddbae0 0x00007ffff7df627a Yes (*) target:/lib64/ld-linux-x86-64.so.2 0x00007ffff7bc48a0 0x00007ffff7bcf514 Yes (*) target:/lib64/libpthread.so.0 gdb/ChangeLog 2016-04-26 Jan Kratochvil <jan.kratochvil@redhat.com> * remote.c (remote_start_remote): Detect PACKET_vFile_setfs.support.
2016-04-13Fix PR remote/19840: gdb crashes on reverse-stepiPedro Alves1-0/+20
Reverse debugging against a remote target that does reverse debugging itself (with the bs/bc packets) always trips on: (gdb) target remote localhost:... (gdb) reverse-stepi ../../gdb/target.c:602: internal-error: default_execution_direction: to_execution_direction must be implemented for reverse async I missed adding a to_execution_direction method to remote.c in commit 3223143295b5 (Adds target_execution_direction to make record targets support async mode), GDB 7.4 time. Later, GDB 7.8 switched to target-async on by default, making the regression user-visible by default too. Fix is simply to add the missing to_execution_direction implementation to target remote. Tested by Andi Kleen against Simics. gdb/ChangeLog: 2016-04-13 Pedro Alves <palves@redhat.com> PR remote/19840 * remote.c (struct remote_state) <last_resume_exec_dir>: New field. (new_remote_state): Default last_resume_exec_dir to EXEC_FORWARD. (remote_open_1): Reset last_resume_exec_dir to EXEC_FORWARD. (remote_resume): Store the last execution direction. (remote_execution_direction): New function. (init_remote_ops): Install it as to_execution_direction target_ops method.
2016-04-12target remote: Don't rely on immediate_quit (introduce quit handlers)Pedro Alves1-156/+113
remote.c is the last user of immediate_quit. It's relied on to immediately break the initial remote connection sync up, if the user does Ctrl-C, assuming that was because the target isn't responding. At that stage, since the connection isn't synced yet, disconnecting is the only safe thing to do. This commit reworks that, to not rely on throwing from the SIGINT signal handler. So, this commit: - Introduces the concept of a "quit handler". This is used to override what does the QUIT macro do when the quit flag is set. - Makes the "struct serial" reachar / write code call QUIT in the partial read/write loops, so the current quit handler is invoked whenever a serial->read_prim / serial->write_prim returns EINTR. - Makes the "struct serial" reachar / write code call interruptible_select instead of gdb_select, so that QUITs are detected in a race-free manner. - Stops remote.c from setting immediate_quit during the initial connection. - Instead, we install a custom quit handler whenever we're calling into the serial code. This custom quit handler knows to immediately throw a quit when we're in the initial connection setup, and otherwise defer handling the quit/Ctrl-C request to later, when we're safely out of a packet command/response sequence. This also is what is now responsible for handling "double Ctrl-C because target connection is stuck/wedged." - remote.c no longer installs a specialized SIGINT handlers, and instead re-uses the quit flag. Since we want to rely on the QUIT macro, the SIGINT handler must also set the quit. And the easiest is just to not install custom SIGINT handler in remote.c. Let the standard SIGINT handler do its job of setting the quit flag. Centralizing SIGINT handlers seems like a good thing to me, anyway. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> * defs.h (quit_handler_ftype, quit_handler) (make_cleanup_override_quit_handler, default_quit_handler): New. (QUIT): Adjust comments. * event-top.c (default_quit_handler): New function. (quit_handler): New global. (struct quit_handler_cleanup_data): New. (restore_quit_handler, restore_quit_handler_dtor) (make_cleanup_override_quit_handler): New. (async_request_quit): Call QUIT. * remote.c (struct remote_state) <got_ctrlc_during_io>: New field. (async_sigint_remote_twice_token, async_sigint_remote_token): Delete. (remote_close): Update comments. (remote_start_remote): Don't set immediate_quit. Set starting_up earlier. (remote_serial_quit_handler, remote_unpush_and_throw): New functions. (remote_open_1): Clear got_ctrlc_during_io. Set remote_async_terminal_ours_p unconditionally. (async_initialize_sigint_signal_handler) (async_handle_remote_sigint, async_handle_remote_sigint_twice) (remote_check_pending_interrupt, async_remote_interrupt) (async_remote_interrupt_twice) (async_cleanup_sigint_signal_handler, ofunc) (sync_remote_interrupt, sync_remote_interrupt_twice): Delete. (remote_terminal_inferior, remote_terminal_ours): Remove async checks. (remote_wait_as): Don't install a SIGINT handler in sync mode. (readchar, remote_serial_write): Override the quit handler with remote_serial_quit_handler. (getpkt_or_notif_sane_1): Don't call QUIT. (initialize_remote_ops): Don't install remote_check_pending_interrupt. (_initialize_remote): Don't create async_sigint_remote_token and async_sigint_remote_twice_token. * ser-base.c (ser_base_wait_for): Call QUIT and use interruptible_select. (ser_base_write): Call QUIT. * ser-go32.c (dos_readchar, dos_write): Call QUIT. * ser-unix.c (wait_for): Don't use VTIME. Always take the gdb_select path, but call QUIT and interruptible_select. * utils.c (maybe_quit): Call the current quit handler. Don't call target_check_pending_interrupt. (defaulted_query, prompt_for_continue): Override the quit handler with the default quit handler.
2016-04-12Do target_terminal_ours in query & friends instead of in all callersPedro Alves1-6/+0
Any time a caller calls query & friends / prompt_for_continue without ensuring that gdb owns the terminal for input is a bug. So do that in defaulted_query / prompt_for_continue directly instead. An example of a case where we currently miss calling target_terminal_ours is internal_error. Ever since defaulted_query was made to use gdb_readline_callback, there's no way to answer the internal error query if the internal error happens while the target is has the terminal: (gdb) c Continuing. .../src/gdb/linux-nat.c:1676: internal-error: linux_nat_resume: Assertion `dummy_counter < 10' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) _ Entering 'y' or 'n' does not work, GDB does not respond. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> PR gdb/19828 * gnu-nat.c (inf_validate_task_sc): Don't call target_terminal_ours / target_terminal_inferior around query. * i386-tdep.c (i386_record_lea_modrm, i386_process_record): Don't call target_terminal_ours / target_terminal_inferior around yquery. * linux-record.c (record_linux_system_call): Don't call target_terminal_ours / target_terminal_inferior around yquery. * nto-procfs.c (interrupt_query): Don't call target_terminal_ours / target_terminal_inferior around query. * record-full.c (record_full_check_insn_num): Remove 'set_terminal' parameter. Don't call target_terminal_ours / target_terminal_inferior around query. (record_full_message, record_full_registers_change) (record_full_xfer_partial): Adjust. * remote.c (interrupt_query): Don't call target_terminal_ours / target_terminal_inferior around query. * utils.c (defaulted_query): Install cleanup to restore target terminal. Put target_terminal_ours_for_output in effect while defaulted producing, and target_terminal_ours in in effect while handling input. (prompt_for_continue): Install cleanup to restore target terminal. Put target_terminal_ours in in effect while handling input.
2016-04-12Pass Ctrl-C to the target in target_terminal_inferiorPedro Alves1-0/+22
If the user presses Ctrl-C immediately before target_terminal_inferior is called and the target is resumed, instead of after, the Ctrl-C ends up pending in the quit flag until the target next stops. remote.c has this bit to handle this: if (!target_is_async_p ()) { ofunc = signal (SIGINT, sync_remote_interrupt); /* If the user hit C-c before this packet, or between packets, pretend that it was hit right here. */ if (check_quit_flag ()) sync_remote_interrupt (SIGINT); } But that's only reachable if async is off, while async is on by default nowadays. It's also obviously not reacheable on native targets. This patch generalizes that to all targets. We can't remove that remote.c bit yet, until we get rid of the sync SIGINT handler though. That'll be done later in the series. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> * remote.c (remote_pass_ctrlc): New function. (init_remote_ops): Install it. * target.c (target_terminal_inferior): Pass pending Ctrl-C to the target. (target_pass_ctrlc, default_target_pass_ctrlc): New functions. * target.h (struct target_ops) <to_pass_ctrlc>: New method. (target_pass_ctrlc, default_target_pass_ctrlc): New declarations. * target-delegates.c: Regenerate.
2016-04-12Decouple target_interrupt from all-stop/non-stop modesPedro Alves1-26/+9
In non-stop mode, "interrupt" results in a "stop with no signal", while in all-stop mode, it results in a remote interrupt request / stop with SIGINT. This is currently implemented in both the Linux and remote target backends. Move it to the core code instead, making target_interrupt specifically always about "Interrupting as if with Ctrl-C", just like it is documented. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> * infcmd.c (interrupt_target_1): Call target_stop is in non-stop mode. * linux-nat.c (linux_nat_interrupt): Delete. (linux_nat_add_target): Don't install linux_nat_interrupt. * remote.c (remote_interrupt_ns): Change return type to void. Throw error if interrupting the target is not supported. (remote_interrupt): Don't call the remote_stop_ns/remote_stop_as.
2016-04-12Don't call clear_quit_flag after check_quit_flagPedro Alves1-4/+1
Obviously not necessary since check_quit_flag clears the flag as side effect. gdb/ChangeLog: 2016-04-12 Pedro Alves <palves@redhat.com> * remote-sim.c (gdb_os_poll_quit): Don't call clear_quit_flag. * remote.c (remote_wait_as): Don't call clear_quit_flag.
2016-04-06Revert the previous commit adding unknown_v_replies_ok.Jan Kratochvil1-31/+0
It broke the compatibility with gdbserver-7.6 due to: warning: remote target does not support file transfer, attempting to access files from local filesystem. gdb/ChangeLog 2016-04-06 Jan Kratochvil <jan.kratochvil@redhat.com> Revert the previous commit adding unknown_v_replies_ok.
2016-04-06Workaround gdbserver<7.7 for setfsJan Kratochvil1-0/+31
With current FSF GDB HEAD and old FSF gdbserver I expected I could do: gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234' (supplying that unsupported qXfer:exec-file:read by "file") But that does not work because: Sending packet: $vFile:setfs:0#bf...Packet received: OK Packet vFile:setfs (hostio-setfs) is supported ... Sending packet: $vFile:setfs:104#24...Packet received: OK "target:/root/redhat/threadit": could not open as an executable file: Invalid argument GDB documentation says: The valid responses to Host I/O packets are: An empty response indicates that this operation is not recognized. This "empty response" vs. "OK" was a bug in gdbserver < 7.7. It was fixed by: commit e7f0d979dd5cc4f8b658df892e93db69d6d660b7 Author: Yao Qi <yao@codesourcery.com> Date: Tue Dec 10 21:59:20 2013 +0800 Fix a bug in matching notifications. Message-ID: <1386684626-11415-1-git-send-email-yao@codesourcery.com> https://sourceware.org/ml/gdb-patches/2013-12/msg00373.html 2013-12-10 Yao Qi <yao@codesourcery.com> * notif.c (handle_notif_ack): Return 0 if no notification matches. with unpatched old FSF gdbserver and patched FSF GDB HEAD: gdb -ex 'file target:/root/redhat/threadit' -ex 'target remote :1234' Sending packet: $vFile:setfs:0#bf...Packet received: OK Packet vFile:setfs (hostio-setfs) is NOT supported ... (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x00007ffff7ddbae0 0x00007ffff7df627a Yes (*) target:/lib64/ld-linux-x86-64.so.2 0x00007ffff7bc48a0 0x00007ffff7bcf514 Yes (*) target:/lib64/libpthread.so.0 gdb/ChangeLog 2016-04-06 Jan Kratochvil <jan.kratochvil@redhat.com> * remote.c (struct remote_state): New field unknown_v_replies_ok. (packet_config_support): Read it. (remote_start_remote): Set it.
2016-04-06Revert check-in by a mistake in the previous commit.Jan Kratochvil1-27/+0
gdb/ChangeLog 2016-04-06 Jan Kratochvil <jan.kratochvil@redhat.com> * remote.c: Revert check-in by a mistake in the previous commit.
2016-04-06Print the "file" command suggestion in exec_file_locate_attachJan Kratochvil1-0/+27
currently: $ gdbserver-7.9 :1234 true & $ gdb -q -ex 'target remote :1234' # that -q is not relevant here Remote debugging using :1234 warning: Could not load vsyscall page because no executable was specified try using the "file" command first. 0x00007ffff7ddcc80 in ?? () (gdb) b main No symbol table is loaded. Use the "file" command. Make breakpoint pending on future shared library load? (y or [n]) _ Provide more suggestive message to use the "file" command. gdb/ChangeLog 2016-04-06 Jan Kratochvil <jan.kratochvil@redhat.com> Pedro Alves <palves@redhat.com> * exec.c (exec_file_locate_attach): Print warning for unsupported target_pid_to_exec_file. * symfile-mem.c (add_vsyscall_page): Remove the "file" command message part.
2016-03-30gdbserver: Handle 'v' packet while processing qSymbol.Marcin Kościelnicki1-5/+7
On powerpc64, qSymbol query may require gdb to read a function descriptor, sending a vFile packet to gdbserver. Thus, we need to handle 'v' packet in look_up_one_symbol. vFile replies may be quite long, and require reallocating own_buf. Since handle_v_requests assumes the buffer is the static global own_buf from server.c and reallocates it, we need to make own_buf global and use it from look_up_one_symbol instead of using our own auto variable. I've also done the same change in relocate_instruction, just in case. On gdb side, in remote_check_symbols, rs->buf may be clobbered by vFile handling, yet we need its contents for the reply (the symbol name is stored there). Allocate a new buffer instead. This broke fast tracepoints on powerpc64, due to errors in reading IPA symbols. gdb/ChangeLog: * remote.c (remote_check_symbols): Allocate own buffer for reply. gdbserver/ChangeLog: * remote-utils.c (look_up_one_symbol): Remove own_buf, handle 'v' packets. (relocate_instruction): Remove own_buf. * server.c (own_buf): Make global. (handle_v_requests): Make global. * server.h (own_buf): New declaration. (handle_v_requests): New prototype.
2016-03-17PR remote/19496, timeout in forking-threads-plus-bkptPedro Alves1-12/+18
This patch addresses a failure in gdb.threads/forking-threads-plus-breakpoint.exp: FAIL: gdb.threads/forking-threads-plus-breakpoint.exp: cond_bp_target=1: detach_on_fork=on: inferior 1 exited (timeout) Cause: A fork event was reported to GDB before GDB knew about the parent thread, followed immediately by a breakpoint event in a different thread. The parent thread was subsequently added via remote_notice_new_inferior in process_stop_reply, but when the thread was added the thread_info.state was set to THREAD_STOPPED. The fork event was then handled correctly, but when the fork parent was resumed via a call to keep_going, the state was unchanged. The breakpoint event was then handled, which caused all the non-breakpoint threads to be stopped. When the breakpoint thread was resumed, all the non-breakpoint threads were resumed via infrun.c:restart_threads. Our old fork parent wasn't restarted, because it still had thread_info.state set to THREAD_STOPPED. Ultimately the program under debug hung waiting for a pthread_join while the old fork parent was stopped forever by GDB. Fix: Since this is non-stop, then the bug is that the thread should have been added in THREAD_RUNNING state. Consider that infrun may be pulling target events out of the target_ops backend into its own event queue, but, not process them immediately. E.g., infrun may be stopping all threads temporarily for a step-over-breakpoint operation for thread A (stop_all_threads). The waitstatus of all threads is thus left pending in the thread structure (save_status), including the fork event of thread B. Right at this point, if the user does "info threads", that should show thread B (the fork parent) running, not stopped, even if internally, gdb is holding it paused for a little bit. Thus if in non-stop mode, always add new threads in the external user-visible THREAD_RUNNING state. Change remote_notice_new_inferior to accept the internal executing state of the thread instead, with EXECUTING set to 1 when we discover a thread that is running on the target (such as through remote_update_thread_list), and 0 when the thread is really paused (such as when we see a stop reply). Tested on x86_64 Linux and Nios II Linux target with x86 Linux host. gdb/ChangeLog: 2016-03-17 Pedro Alves <palves@redhat.com> Don Breazeal <donb@codesourcery.com> PR remote/19496 * infcmd.c (notice_new_inferior): Use the 'leave_running' argument instead of checking the 'non_stop' global. * remote.c (remote_add_thread): New parameter 'executing'. Use it to set the new thread's executing state. (remote_notice_new_inferior): Rename parameter 'running' to 'executing'. Always set the thread state to THREAD_RUNNING in non-stop mode, and to THREAD_STOPPED in all-stop mode. Pass EXECUTING to remote_add_thread and notice_new_inferior. (remote_update_thread_list): Update to pass executing state, not running state.
2016-02-16PR remote/19496, internal err forking-threads-plus-bkptDon Breazeal1-1/+6
This patch fixes an internal error that occurs in gdb.threads/forking-threads-plus-breakpoint.exp: /blah/binutils-gdb/gdb/target.c:2723: internal-error: Can't determine the current address space of thread Thread 3170.3170 In default_thread_address_space, find_inferior_ptid couldn't find 3170.3170 because it had been overwritten in inferior_appeared, called as follows: inferior_appeared remote_add_inferior remote_notice_new_inferior remote_update_thread_list The cause of the problem was the following sequence of events: * GDB knows only about the main thread * the first fork event is reported to GDB, saved as pending_event * qXfer:threads:read gets the threads from the remote. remove_new_fork_children id's the fork child from the pending event and removes it from the list reported to GDB. All the rest of the threads, including the fork parent, are added to the GDB thread list. * GDB stops all the threads. All the stop events are pushed onto the stop reply queue behind the pending fork event. The fork waitstatus is saved in the fork parent thread's pending status field thread_info.suspend. * remote_wait_ns calls queued_stop_reply and process_stop_reply to remove the fork event from the front of the stop reply queue and save event information in the thread_info structure for the fork parent thread. Unfortunately, none of the information saved in this way is the fork-specific information. * A subsequent qXfer:threads:read packet gets the thread list including the fork parent and fork child. remove_new_fork_children checks the thread list to see if there is a fork parent, doesn't find one, checks the stop reply queue for a pending fork event, doesn't find one, and allows the fork child thread to be reported to GDB before the fork event has been handled. remote_update_thread_list calls remote_notice_new_thread and overwrites the current (main) thread in inferior_appeared. So the fork event has been reported out of target_wait but it was left pending on the infrun side (infrun.c:save_waitstatus). IOW, the fork event hasn't been processed by handle_inferior_event yet, so it hasn't made it to tp->pending_follow yet. The fix is to check thread_info.suspend along with the thread_info.pending_follow in remote.c:remove_new_fork_children, to prevent premature reporting of the fork child thread creation. gdb/ChangeLog: PR remote/19496 * remote.c (remove_new_fork_children): Check for pending fork status in thread_info.suspend. gdb/testsuite/ChangeLog: PR remote/19496 * gdb.threads/forking-threads-plus-breakpoint.exp (do_test): Remove kfail for PR remote/19496.
2016-02-08remote.c: Cleanup unused variablesSimon Marchi1-35/+2
I built remote.c with -Wunused, to check a function I was working on, turns out there is a bunch of unused variables. gdb/ChangeLog: * remote.c (remote_register_number_and_offset): Remove unused variable(s). (remote_thread_always_alive): Likewise. (remote_update_thread_list): Likewise. (process_initial_stop_replies): Likewise. (remote_start_remote): Likewise. (remote_check_symbols): Likewise. (discard_pending_stop_replies): Likewise. (process_stop_reply): Likewise. (putpkt_binary): Likewise. (getpkt): Likewise. (remote_add_target_side_condition): Likewise. (remote_insert_breakpoint): Likewise. (remote_supports_stopped_by_sw_breakpoint): Likewise. (remote_supports_stopped_by_hw_breakpoint): Likewise. (remote_xfer_partial): Likewise. (remote_read_btrace): Likewise. (remote_async_serial_handler): Likewise. (remote_thread_events): Likewise. (_initialize_remote): Likewise.
2016-02-04waiting_for_stop_reply around remote_fileio_requestYao Qi1-0/+8
Hi, I see this error when GDB connects with qemu, (gdb) n .... Sending packet: $vCont;c#a8...Ack Packet received: Ffstat,00000001,f6fff038 Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. looks we don't set rs->waiting_for_stop_reply to zero before handle fileio request, #10 0x00000000005edb64 in target_write (len=64, offset=4143968312, buf=0x7fffffffd570 "\375\377\377\377", annex=0x0, object=TARGET_OBJECT_MEMORY, ops=<optimised out>) at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1922 #11 target_write_memory (memaddr=memaddr@entry=4143968312, myaddr=myaddr@entry=0x7fffffffd6a0 "", len=len@entry=64) at /home/yao/SourceCode/gnu/gdb/git/gdb/target.c:1500 #12 0x00000000004b2b41 in remote_fileio_func_fstat (buf=0x127b258 "") at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1037 #13 0x00000000004b1878 in do_remote_fileio_request (uiout=<optimised out>, buf_arg=buf_arg@entry=0x127b240) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1204 #14 0x00000000005b8c7c in catch_exceptions_with_msg (func_uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>, func_args=func_args@entry=0x127b240, gdberrmsg=gdberrmsg@entry=0x0, mask=mask@entry=RETURN_MASK_ALL) at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:187 #15 0x00000000005b8dea in catch_exceptions (uiout=<optimised out>, func=func@entry=0x4b1800 <do_remote_fileio_request>, func_args=func_args@entry=0x127b240, mask=mask@entry=RETURN_MASK_ALL) at /home/yao/SourceCode/gnu/gdb/git/gdb/exceptions.c:167 #16 0x00000000004b2fff in remote_fileio_request (buf=0x127b240 "Xf6fff038,0:", ctrlc_pending_p=0) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote-fileio.c:1255 #17 0x0000000000496f12 in remote_wait_as (ptid=..., status=0x7fffffffdb20, options=1) at /home/yao/SourceCode/gnu/gdb/git/gdb/remote.c:6997 however, we did set rs->waiting_for_stop_reply to zero before Luis's patch https://sourceware.org/ml/gdb-patches/2015-10/msg00336.html In fact, Luis's patch v1 https://sourceware.org/ml/gdb-patches/2015-08/msg00809.html is about setting rs->waiting_for_stop_reply back to one after remote_fileio_request, which is correct. However during the review, the patch is changed and ends up with "not setting rs->waiting_for_stop_reply to zero". I manually test GDB, but I don't have a way to run regression tests. gdb: 2016-02-04 Yao Qi <yao.qi@linaro.org> * remote.c (remote_wait_as): Set rs->waiting_for_stop_reply to 0 before handling 'F' and set it back afterwards.
2016-01-28Import strchrnul from gnulib and use itSimon Marchi1-18/+8
For a forthcoming patch, I need a "skip_to_colon" function. I noticed there are two skip_to_semicolon (one in gdb and one in gdbserver). I thought we could put it in common/, and generalize it for any character. It turns out that the strchrnul function does exactly that. I imported the corresponding module from gnulib, for those systems that do not have it. There are probably more places where this function can be used instead of doing the work by hand (I am looking at remote-utils.c::look_up_one_symbol). gdb/ChangeLog: * remote.c (skip_to_semicolon): Remove. (remote_parse_stop_reply): Use strchrnul instead of skip_to_semicolon. * gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add strchrnul. * gnulib/aclocal.m4: Regenerate. * gnulib/config.in: Regenerate. * gnulib/configure: Regenerate. * gnulib/import/Makefile.am: Regenerate. * gnulib/import/Makefile.in: Regenerate. * gnulib/import/m4/gnulib-cache.m4: Regenerate. * gnulib/import/m4/gnulib-comp.m4: Regenerate. * gnulib/import/m4/rawmemchr.m4: New file. * gnulib/import/m4/strchrnul.m4: New file. * gnulib/import/rawmemchr.c: New file. * gnulib/import/rawmemchr.valgrind: New file. * gnulib/import/strchrnul.c: New file. * gnulib/import/strchrnul.valgrind: New file. gdb/gdbserver/ChangeLog: * server.c (skip_to_semicolon): Remove. (process_point_options): Use strchrnul instead of skip_to_semicolon.
2016-01-14Fix C++ build error by casting void *Yao Qi1-1/+1
Two recent patches breaks GDB C++ mode build, https://sourceware.org/ml/gdb-patches/2016-01/msg00150.html https://sourceware.org/ml/gdb-patches/2016-01/msg00086.html gdb/remote.c: In function 'int remote_set_syscall_catchpoint(target_ops*, int, int, int, int, int*)': gdb/remote.c:2036:39: error: invalid conversion from 'void*' to 'char*' [-fpermissive] catch_packet = xmalloc (maxpktsz); ^ gdb/thread.c: In function 'int do_captured_thread_select(ui_out*, void*)': gdb/git/gdb/thread.c:1999:24: error: invalid conversion from 'void*' to 'const char*' [-fpermissive] const char *tidstr = tidstr_v; ^ this patch fixes them by casting void * to the right type. gdb: 2016-01-14 Yao Qi <yao.qi@linaro.org> * remote.c (remote_set_syscall_catchpoint): Cast to char *. * thread.c (do_captured_thread_select): Cast to const char *.
2016-01-13Per-inferior/Inferior-qualified thread IDsPedro Alves1-1/+3
This commit changes GDB to track thread numbers per-inferior. Then, if you're debugging multiple inferiors, GDB displays "inferior-num.thread-num" instead of just "thread-num" whenever it needs to display a thread: (gdb) info inferiors Num Description Executable 1 process 6022 /home/pedro/gdb/tests/threads * 2 process 6037 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame 1.1 Thread 0x7ffff7fc2740 (LWP 6022) "threads" (running) 1.2 Thread 0x7ffff77c0700 (LWP 6028) "threads" (running) 1.3 Thread 0x7ffff7fc2740 (LWP 6032) "threads" (running) 2.1 Thread 0x7ffff7fc1700 (LWP 6037) "threads" (running) 2.2 Thread 0x7ffff77c0700 (LWP 6038) "threads" (running) * 2.3 Thread 0x7ffff7fc2740 (LWP 6039) "threads" (running) (gdb) ... (gdb) thread 1.1 [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))] (gdb) ... etc. You can still use "thread NUM", in which case GDB infers you're referring to thread NUM of the current inferior. The $_thread convenience var and Python's InferiorThread.num attribute are remapped to the new per-inferior thread number. It's a backward compatibility break, but since it only matters when debugging multiple inferiors, I think it's worth doing. Because MI thread IDs need to be a single integer, we keep giving threads a global identifier, _in addition_ to the per-inferior number, and make MI always refer to the global thread IDs. IOW, nothing changes from a MI frontend's perspective. Similarly, since Python's Breakpoint.thread and Guile's breakpoint-thread/set-breakpoint-thread breakpoint methods need to work with integers, those are adjusted to work with global thread IDs too. Follow up patches will provide convenient means to access threads' global IDs. To avoid potencially confusing users (which also avoids updating much of the testsuite), if there's only one inferior and its ID is "1", IOW, the user hasn't done anything multi-process/inferior related, then the "INF." part of thread IDs is not shown. E.g,.: (gdb) info inferiors Num Description Executable * 1 process 15275 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame * 1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) add-inferior Added inferior 2 (gdb) info threads Id Target Id Frame * 1.1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) No regressions on x86_64 Fedora 20. gdb/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * NEWS: Mention that thread IDs are now per inferior and global thread IDs. * Makefile.in (SFILES): Add tid-parse.c. (COMMON_OBS): Add tid-parse.o. (HFILES_NO_SRCDIR): Add tid-parse.h. * ada-tasks.c: Adjust to use ptid_to_global_thread_id. * breakpoint.c (insert_breakpoint_locations) (remove_threaded_breakpoints, bpstat_check_breakpoint_conditions) (print_one_breakpoint_location, set_longjmp_breakpoint) (check_longjmp_breakpoint_for_call_dummy) (set_momentary_breakpoint): Adjust to use global IDs. (find_condition_and_thread, watch_command_1): Use parse_thread_id. (until_break_command, longjmp_bkpt_dtor) (breakpoint_re_set_thread, insert_single_step_breakpoint): Adjust to use global IDs. * dummy-frame.c (pop_dummy_frame_bpt): Adjust to use ptid_to_global_thread_id. * elfread.c (elf_gnu_ifunc_resolver_stop): Likewise. * gdbthread.h (struct thread_info): Rename field 'num' to 'global_num. Add new fields 'per_inf_num' and 'inf'. (thread_id_to_pid): Rename thread_id_to_pid to global_thread_id_to_ptid. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (find_thread_id): Rename to ... (find_thread_global_id): ... this. (ALL_THREADS, ALL_THREADS_BY_INFERIOR): Declare. (print_thread_info): Add comment. * tid-parse.h: New file. * tid-parse.c: New file. * infcmd.c (step_command_fsm_prepare) (step_command_fsm_should_stop): Adjust to use the global thread ID. (until_next_command, until_next_command) (finish_command_fsm_should_stop): Adjust to use the global thread ID. (attach_post_wait): Adjust to check the inferior number too. * inferior.h (struct inferior) <highest_thread_num>: New field. * infrun.c (handle_signal_stop) (insert_exception_resume_breakpoint) (insert_exception_resume_from_probe): Adjust to use the global thread ID. * record-btrace.c (record_btrace_open): Use global thread IDs. * remote.c (process_initial_stop_replies): Also consider the inferior number. * target.c (target_pre_inferior): Clear the inferior's highest thread num. * thread.c (clear_thread_inferior_resources): Adjust to use the global thread ID. (new_thread): New inferior parameter. Adjust to use it. Set both the thread's global ID and the thread's per-inferior ID. (add_thread_silent): Adjust. (find_thread_global_id): New. (find_thread_id): Make static. Adjust to rename. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (thread_id_to_pid): Rename to ... (global_thread_id_to_ptid): ... this. Adjust. (first_thread_of_process): Adjust. (do_captured_list_thread_ids): Adjust to use global thread IDs. (should_print_thread): New function. (print_thread_info): Rename to ... (print_thread_info_1): ... this, and add new show_global_ids parameter. Handle it. Iterate over inferiors. (print_thread_info): Reimplement as wrapper around print_thread_info_1. (show_inferior_qualified_tids): New function. (print_thread_id): Use it. (tp_array_compar): Compare inferior numbers too. (thread_apply_command): Use tid_range_parser. (do_captured_thread_select): Use parse_thread_id. (thread_id_make_value): Adjust. (_initialize_thread): Adjust "info threads" help string. * varobj.c (struct varobj_root): Update comment. (varobj_create): Adjust to use global thread IDs. (value_of_root_1): Adjust to use global_thread_id_to_ptid. * windows-tdep.c (display_tib): No longer accept an argument. * cli/cli-utils.c (get_number_trailer): Make extern. * cli/cli-utils.h (get_number_trailer): Declare. (get_number_const): Adjust documentation. * mi/mi-cmd-var.c (mi_cmd_var_update_iter): Adjust to use global thread IDs. * mi/mi-interp.c (mi_new_thread, mi_thread_exit) (mi_on_normal_stop, mi_output_running_pid, mi_on_resume): * mi/mi-main.c (mi_execute_command, mi_cmd_execute): Likewise. * guile/scm-breakpoint.c (gdbscm_set_breakpoint_thread_x): Likewise. * python/py-breakpoint.c (bppy_set_thread): Likewise. * python/py-finishbreakpoint.c (bpfinishpy_init): Likewise. * python/py-infthread.c (thpy_get_num): Add comment and return the per-inferior thread ID. (thread_object_getset): Update comment of "num". gdb/testsuite/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.base/break.exp: Adjust to output changes. * gdb.base/hbreak2.exp: Likewise. * gdb.base/sepdebug.exp: Likewise. * gdb.base/watch_thread_num.exp: Likewise. * gdb.linespec/keywords.exp: Likewise. * gdb.multi/info-threads.exp: Likewise. * gdb.threads/thread-find.exp: Likewise. * gdb.multi/tids.c: New file. * gdb.multi/tids.exp: New file. gdb/doc/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Threads): Document per-inferior thread IDs, qualified thread IDs, global thread IDs and thread ID lists. (Set Watchpoints, Thread-Specific Breakpoints): Adjust to refer to thread IDs. (Convenience Vars): Document the $_thread convenience variable. (Ada Tasks): Adjust to refer to thread IDs. (GDB/MI Async Records, GDB/MI Thread Commands, GDB/MI Ada Tasking Commands, GDB/MI Variable Objects): Update to mention global thread IDs. * guile.texi (Breakpoints In Guile) <breakpoint-thread/set-breakpoint-thread breakpoint>: Mention global thread IDs instead of thread IDs. * python.texi (Threads In Python): Adjust documentation of InferiorThread.num. (Breakpoint.thread): Mention global thread IDs instead of thread IDs.
2016-01-12Implement 'catch syscall' for gdbserverJosh Stone1-0/+110
This adds a new QCatchSyscalls packet to enable 'catch syscall', and new stop reasons "syscall_entry" and "syscall_return" for those events. It is currently only supported on Linux x86 and x86_64. gdb/ChangeLog: 2016-01-12 Josh Stone <jistone@redhat.com> Philippe Waroquiers <philippe.waroquiers@skynet.be> * NEWS (Changes since GDB 7.10): Mention QCatchSyscalls and the syscall_entry and syscall_return stop reasons. Mention GDB support for remote catch syscall. * remote.c (PACKET_QCatchSyscalls): New enum. (remote_set_syscall_catchpoint): New function. (remote_protocol_features): New element for QCatchSyscalls. (remote_parse_stop_reply): Parse syscall_entry/return stops. (init_remote_ops): Install remote_set_syscall_catchpoint. (_initialize_remote): Config QCatchSyscalls. * linux-nat.h (struct lwp_info) <syscall_state>: Comment typo. gdb/doc/ChangeLog: 2016-01-12 Josh Stone <jistone@redhat.com> Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.texinfo (Remote Configuration): List the QCatchSyscalls packet. (Stop Reply Packets): List the syscall entry and return stop reasons. (General Query Packets): Describe QCatchSyscalls, and add it to the table and the detailed list of stub features. gdb/gdbserver/ChangeLog: 2016-01-12 Josh Stone <jistone@redhat.com> Philippe Waroquiers <philippe.waroquiers@skynet.be> * inferiors.h: Include "gdb_vecs.h". (struct process_info): Add syscalls_to_catch. * inferiors.c (remove_process): Free syscalls_to_catch. * remote-utils.c (prepare_resume_reply): Report syscall_entry and syscall_return stops. * server.h (UNKNOWN_SYSCALL, ANY_SYSCALL): Define. * server.c (handle_general_set): Handle QCatchSyscalls. (handle_query): Report support for QCatchSyscalls. * target.h (struct target_ops): Add supports_catch_syscall. (target_supports_catch_syscall): New macro. * linux-low.h (struct linux_target_ops): Add get_syscall_trapinfo. (struct lwp_info): Add syscall_state. * linux-low.c (handle_extended_wait): Mark syscall_state as an entry. Maintain syscall_state and syscalls_to_catch across exec. (get_syscall_trapinfo): New function, proxy to the_low_target. (linux_low_ptrace_options): Enable PTRACE_O_TRACESYSGOOD. (linux_low_filter_event): Toggle syscall_state entry/return for syscall traps, and set it ignored for all others. (gdb_catching_syscalls_p): New function. (gdb_catch_this_syscall_p): New function. (linux_wait_1): Handle SYSCALL_SIGTRAP. (linux_resume_one_lwp_throw): Add PTRACE_SYSCALL possibility. (linux_supports_catch_syscall): New function. (linux_target_ops): Install it. * linux-x86-low.c (x86_get_syscall_trapinfo): New function. (the_low_target): Install it. gdb/testsuite/ChangeLog: 2016-01-12 Josh Stone <jistone@redhat.com> Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/catch-syscall.c (do_execve): New variable. (main): Conditionally trigger an execve. * gdb.base/catch-syscall.exp: Enable testing for remote targets. (test_catch_syscall_execve): New, check entry/return across execve. (do_syscall_tests): Call test_catch_syscall_execve.
2016-01-01GDB copyright headers update after running GDB's copyright.py script.Joel Brobecker1-1/+1
gdb/ChangeLog: Update year range in copyright notice of all files.
2015-12-14Target remote mode fork and exec event supportDon Breazeal1-106/+99
This patch implements support for fork and exec events with target remote mode Linux targets. For such targets with Linux kernels 2.5.46 and later, this enables follow-fork-mode, detach-on-fork and fork and exec catchpoints. The changes required to implement this included: * Don't exit from gdbserver if there are still active inferiors. * Allow changing the active process in remote mode. * Enable fork and exec events in remote mode. * Print "Ending remote debugging" only when disconnecting. * Combine remote_kill and extended_remote_kill into a single function that can handle the multiple inferior case for target remote. Also, the same thing for remote_mourn and extended_remote_mourn. * Enable process-style ptids in target remote. * Remove restriction on multiprocess mode in target remote. gdb/gdbserver/ChangeLog: * server.c (process_serial_event): Don't exit from gdbserver in remote mode if there are still active inferiors. gdb/ChangeLog: * inferior.c (number_of_live_inferiors): New function. (have_live_inferiors): Use number_of_live_inferiors in place of duplicate code. * inferior.h (number_of_live_inferiors): Declare new function. * remote.c (set_general_process): Remove restriction on target remote mode. (remote_query_supported): Likewise. (remote_detach_1): Exit in target remote mode only when there is just one live inferior left. (remote_disconnect): Unpush the target directly instead of calling remote_mourn. (remote_kill): Rewrite function to handle both target remote and extended-remote. Call remote_kill_k. (remote_kill_k): New function. (extended_remote_kill): Delete function. (remote_mourn, extended_remote_mourn): Combine functions into one, remote_mourn, and enable extended functionality for target remote. (remote_pid_to_str): Enable "process" style ptid string for target remote. (remote_supports_multi_process): Remove restriction on target remote mode.
2015-12-01Avoid "operation may be undefined" warning in remote.cUlrich Weigand1-1/+1
GCC 4.1 gives the following warning: gdb/remote.c: In function 'remote_parse_stop_reply': gdb/remote.c:6549: warning: operation on 'p' may be undefined on this line of code: event->ptid = read_ptid (++p, &p); Since p actually isn't used afterwards anyway, simply use NULL. gdb/ * remote.c (remote_parse_stop_reply): Avoid GCC 4.1 "operation may be undefined" warning.
2015-12-01Fix uninitialized variable warnings in remote.cUlrich Weigand1-0/+2
Fix a couple of places where a struct thread_item was added to a vector while the item.name field was uninitialized. gdb/ * remote.c (remote_newthread_step): Initialize item.name. (remote_get_threads_with_qthreadinfo): Likewise.
2015-11-30Implement TARGET_WAITKIND_NO_RESUMED in the remote protocolPedro Alves1-3/+20
Testing with "maint set target-non-stop on" causes regressions in tests that rely on TARGET_WAITKIND_NO_RESUMED, which isn't modelled on the RSP. In real all-stop, gdbserver detects the situation and reporst error to GDB, and so the tests (e.g., gdb.threads/no-unwaited-for-left.exp) at fail quickly. But with "maint set target-non-stop on", GDB instead hangs forever waiting for a stop reply that never comes, and so the tests take longer to time out. This adds a new "N" stop reply packet that maps 1-1 to TARGET_WAITKIND_NO_RESUMED. gdb/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> PR 14618 * NEWS (New remote packets): Mention the N stop reply. * remote.c (remote_protocol_features): Add "no-resumed" entry. (remote_query_supported): Report no-resumed+ support. (remote_parse_stop_reply): Handle 'N'. (process_stop_reply): Handle TARGET_WAITKIND_NO_RESUMED. (remote_wait_as): Handle 'N' / TARGET_WAITKIND_NO_RESUMED. (_initialize_remote): Register "set/show remote no-resumed-stop-reply" commands. gdb/doc/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> PR 14618 * gdb.texinfo (Stop Reply Packets): Document the N stop reply. (Remote Configuration): Add the "set/show remote no-resumed-stop-reply" to the available settings table. (General Query Packets): Document the "no-resumed" qSupported feature. gdb/gdbserver/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> PR 14618 * linux-low.c (linux_wait_1): If the last resumed thread is gone, report TARGET_WAITKIND_NO_RESUMED. * remote-utils.c (prepare_resume_reply): Handle TARGET_WAITKIND_NO_RESUMED. * server.c (report_no_resumed): New global. (handle_query) <qSupported>: Handle "no-resumed+". Report "no-resumed+" support. (resume): When the target reports TARGET_WAITKIND_NO_RESUMED, only return error if the client doesn't support no-resumed events. (push_stop_notification): New function. (handle_target_event): Use it. Report TARGET_WAITKIND_NO_RESUMED events if the client supports them. gdb/testsuite/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> * gdb.threads/no-unwaited-for-left.exp: Remove setup_kfail calls.
2015-11-30Remote thread create/exit eventsPedro Alves1-5/+66
When testing with "maint set target-non-stop on", a few threading-related tests expose an issue that requires new RSP packets. Say there are 3 threads running, 1-3. If GDB tries to stop thread 1, 2 and 3, and then waits for their stops, but meanwhile say, thread 2 exits, GDB hangs forever waiting for a stop for thread 2 that won't ever happen. This patch fixes the issue by adding support for thread exit events to the protocol. However, we don't want these always enabled, as they're useless most of the time, and would slow down remote debugging. So I made it so that GDB can enable/disable them, and then made gdb do that around the cases that need it, which currently is only infrun.c:stop_all_threads. In turn, if we have thread exit events, then the extra "thread x exited" traffic slows down attach-many-short-lived-threads.exp enough that gdb has trouble keeping up with new threads that are spawned while gdb tries to stop existing ones. To fix that I added support for the counterpart thread created events too. Enabling those when we try to stop threads ensures that new threads never get a chance to themselves start new threads, killing the race. gdb/doc/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> * gdb.texinfo (Remote Configuration): List "set/show remote thread-events" command in configuration table. (Stop Reply Packets): Document "T05 create" stop reason and 'w' stop reply. (General Query Packets): Document QThreadEvents packet. Document QThreadEvents qSupported feature. gdb/gdbserver/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> * linux-low.c (handle_extended_wait): Assert that the LWP's waitstatus is TARGET_WAITKIND_IGNORE. If GDB wants to hear about thread create events, leave the new child's status pending. (linux_low_filter_event): If GDB wants to hear about thread exit events, leave the LWP marked dead and don't delete it. (linux_wait_for_event_filtered): Don't check for thread exit. (filter_exit_event): New function. (linux_wait_1): Use it, when returning an exit event. (linux_resume_one_lwp_throw): Assert that the LWP's waitstatus is TARGET_WAITKIND_IGNORE. * remote-utils.c (prepare_resume_reply): Handle TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED. * server.c (report_thread_events): New global. (handle_general_set): Handle QThreadEvents. (handle_query) <qSupported>: Handle and report QThreadEvents+; (handle_target_event): Handle TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED. * server.h (report_thread_events): Declare. gdb/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> * NEWS (New commands): Mention "set/show remote thread-events" commands. (New remote packets): Mention thread created/exited stop reasons and QThreadEvents packet. * infrun.c (disable_thread_events): New function. (stop_all_threads): Disable/enable thread create/exit events. Handle TARGET_WAITKIND_THREAD_EXITED. (handle_inferior_event_1): Handle TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED. * remote.c (remove_child_of_pending_fork): Also remove threads of threads that have TARGET_WAITKIND_THREAD_EXITED events. (remote_parse_stop_reply): Handle "create" magic register. Handle 'w' stop reply. (initialize_remote): Install remote_thread_events as to_thread_events target hook. (remote_thread_events): New function. * target-delegates.c: Regenerate. * target.c (target_thread_events): New function. * target.h (struct target_ops) <to_thread_events>: New field. (target_thread_events): Declare. * target/waitstatus.c (target_waitstatus_to_string): Handle TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED. * target/waitstatus.h (enum target_waitkind) <TARGET_WAITKIND_THREAD_CREATED, TARGET_WAITKIND_THREAD_EXITED): New values.
2015-11-30New vCtrlC packet, non-stop mode equivalent of \003Pedro Alves1-7/+58
There's currently no non-stop equivalent of the all-stop ^C (\003) "packet" that GDB sends when a ctrl-c is pressed while a foreground command is active. There's vCont;t, but that's defined to cause a "signal 0" stop. This fixes many tests that type ^C, when testing with extended-remote with "maint set target-non-stop on". E.g.: Continuing. talk to me baby PASS: gdb.base/interrupt.exp: process is alive a a PASS: gdb.base/interrupt.exp: child process ate our char ^C [Thread 22730.22730] #1 stopped. 0x0000003615ee6650 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:81 81 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS) (gdb) FAIL: gdb.base/interrupt.exp: send_gdb control C p func1 () gdb/ 2015-11-30 Pedro Alves <palves@redhat.com> * NEWS (New remote packets): Mention vCtrlC. * remote.c (PACKET_vCtrlC): New enum value. (async_remote_interrupt): Call target_interrupt instead of target_stop. (remote_interrupt_as): Remove 'ptid' parameter. (remote_interrupt_ns): New function. (remote_stop): Adjust. (remote_interrupt): If the target is in non-stop mode, try interrupting with vCtrlC. (initialize_remote): Install set remote ctrl-c packet. gdb/doc/ 2015-11-30 Pedro Alves <palves@redhat.com> * gdb.texinfo (Bootstrapping): Add "interrupting remote targets" anchor. (Packets): Document vCtrlC. gdb/gdbserver/ 2015-11-30 Pedro Alves <palves@redhat.com> * server.c (handle_v_requests): Handle vCtrlC.
2015-11-30remote: stop reason and watchpoint data address per threadPedro Alves1-25/+44
Running local-watch-wrong-thread.exp with "maint set target-non-stop on" exposes that gdb/remote.c only records whether the target stopped for a breakpoint/watchpoint plus the watchpoint data address *for the last reported remote event*. But in non-stop mode, we need to keep that info per-thread, as each thread can end up with its own last-status pending. gdb/ChangeLog: 2015-11-30 Pedro Alves <palves@redhat.com> * remote.c (struct remote_state) <remote_watch_data_address, stop_reason>: Delete fields. (struct private_thread_info) <stop_reason, watch_data_address>: New fields. (resume_clear_thread_private_info): New function. (append_pending_thread_resumptions): Call it. (remote_resume): Clear all threads' private info. (process_stop_reply): Adjust. (remote_wait_as): Don't reference remote_state's stop_reason field. (remote_stopped_by_sw_breakpoint) (remote_stopped_by_hw_breakpoint, remote_stopped_by_watchpoint) (remote_stopped_data_address): Adjust to refer get data from the current thread.
2015-11-30Remote all-stop-on-top-of-non-stopPedro Alves1-46/+162
This is the first pass at implementing support for all-stop mode running against the remote target using the non-stop variant of the protocol. The trickiest part here is the initial connection setup/synching. We need to fetch all inferiors' target descriptions etc. before stopping threads, because stop_all_threads needs to read the threads' registers (to record each thread's stop_pc). But OTOH, the initial inferior setup (target_post_attach, post_create_inferior, etc.), only works correctly if the inferior is stopped... So I've split that initial setup part from attach_command_post_wait to a separate function, and added a "still needs setup" flag to the inferior structure. This is similar to gdbserver/linux-low.c's handling of discovering the process's target description). Then if on connection all threads of the remote inferior are running, when we go about stopping them, as soon as they stop we call setup_inferior, from within stop_all_threads. Also, in all-stop, we need to process all the initial stop replies to learn about all the pending signal the threads may already be stopped for, and pick the one to report as current. This is exposed by gdb.threads/reconnect-signal.exp. gdb/ 2015-11-30 Pedro Alves <palves@redhat.com> * gdbthread.h (switch_to_thread_no_regs): Declare. * infcmd.c (setup_inferior): New function, factored out from ... (attach_command_post_wait): ... this. Rename to ... (attach_post_wait): ... this. Replace parameter async_exec with attach_post_wait_mode parameter. Adjust. (enum attach_post_wait_mode): New enum. (struct attach_command_continuation_args): Replace 'async_exec' field with 'mode' field. (attach_command_continuation): Adjust. (attach_command): Add comment. Mark the inferior as needing setup. Adjust to use enum attach_post_wait_mode. (notice_new_inferior): Use switch_to_thread_no_regs. Adjust to use enum attach_post_wait_mode. * inferior.h (setup_inferior): Declare. (struct inferior) <needs_setup>: New field. * infrun.c (set_last_target_status): Make extern. (stop_all_threads): Make extern. Setup inferior, if necessary. * infrun.h (set_last_target_status, stop_all_threads): Declare. * remote-notif.c (remote_async_get_pending_events_handler) (handle_notification): Replace non_stop checks with target_is_non_stop_p() checks. * remote.c (remote_notice_new_inferior): Remove non_stop check. (remote_update_thread_list): Replace non_stop check with target_is_non_stop_p() check. (print_one_stopped_thread): New function. (process_initial_stop_replies): New 'from_tty' parameter. "Notice" all new live inferiors after storing initial stops as pending status in each corresponding thread. If all-stop, stop all threads, try picking a signalled thread as current, and print the status of that one thread. Record the last target status. (remote_start_remote): Replace non_stop checks with target_is_non_stop_p() checks. Don't query for the remote current thread of use qOffsets here. Pass from_tty to process_initial_stop_replies. (extended_remote_attach): Replace non_stop checks with target_is_non_stop_p() checks. (extended_remote_post_attach): Send qOffsets here. (remote_vcont_resume, remote_resume, remote_stop) (remote_interrupt, remote_parse_stop_reply, remote_wait): Replace non_stop checks with target_is_non_stop_p() checks. (remote_async): If target is non-stop, mark/clear the pending events token. * thread.c (switch_to_thread_no_regs): New function.
2015-11-27remote.c: Add missing castSimon Marchi1-1/+1
Fixes in C++: /home/emaisin/src/binutils-gdb/gdb/remote.c: In function ‘void start_thread(gdb_xml_parser*, const gdb_xml_element*, void*, VEC_gdb_xml_value_s*)’: /home/emaisin/src/binutils-gdb/gdb/remote.c:2975:59: error: invalid conversion from ‘void*’ to ‘const char*’ [-fpermissive] item.name = attr != NULL ? (char *) xstrdup (attr->value) : NULL; ^ In file included from /home/emaisin/src/binutils-gdb/gdb/common/common-defs.h:64:0, from /home/emaisin/src/binutils-gdb/gdb/defs.h:28, from /home/emaisin/src/binutils-gdb/gdb/remote.c:22: /home/emaisin/src/binutils-gdb/gdb/../include/libiberty.h:323:14: error: initializing argument 1 of ‘char* xstrdup(const char*)’ [-fpermissive] extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; ^ make[2]: *** [remote.o] Error 1 gdb/ChangeLog: * remote.c (start_thread): Add cast.
2015-11-26Display names of remote threadsSimon Marchi1-1/+28
This patch adds support for thread names in the remote protocol, and updates gdb/gdbserver to use it. The information is added to the XML description sent in response to the qXfer:threads:read packet. gdb/ChangeLog: * linux-nat.c (linux_nat_thread_name): Replace implementation by call to linux_proc_tid_get_name. * nat/linux-procfs.c (linux_proc_tid_get_name): New function, implementation inspired by linux_nat_thread_name. * nat/linux-procfs.h (linux_proc_tid_get_name): New declaration. * remote.c (struct private_thread_info) <name>: New field. (free_private_thread_info): Free name field. (remote_thread_name): New function. (thread_item_t) <name>: New field. (clear_threads_listing_context): Free name field. (start_thread): Get name xml attribute. (thread_attributes): Add "name" attribute. (remote_update_thread_list): Copy name field. (init_remote_ops): Assign remote_thread_name callback. * target.h (target_thread_name): Update comment. * NEWS: Mention remote thread name support. gdb/gdbserver/ChangeLog: * linux-low.c (linux_target_ops): Use linux_proc_tid_get_name. * server.c (handle_qxfer_threads_worker): Refactor to include thread name in reply. * target.h (struct target_ops) <thread_name>: New field. (target_thread_name): New macro. gdb/doc/ChangeLog: * gdb.texinfo (Thread List Format): Mention thread names.
2015-11-19gdb: Workaround bad gdbserver qSupported:xmlRegisters=i386;UnknwnFeat+ handlingPedro Alves1-3/+5
gdbserver's target_process_qsupported is called for each feature that the gdbserver common code does not recognize. The only current implementation, for x86 Linux, does this: static void x86_linux_process_qsupported (const char *query) { /* Return if gdb doesn't support XML. If gdb sends "xmlRegisters=" with "i386" in qSupported query, it supports x86 XML target descriptions. */ use_xml = 0; if (query != NULL && startswith (query, "xmlRegisters=")) { char *copy = xstrdup (query + 13); char *p; for (p = strtok (copy, ","); p != NULL; p = strtok (NULL, ",")) { if (strcmp (p, "i386") == 0) { use_xml = 1; break; } } free (copy); } x86_linux_update_xmltarget (); } Notice that this clears use_xml and calls x86_linux_update_xmltarget each time target_process_qsupported is called. So if gdb sends in any unknown feature after "xmlRegisters=i386", like e.g., "xmlRegisters=i386;UnknownFeature+" gdbserver ends up not reporting a XML description... Work around this by having GDB send the "xmlRegisters=" feature last. gdb/ChangeLog: 2015-11-19 Pedro Alves <palves@redhat.com> * remote.c (remote_query_supported): Send the "xmlRegisters=" feature last.
2015-11-19[C++] remote.c: Avoid enum arithmeticPedro Alves1-1/+1
Fixes: src/gdb/remote.c: In function ‘void remote_unpush_target()’: src/gdb/remote.c:4610:45: error: invalid conversion from ‘int’ to ‘strata’ [-fpermissive] pop_all_targets_above (process_stratum - 1); ^ In file included from src/gdb/inferior.h:38:0, from src/gdb/remote.c:25: src/gdb/target.h:2299:13: error: initializing argument 1 of ‘void pop_all_targets_above(strata)’ [-fpermissive] extern void pop_all_targets_above (enum strata above_stratum); ^ I used to carry a patch in the C++ branch that just did: - pop_all_targets_above (process_stratum - 1); + pop_all_targets_above ((enum strata) (process_stratum - 1)); But then thought that maybe adding a routine that does exactly what we need results in clearer code. This is the result. gdb/ChangeLog: 2015-11-19 Pedro Alves <palves@redhat.com> * remote.c (remote_unpush_target): Use pop_all_targets_at_and_above instead of pop_all_targets_above. * target.c (unpush_target_and_assert): New function, factored out from ... (pop_all_targets_above): ... here. (pop_all_targets_at_and_above): New function. * target.h (pop_all_targets_at_and_above): Declare.