aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2020-06-21Various procfs.c cleanupsRainer Orth2-175/+52
While reading through procfs.c, I noticed a couple of cleanup opportunities: * Some comments and code allowed for portability across different targets. Since procfs.c is Solaris-only for some time now, those can go. * Likewise, there were some references to the old ioctl-based /proc left. * The code still allowed for SYS_exec. However, it is no longer present in either Solaris 11.3, 11.4, or Illumos. Checking the OpenSolaris sources, I found that it had already been removed in 2010 well before the Solaris 11 release. * Some blocks of #if 0 code can go: ** References to struct procinfo.{g,fp}regs_dirty which are no longer defined. ** Code handling the PR_ASLWP flag where <sys/procfs.h> has #define PR_ASLWP 0x00000040 /* obsolete flag; never set */ Tested on amd64-pc-solaris2.11. * procfs.c: Cleanup many comments. (READ_WATCHFLAG, WRITE_WATCHFLAG, EXEC_WATCHFLAG) (AFTER_WATCHFLAG): Replace by value. (MAIN_PROC_NAME_FORMAT): Inline ... (create_procinfo): ... here. (procfs_debug_inferior): Remove SYS_exec handling. (syscall_is_exec): Likewise. (procfs_set_exec_trap): Likewise. (syscall_is_lwp_exit): Inline in callers. (syscall_is_exit): Likewise. (syscall_is_exec): Likewise. (syscall_is_lwp_create): Likewise. (invalidate_cache): Remove #if 0 code. (make_signal_thread_runnable): Remove. (procfs_target::resume): Remove #if 0 code.
2020-06-21[PR gdb/25939] Move push_target call earlier in procfs.cRainer Orth2-5/+10
Since the multi-target patch, the run command fails on Solaris with an assertion failure even for a trivial program: $ ./gdb -D ./data-directory ./hello GNU gdb (GDB) 10.0.50.20200106-git [...] Reading symbols from ./hello... (gdb) run Starting program: /vol/obj/gnu/gdb/gdb/reghunt/no-resync/122448/gdb/hello /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:336: internal-error: thread_info::thread_info(inferior*, ptid_t): Assertion `inf_ != NULL' failed. Here's the start of the corresponding stack trace: #0 internal_error ( file=file@entry=0x966150 "/vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c", line=line@entry=336, fmt=0x9ddb94 "%s: Assertion `%s' failed.") at /vol/src/gnu/gdb/hg/master/reghunt/gdb/gdbsupport/errors.c:51 #1 0x0000000000ef81f4 in thread_info::thread_info (this=0x1212020, inf_=<optimized out>, ptid_=...) at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:344 #2 0x0000000000ef82cd in new_thread (inf=inf@entry=0x0, ptid=...) at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:239 #3 0x0000000000efac3c in add_thread_silent ( targ=targ@entry=0x11b0940 <the_procfs_target>, ptid=...) at /vol/src/gnu/gdb/hg/master/reghunt/gdb/thread.c:304 #4 0x0000000000d90692 in procfs_target::create_inferior ( this=0x11b0940 <the_procfs_target>, exec_file=0x13dbef0 "/vol/obj/gnu/gdb/gdb/reghunt/no-resync/122448/gdb/hello", allargs="", env=0x13c48f0, from_tty=<optimized out>) at /vol/src/gnu/gdb/hg/master/reghunt/gdb/gdbsupport/ptid.h:47 #5 0x0000000000c84e64 in run_command_1 (args=<optimized out>, from_tty=1, run_how=run_how@entry=RUN_NORMAL) at /vol/gcc-9/include/c++/9.1.0/bits/basic_string.h:263 #6 0x0000000000c85007 in run_command (args=<optimized out>, from_tty=<optimized out>) at /vol/src/gnu/gdb/hg/master/reghunt/gdb/infcmd.c:687 Looking closer, I found that in add_thread_silent as called from procfs.c (procfs_target::create_inferior) find_inferior_ptid returns NULL. The all_inferiors (targ) iterator comes up empty. Going from there, I see that in add_thread_silent m_target_stack = {m_top = file_stratum, m_stack = {0x20190e0 <the_dummy_target>, 0x200b8c0 <exec_ops>, 0x0, 0x0, 0x0, 0x0, 0x0}}} i.e. the_procfs_target is missing compared to the_amd64_linux_nat_target on Linux/x86_64. Moving the push_target call earlier allows debugging to get over the initial assertion failure. I run instead into procfs: couldn't find pid 0 in procinfo list. which is fixed by https://sourceware.org/pipermail/gdb-patches/2020-June/169674.html Both patches tested together on amd64-pc-solaris2.11. PR gdb/25939 * procfs.c (procfs_target::procfs_init_inferior): Move push_target call ... (procfs_target::create_inferior): ... here.
2020-06-21Ensure 'exec-file has changed' check has priority over 'exec-file-mismatch' ↵Philippe Waroquiers7-4/+104
check Following the implementation of exec-file-mismatch based on build-id, an attach to a process that runs a modified exec-file was triggering the exec-file-mismatch handling, giving a warning such as: warning: Mismatch between current exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach and automatically determined exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach exec-file-mismatch handling is currently "ask" as the build-ids differ when an exec-file is recompiled. This patch ensures that the exec-file-mismatch check is done with an up to date build-id. With this, exec-file-mismatch check will only trigger when the PID file really differs from the (build-id refreshed) current exec-file. Note that the additional check does not (yet) reload the symbols if the exec-file is changed: this reload will happen later if needed. gdb/ChangeLog 2020-06-21 Philippe Waroquiers <philippe.waroquiers@skynet.be> * exec.c (validate_exec_file): Ensure the build-id is up to date by calling reopen_exec_file (that checks file timestamp to decide to re-read the file). gdb/testsuite/ChangeLog 2020-06-21 Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/attach.exp: Test priority of 'exec-file' changed over 'exec-file-mismatch'. * gdb.base/attach.c: Mark should_exit volatile. * gdb.base/attach2.c: Likewise. Add a comment explaining why the sleep cannot be big. * gdb.base/attach3.c: New file.
2020-06-20Adjust gdb.mi/mi-sym-info.exp filename patterns.Sandra Loosemore2-9/+14
2020-06-20 Sandra Loosemore <sandra@codesourcery.com> * gdb.mi/mi-sym-info.exp: Adjust filename patterns to make directory prefix optional.
2020-06-20Fix gdb.base/list-missing-source.exp on remote host.Sandra Loosemore2-1/+7
2020-06-20 Sandra Loosemore <sandra@codesourcery.com> gdb/testsuite/ * gdb.base/list-missing-source.exp: Correct $srcfile manipulation for remote host.
2020-06-19Fixes for gdb.xml/tdesc-regs.exp.Sandra Loosemore2-2/+9
2020-06-19 Sandra Loosemore <sandra@codesourcery.com> Hafiz Abid Qadeer <abidh@codesourcery.com> * gdb.xml/tdesc-regs.exp (load_description): Correct pathname of file sent to remote host. (top level): Allow int32_t as type of 32-bit register.
2020-06-19[gdb/testsuite] Limit default_target_compile overrideTom de Vries3-13/+72
The file lib/future.exp contains an override of dejagnu's default_target_compile. The override is activated if dejagnu's default_target_compile is missing support for one or more languages. However, if the override is activated, it's active for all languages. This unnecessarily extends the scope of potential problems in the override to languages that don't need the override. Fix this by limiting the scope of the override. Also add a note stating for which languages the override is active, as a reminder that support for those languages needs to be ported to dejagnu. With my system dejagnu 1.6.1, as well as with current dejagnu trunk, that gives us: ... NOTE: Dejagnu's default_target_compile is missing support for Go, using \ local override NOTE: Dejagnu's default_target_compile is missing support for Rust, using \ local override ... Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-06-19 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (gdb_note): New proc. * lib/future.exp (gdb_default_target_compile_1): Factor out of ... (gdb_default_target_compile): ... here. Only call gdb_default_target_compile_1 if use_gdb_compile(<lang>) is set. (use_gdb_compile): Change to array. (toplevel): Update sets of use_gdb_compile to specify language. Warn about default_target_compile override. Store dejagnu's version of default_target_compile in dejagnu_default_target_compile.
2020-06-18Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR 25412)Pedro Alves3-72/+59
In PR 25412, Simon noticed that after the multi-target series, the tid-reuse.exp testcase manages to create a duplicate thread in the thread list. Or rather, two threads with the same PTID. add_thread_silent has code in place to detect the case of a new thread reusing some older thread's ptid, but it doesn't work correctly anymore when the old thread is NOT the current thread and it has a refcount higher than 0. Either condition prevents a thread from being deleted, but the refcount case wasn't being considered. I think the reason that case wasn't considered is that that code predates thread_info refcounting. Back when it was originally written, delete_thread always deleted the thread. That add_thread_silent code in question has some now-unnecessary warts, BTW. For instance, this: /* Make switch_to_thread not read from the thread. */ new_thr->state = THREAD_EXITED; ... used to be required because switch_to_thread would update 'stop_pc' otherwise. I.e., it would read registers from an exited thread otherwise. switch_to_thread no longer reads the stop_pc, since: commit f2ffa92bbce9dd5fbedc138ac2a3bc8a88327d09 Author: Pedro Alves <palves@redhat.com> AuthorDate: Thu Jun 28 20:18:24 2018 +0100 gdb: Eliminate the 'stop_pc' global Also, if the ptid of the now-gone current thread is reused, we currently return from add_thread_silent with the current thread pointing at the _new_ thread. Either pointing at the old thread, or at no thread selected would be reasonable. But pointing at an unrelated thread (the new thread that happens to reuse the ptid) is just broken. Seems like I was the one who wrote it like that but I have no clue why, FWIW. Currently, an exited thread kept in the thread list still holds its original ptid. The idea was that we need the ptid to be able to temporarily switch to another thread and then switch back to the original thread, because thread switching is really inferior_ptid switching. Switching back to the original thread requires a ptid lookup. Now, in order to avoid exited threads with the same ptid as a live thread in the same thread list, one thing I considered (and tried) was to change an exited thread's ptid to minus_one_ptid. However, with that, there's a case that we won't handle well, which is if we end up with more than one exited thread in the list, since then all exited threads will all have the same ptid. Since inferior_thread() relies on inferior_ptid, may well return the wrong thread. My next attempt to address this, was to switch an exited thread's ptid to a globally unique "exited" ptid, which is a ptid with pid == -1 and tid == 'the thread's global GDB thread number'. Note that GDB assumes that the GDB global thread number is monotonically increasing and doesn't wrap around. (We should probably make GDB thread numbers 64-bit to prevent that happening in practice; they're currently signed 32-bit.) This attempt went a long way, but still ran into a number of issues. It was a major hack too, obviously. My next attempt is the one that I'm proposing, which is to bite the bullet and break the connection between inferior_ptid and inferior_thread(), aka the current thread. I.e., make the current thread be a global thread_info pointer that is written to directly by switch_to_thread, etc., and making inferior_thread() return that pointer, instead of having inferior_thread() lookup up the inferior_ptid thread, by ptid_t. You can look at this as a continuation of the effort of using more thread_info pointers instead of ptids when possible. By making the current thread a global thread_info pointer, we can make switch_to_thread simply write to the global thread pointer, which makes scoped_restore_current_thread able to restore back to an exited thread without relying on unrelyable ptid look ups. I.e., this makes it not a real problem to have more than one thread with the same ptid in the thread list. There will always be only one live thread with a given ptid, so code that looks up a live thread by ptid will always be able to find the right one. This change required auditing the whole codebase for places where we were writing to inferior_ptid directly to change the current thread, and change them to use switch_to_thread instead or one of its siblings, because otherwise inferior_thread() would return a thread unrelated to the changed-to inferior_ptid. That was all (hopefully) done in previous patches. After this, inferior_ptid is mainly used by target backend code. It is also relied on by a number of target methods. E.g., the target_resume interface and the memory reading routines -- we still need it there because we need to be able to access memory off of processes for which we don't have a corresponding inferior/thread object, like when handling forks. Maybe we could pass down a context explicitly to target_read_memory, etc. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> PR gdb/25412 * gdbthread.h (delete_thread, delete_thread_silent) (find_thread_ptid): Update comments. * thread.c (current_thread_): New global. (is_current_thread): Move higher, and reimplement. (inferior_thread): Reimplement. (set_thread_exited): Use bool. Add assertions. (add_thread_silent): Simplify thread-reuse handling by always calling delete_thread. (delete_thread): Remove intro comment. (find_thread_ptid): Skip exited threads. (switch_to_thread_no_regs): Write to current_thread_. (switch_to_no_thread): Check CURRENT_THREAD_ instead of INFERIOR_PTID. Clear current_thread_.
2020-06-18Don't write to inferior_ptid in aix-thread.cPedro Alves2-1/+5
There are other writes in the file, but they seem more harmless. This one is changing the current thread permanently. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * aix-thread.c (pd_update): Use switch_to_thread.
2020-06-18Don't write to inferior_ptid in ravenscar-thread.cPedro Alves2-25/+32
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * ravenscar-thread.c (ravenscar_thread_target): Update. (ravenscar_thread_target::update_inferior_ptid): Rename to ... (ravenscar_thread_target::add_active_thread): ... this. Don't set m_base_ptid here. Update to avoid referencing inferior_ptid. (ravenscar_thread_target::wait): Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in windows-nat.c, part IIPedro Alves4-51/+70
Writing to inferior_ptid in windows_nat_target::get_windows_debug_event is just incorrect and not necessary. We'll report the event to GDB's core, which then takes care of switching inferior_ptid / current thread. Related (see windows_nat_target::get_windows_debug_event), there's also a "current_windows_thread" global that is just begging to get out of sync with core GDB's current thread. This patch removes it. gdbserver already does not have an equivalent global in win32-low.cc. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * nat/windows-nat.c (current_windows_thread): Remove. * nat/windows-nat.h (current_windows_thread): Remove. * windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint): Adjust. (display_selectors): Adjust to fetch the current windows_thread_info based on inferior_ptid. (fake_create_process): No longer write to current_windows_thread. (windows_nat_target::get_windows_debug_event): Don't set inferior_ptid or current_windows_thread. (windows_nat_target::wait): Adjust to not rely on current_windows_thread. (do_initial_windows_stuff): Now a method of windows_nat_target. Switch to the last_ptid thread. (windows_nat_target::attach): Adjust. (windows_nat_target::detach): Use switch_to_no_thread instead of writing to inferior_ptid directly. (windows_nat_target::create_inferior): Adjust.
2020-06-18Don't write to inferior_ptid in windows-nat.c, part IPedro Alves2-6/+4
The inferior_ptid hack in do_initial_win32_stuff, added back in 2008: https://sourceware.org/ml/gdb-patches/2008-10/msg00012.html with: commit 9f9d052e600ed9436f9fd558d62a189c8cc3d43e Author: Pierre Muller <muller@sourceware.org> AuthorDate: Thu Oct 2 14:20:07 2008 +0000 * win32-nat.c (do_initial_win32_stuff): Set inferior_ptid. is no longer needed. Back then, current_inferior looked like this: struct inferior* current_inferior (void) { struct inferior *inf = find_inferior_pid (ptid_get_pid (inferior_ptid)); gdb_assert (inf); return inf; } Nowadays, current_inferior() just returns the global current_inferior_ pointer, which didn't exist back then. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * windows-nat.c (do_initial_windows_stuff): No longer set inferior_ptid.
2020-06-18Don't write to inferior_ptid in go32-nat.cPedro Alves2-2/+8
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * go32-nat.c (go32_nat_target::create_inferior): Switch to thread after creating it, instead of writing to inferior_ptid. Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in fork-child.cPedro Alves2-3/+4
This is no longer necessary. All targets that call fork_inferior now also call switch_to_thread as soon as they add the main thread. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * fork-child.c (postfork_hook): Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in bsd-kvm.cPedro Alves2-2/+7
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * bsd-kvm.c (bsd_kvm_target_open): Switch to thread after adding it, instead of writing to inferior_ptid.
2020-06-18Don't write to inferior_ptid in btrace_fetchPedro Alves2-5/+11
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * btrace.c (btrace_fetch): Use switch_to_thread instead of writing to inferior_ptid.
2020-06-18Don't write to inferior_ptid in bsd-kvm.cPedro Alves2-1/+6
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * bsd-kvm.c (bsd_kvm_target::close): Use switch_to_no_thread instead of writing to inferior_ptid directly.
2020-06-18Don't write to inferior_ptid in corelow.cPedro Alves2-11/+16
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * corelow.c (core_target::close): Use switch_to_no_thread instead of writing to inferior_ptid directly. (add_to_thread_list, core_target_open): Use switch_to_thread instead of writing to inferior_ptid directly.
2020-06-18Don't write to inferior_ptid in darwin-nat.cPedro Alves2-9/+20
Untested. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * darwin-nat.c (darwin_nat_target::decode_message): Don't write to inferior_ptid. (darwin_nat_target::stop_inferior, darwin_nat_target::kill): Avoid inferior_ptid. (darwin_attach_pid): Use switch_to_no_thread instead of writing to inferior_ptid directly. (darwin_nat_target::init_thread_list): Switch to thread, instead of writing to inferior_ptid. (darwin_nat_target::attach): Don't write to inferior_ptid. (darwin_nat_target::get_ada_task_ptid): Avoid inferior_ptid.
2020-06-18Don't write to inferior_ptid in gnu-nat.cPedro Alves2-8/+17
Untested. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * gnu-nat.c (gnu_nat_target::create_inferior): Switch to the added thread. (gnu_nat_target::attach): Don't write to inferior_ptid directly. Instead use switch_to_thread. (gnu_nat_target::detach): Use switch_to_no_thread instead of writing to inferior_ptid directly. Used passed-in inferior instead of looking up the inferior by pid.
2020-06-18Don't write to inferior_ptid in go32-nat.cPedro Alves2-4/+5
generic_mourn_inferior already takes care of switching to no thread. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * go32-nat.c (go32_nat_target::create_inferior): Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in nto-procfs.cPedro Alves2-12/+26
A best effort patch, which fixes some bit rot and removes some inferior_ptid references -- this port clearly hasn't been built in a long while. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * nto-procfs.c (nto_procfs_target::update_thread_list): Avoid inferior_ptid. (nto_procfs_target::attach): Avoid inferior_ptid. Switch to thread. (nto_procfs_target::detach): Avoid referencing inferior_ptid. Use switch_to_no_thread instead of writing to inferior_ptid directly. (nto_procfs_target::mourn_inferior): Use switch_to_no_thread instead of writing to inferior_ptid directly. (nto_procfs_target::create_inferior): Avoid inferior_ptid. Switch to thread.
2020-06-18Don't write to inferior_ptid in remote-sim.cPedro Alves2-5/+13
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * remote-sim.c (gdbsim_target::create_inferior): Switch to thread after creating it, instead of writing to inferior_ptid. (gdbsim_target_open): Use switch_to_no_thread instead of writing to inferior_ptid directly. (gdbsim_target::wait): Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in remote.cPedro Alves2-16/+28
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * remote.c (remote_target::remote_notice_new_inferior): Use switch_to_thread instead of writing to inferior_ptid directly. (remote_target::add_current_inferior_and_thread): Use switch_to_no_thread instead of writing to inferior_ptid directly. (extended_remote_target::attach): Use switch_to_inferior_no_thread and switch_to_thread instead of using set_current_inferior or writing to inferior_ptid directly.
2020-06-18Don't write to inferior_ptid in tracectf.cPedro Alves2-3/+11
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * tracectf.c (ctf_target_open): Switch to added thread instead of writing to inferior_ptid directly. (ctf_target::close): Use switch_to_no_thread instead of writing to inferior_ptid directly.
2020-06-18Don't write to inferior_ptid in tracefile-tfile.cPedro Alves2-3/+11
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * tracefile-tfile.c (tfile_target_open): Don't write to inferior_ptid directly, instead switch to added thread. (tfile_target::close): Use switch_to_no_thread instead of writing to inferior_ptid directly.
2020-06-18Don't write to inferior_ptid in procfs.cPedro Alves2-10/+18
The inferior_ptid write in procfs_do_thread_registers should be unnecessary because the target_fetch_registers method should (and does) extract the ptid from the regcache. Not tested. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * procfs.c (procfs_target::attach): Don't write to inferior_ptid. (procfs_target::detach): Use switch_to_no_thread instead of writing to inferior_ptid directly. (do_attach): Change return type to void. Switch to the added thread. (procfs_target::create_inferior): Switch to the added thread. (procfs_do_thread_registers): Don't write to inferior_ptid.
2020-06-18Don't write to inferior_ptid in infrun.cPedro Alves2-61/+64
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * infrun.c (generic_mourn_inferior): Use switch_to_thread instead of writing to inferior_ptid. (scoped_restore_exited_inferior): Delete. (handle_vfork_child_exec_or_exit): Simplify using scoped_restore_current_pspace_and_thread. Use switch_to_thread instead of writing to inferior_ptid. (THREAD_STOPPED_BY): Delete. (thread_stopped_by_watchpoint, thread_stopped_by_sw_breakpoint) (thread_stopped_by_hw_breakpoint): Delete. (save_waitstatus): Use scoped_restore_current_thread+switch_to_thread, and call target_stopped_by_watchpoint instead of thread_stopped_by_watchpoint, target_stopped_by_sw_breakpoint instead of thread_stopped_by_sw_breakpoint, and target_stopped_by_hw_breakpoint instead of thread_stopped_by_hw_breakpoint. (handle_inferior_event) <TARGET_WAITKIND_EXITED/TARGET_WAITKIND_SIGNALLED>: Don't write to inferior_ptid directly, nor set_current_inferior/set_current_program_space. Use switch_to_thread / switch_to_inferior_no_thread instead.
2020-06-18Don't write to inferior_ptid in target.cPedro Alves2-1/+6
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * target.c (generic_mourn_inferior): Use switch_to_no_thread instead of writing to inferior_ptid.
2020-06-18Don't write to inferior_ptid in inf-ptrace.cPedro Alves2-10/+18
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * inf-ptrace.c (inf_ptrace_target::create_inferior): Switch to the added thread. (inf_ptrace_target::attach): Don't write to inferior_ptid. Switch to the added thread. (inf_ptrace_target::detach_success): Use switch_to_no_thread instead of writing to inferior_ptid.
2020-06-18Don't write to inferior_ptid in gdbarch-selftests.c, mock address_space tooPedro Alves2-8/+16
Use switch_to_thread instead of writing to inferior_ptid. This requires a couple of improvements to the mocking environment. One is to mock a pspace too, and assigning it to the inferior. In turn, this requires heap-allocating the address space, so that the regular program_space dtor destroys the address space correctly. (Note that new the mock program_space is allocated on the stack, and thus depends on the previous patch that eliminated delete_program_space.) gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * gdbarch-selftests.c: Include "progspace-and-thread.h". (register_to_value_test): Mock a program_space too. Heap-allocate the address space. Don't write to inferior_ptid. Use switch_to_thread instead.
2020-06-18gcore, handle exited threads betterPedro Alves2-27/+42
An early (and since discarded) version of this series tried to make exited threads have distinct PTID between each other, and that change exposed a problem in linux-tdep.c... This was exposed by the gdb.threads/gcore-stale-thread.exp testcase, which is exactly about calling gcore with an exited thread selected: (gdb) [Thread 0x7ffff7fb6740 (LWP 31523) exited] PASS: gdb.threads/gcore-stale-thread.exp: continue to breakpoint: break-here gcore /home/pedro/gdb/binutils-gdb/build/gdb/testsuite/outputs/gdb.threads/gcore-stale-thread/gcore-stale-thread.core /home/pedro/gdb/binutils-gdb/build/../src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, That was find_inferior_ptid being called on the "exited" ptid, which on that previous (and discarded attempt) had pid==-1. The problem is that linux-tdep.c, where it looks for the signalled thread, isn't considering exited threads. Also, while at it, that code isn't considering multi-target either, since it is using iterate_over_threads which iterates over all threads of all targets. Fixed by switching to range-for iteration instead. gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * linux-tdep.c (find_signalled_thread(thread_info *,void *)): Delete. (find_signalled_thread()): New, factored out from linux_make_corefile_notes and adjusted to handle exited threads. (linux_make_corefile_notes): Adjust to use the new find_signalled_thread.
2020-06-18Don't write to inferior_ptid in linux_get_siginfo_dataPedro Alves2-2/+7
gdb/ChangeLog: 2020-06-18 Pedro Alves <palves@redhat.com> * linux-tdep.c (btrace_fetch): Save/restore current thread instead of saving/restoring inferior_ptid.
2020-06-18[gdb/testsuite] Move code from gdb_init to default_gdb_initTom de Vries2-119/+132
If a baseboard file wants to override a proc foo, but also use the original proc, it'll have to do something like: ... rename foo save_foo proc foo { } { ... set res [save_foo] ... return res } ... This adds a new proc named save_foo, which introduces the risk of clashing with an existing proc. There's a pattern in the gdb testsuite procs, that facilitates this override: ... proc default_foo { } { ... } proc foo { } { return [default_foo] } ... such that in a baseboard file we don't need the rename: ... proc foo { } { ... set res [default_foo] ... return res } ... The exception to the pattern though is gdb_init, which has a default_gdb_init counterpart, but contains much more code than just the call to default_gdb_init. Fix this by moving all but the call to default_gdb_init to default_gdb_init. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-06-18 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (gdb_init): Move all but call to default_gdb_init to ... (default_gdb_init): ... here.
2020-06-17Fix TUI support checks in gdb.tui tests.Sandra Loosemore14-0/+39
2020-06-17 Sandra Loosemore <sandra@codesourcery.com> gdb/testsuite/ * gdb.tui/basic.exp: Skip test when TUI is unsupported, don't just say UNSUPPORTED. * gdb.tui/corefile-run.exp: Likewise. * gdb.tui/empty.exp: Likewise. * gdb.tui/list-before.exp: Likewise. * gdb.tui/list.exp: Likewise. * gdb.tui/main.exp: Likewise. * gdb.tui/regs.exp: Likewise. * gdb.tui/resize.exp: Likewise. * gdb.tui/tui-layout-asm-short-prog.exp: Likewise. * gdb.tui/tui-layout-asm.exp: Likewise. * gdb.tui/tui-missing-src.exp: Likewise. * gdb.tui/winheight.exp: Likewise. * gdb.tui/new-layout.exp: Likewise. Also move check earlier.
2020-06-17Remove unnecessary TUI declarationsTom Tromey3-7/+7
I found some unnecessary declarations (and one unused macro) in the TUI. This patch removes them. gdb/ChangeLog 2020-06-17 Tom Tromey <tom@tromey.com> * tui/tui-win.h (tui_scroll_forward, tui_scroll_backward) (tui_scroll_left, tui_scroll_right, struct tui_win_info): Don't declare. * tui/tui-data.h (MIN_CMD_WIN_HEIGHT): Remove.
2020-06-17Fix typo in my gdb.debuginfod entry.Keith Seitz1-1/+1
2020-06-17Fix TCL error in gdb.python/py-format-string.exp.Sandra Loosemore2-3/+12
2020-06-17 Sandra Loosemore <sandra@codesourcery.com> gdb/testsuite/ * gdb.python/py-format-string.exp: Move test for python support earlier, out of function body.
2020-06-17gdb: check for partial symtab presence in dwarf2_initialize_objfileSimon Marchi5-0/+82
This patch fixes an internal error that is triggered when loading the same binary twice with the index-cache on: $ ./gdb -q -nx --data-directory=data-directory (gdb) set index-cache on (gdb) shell mktemp -d /tmp/tmp.BLgouVoPq4 (gdb) set index-cache directory /tmp/tmp.BLgouVoPq4 (gdb) file a.out Reading symbols from a.out... (gdb) file a.out Load new symbol table from "a.out"? (y or n) y Reading symbols from a.out... /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:2540: internal-error: void create_cus_from_index(dwarf2_per_bfd*, const gdb_byte*, offset_type, const gdb_byte*, offset_type): Assertion `per_bfd->all_comp_units.empty ()' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) This is what happens: 1. We load the binary the first time, partial symtabs are created, per_bfd->all_comp_units is filled from those. 2. Because index-cache is on, we also generate an index in the cache. 3. We load the binary a second time, in dwarf2_initialize_objfile we check: was an index already loaded for this BFD? No, so we try to read the index and fill the per-bfd using it. We do find an index, it's in the cache. 4. The function create_cus_from_index asserts (rightfully) that per_cu->all_comp_units is empty, and the assertion fails. This assertion verifies that we are not reading an index for a BFD for which we have already built partial symtabs or read another index. The index-cache gives a situation that isn't currently accounted for: a BFD for which we have built the partial symtabs the first time, but has an index the second time. This patch addresses it by checking for the presence of partial symtabs in dwarf2_initialize_objfile. If there are, we don't try reading the index. gdb/ChangeLog: * dwarf2/read.c (dwarf2_initialize_objfile): Check for presence of partial symtabs. gdb/testsuite/ChangeLog: * gdb.base/index-cache-load-twice.c: New. * gdb.base/index-cache-load-twice.exp: New. Change-Id: Ie05474c44823fcdff852b73170dd28dfd66cb6a2
2020-06-17gdb/regformats: remove unused regformats/reg-*.datSimon Marchi8-335/+10
I believe that the .dat files starting with `reg-` are the manually written ones, the other being generated from xml files from the features directory. This patch removes the manually-written files that are no longer needed. They are unused since the recent series that removed a bunch of gdbserver ports. gdb/ChangeLog: * regformats/reg-arm.dat: Remove. * regformats/reg-bfin.dat: Remove. * regformats/reg-cris.dat: Remove. * regformats/reg-crisv32.dat: Remove. * regformats/reg-m32r.dat: Remove. * regformats/reg-tilegx.dat: Remove. * regformats/reg-tilegx32.dat: Remove. Change-Id: I55ab6e45e3d0d316cda93f863c51fc9b867adfaa
2020-06-17gdb, gdbserver: remove ARM regdat filesSimon Marchi6-232/+9
This patch removes the leftover regformats .dat files for the arm architecture. There are no longer relevant, since the arm architecture has been converted to use feature-based target-descriptions. These .dat files are used by GDBserver ports that still use static target descriptions. These .dat files are generated from corresponding .xml files in the features directory. And since the corresponding .xml files for these arm .dat files don't exist anymore, it is impossible to re-generated them. If you delete these .dat files and type "make" in the features directory, you'll get: make: *** No rule to make target '../regformats/arm/arm-with-iwmmxt.dat', needed by 'all'. Stop. So it removes the entries in the `WHICH` variable of gdb/features/Makefile. Finally, it removes the rule in gdbserver/Makefile to generate .cc files from `../gdb/regformats/arm/%.dat`. gdb/ChangeLog: * features/Makefile (WHICH): Remove arm files. * regformats/arm/arm-with-iwmmxt.dat: Remove. * regformats/arm/arm-with-neon.dat: Remove. * regformats/arm/arm-with-vfpv2.dat: Remove. * regformats/arm/arm-with-vfpv3.dat: Remove. gdbserver/ChangeLog: * Makefile.in (%-generated.cc: ../gdb/regformats/arm/%.dat): Remove. Change-Id: I3b7d989c50e2cb92235c1f7c7071a26839d84c78
2020-06-17gdb/features: remove rx.xml from XMLTOC listSimon Marchi2-1/+4
When trying to run `make` in the features directory, in a clean repo, we get: Makefile:254: warning: overriding recipe for target 'rx.c' Makefile:250: warning: ignoring old recipe for target 'rx.c' make: Nothing to be done for 'all'. The warnings come from the fact that `rx.xml` is present in two lists, causing two `rx.c` targets to be defined. It is ok for it to be in the FEATURES_XMLFILES list, as this architecture uses the "feature-based" target-descriptions. It shouldn't be in the XMLTOC list, as this is for architectures that define complete/static target descriptions as XML files. gdb/ChangeLog: * features/Makefile (XMLTOC): Remove rx.xml. Change-Id: Iada4ab54b3d4542588fac543d16ee35a92537319
2020-06-17Pass INTERNAL_GDBFLAGS when executing GDBKeith Seitz2-1/+7
gdb.debuginfod/fetch_src_and_symbols.exp attempts to ascertain whether GDB was built with debuginfod support by executing "$GDB --configuration". That seems harmless enough. However, if GDB is not already installed on the host, the command will fail: $ ./gdb --config Exception caught while booting Guile. Error in function "open-file": No such file or directory: "/usr/share/gdb/guile/gdb/boot.scm" ./gdb: warning: Could not complete Guile gdb module initialization from: /usr/share/gdb/guile/gdb/boot.scm. Limited Guile support is available. Suggest passing --data-directory=/path/to/gdb/data-directory. Python Exception <class 'ModuleNotFoundError'> No module named 'gdb': ./gdb: warning: Could not load the Python gdb module from `/usr/share/gdb/python'. Limited Python support is available from the _gdb module. Suggest passing --data-directory=/path/to/gdb/data-directory. This GDB was configured as follows: configure --host=x86_64-redhat-linux-gnu --target=x86_64-redhat-linux-gnu [abbreviated output] The problem here is, of course, that while running in the test suite, we must pass INTERNAL_GDBFLAGS in order to pick up the --data-directory option. gdb/testsuite/ChangeLog 2020-06-17 Keith Seitz <keiths@redhat.com> * gdb.deuginfod/fetch_src_and_symbols.exp: Pass INTERNAL_GDBFLAGS when executing "gdb --configuration".
2020-06-17[gdb/testsuite] Remove dependence on tcl_unknownTom de Vries2-11/+34
In gdb_init we install a local version of ::unknown, which relies on ::tcl_unknown, which is defined by dejagnu. This proc may be moved into a namespace, or disappear altogether, as indicated by dejagnu maintainers, so we can't rely on it. Fix this by recreating tcl's version of unknown, and using that instead. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-06-17 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (gdb_tcl_unknown): New proc. (gdb_init): Use gdb_tcl_unknown for ::unknown override. Make override conditional on presence of gdb_tcl_unknown. (gdb_finish): Make override undo conditional on presence of gdb_tcl_unknown.
2020-06-17Update thread_control_state::trap_expected commentsPedro Alves2-22/+9
The comments describing trap_expected are out of date. It predates displaced stepping and non-stop mode ("keep other threads stopped"). It predates stepping over watchpoints with breakpoints inserted (keep_going_pass_signal). Says the variable is cleared in normal_stop, when it isn't. This fixes it. gdb/ChangeLog: 2020-06-17 Pedro Alves <palves@redhat.com> * gdbthread.h (thread_control_state) <trap_expected> Update comments.
2020-06-17gdb: Convert language la_lookup_symbol_nonlocal field to a methodAndrew Burgess16-128/+171
This commit changes the language_data::la_lookup_symbol_nonlocal function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_lookup_symbol_nonlocal): Rename to ada_language::lookup_symbol_nonlocal. (ada_language_data): Delete la_lookup_symbol_nonlocal initializer. (ada_language::lookup_symbol_nonlocal): New member function, implementation from ada_lookup_symbol_nonlocal. * c-lang.c (c_language_data): Delete la_lookup_symbol_nonlocal initializer. (cplus_language_data): Delete la_lookup_symbol_nonlocal initializer. (cplus_language::lookup_symbol_nonlocal): New member function. (asm_language_data): Delete la_lookup_symbol_nonlocal initializer. (minimal_language_data) Likewise. * cp-namespace.c (cp_lookup_nested_symbol): Update comment. * d-lang.c (d_language_data): Delete la_lookup_symbol_nonlocal initializer. (d_language::lookup_symbol_nonlocal): New member function. * f-lang.c (f_language_data): Delete la_lookup_symbol_nonlocal initializer. (f_language::lookup_symbol_nonlocal): New member function. * go-lang.c (go_language_data): Delete la_lookup_symbol_nonlocal initializer. * language.c (unknown_language_data): Likewise. (auto_language_data): Likewise. * language.h (language_data): Delete la_lookup_symbol_nonlocal field. (language_defn::lookup_symbol_nonlocal): New member function. * m2-lang.c (m2_language_data): Delete la_lookup_symbol_nonlocal initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_lookup_symbol_nonlocal): Rename to rust_language::lookup_symbol_nonlocal. (rust_language_data): Delete la_lookup_symbol_nonlocal initializer. (rust_language::lookup_symbol_nonlocal): New member function, implementation from rust_lookup_symbol_nonlocal. * symtab.c (lookup_symbol_aux): Update call to lookup_symbol_nonlocal. (basic_lookup_symbol_nonlocal): Rename to... (language_defn::lookup_symbol_nonlocal): ...this, and update header comment. Remove language_defn parameter, and replace with uses of `this'. * symtab.h (basic_lookup_symbol_nonlocal): Delete declaration.
2020-06-17gdb: Convert language la_value_print_inner field to a methodAndrew Burgess16-34/+145
This commit changes the language_data::la_value_print_inner function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_value_print_inner initializer. (ada_language::value_print_inner): New member function. * c-lang.c (c_language_data): Delete la_value_print_inner initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. (d_language::value_print_inner): New member function. * f-lang.c (f_language_data): Delete la_value_print_inner initializer. (f_language::value_print_inner): New member function. * f-lang.h (f_value_print_innner): Rename to... (f_value_print_inner): ...this (note spelling of 'inner'). * f-valprint.c (f_value_print_innner): Rename to... (f_value_print_inner): ...this (note spelling of 'inner'). * go-lang.c (go_language_data): Delete la_value_print_inner initializer. (go_language::value_print_inner): New member function. * language.c (language_defn::value_print_inner): Define new member function. (unk_lang_value_print_inner): Delete. (unknown_language_data): Delete la_value_print_inner initializer. (unknown_language::value_print_inner): New member function. (auto_language_data): Delete la_value_print_inner initializer. (auto_language::value_print_inner): New member function. * language.h (language_data): Delete la_value_print_inner field. (language_defn::value_print_inner): Delcare new member function. * m2-lang.c (m2_language_data): Delete la_value_print_inner initializer. (m2_language::value_print_inner): New member function. * objc-lang.c (objc_language_data): Delete la_value_print_inner initializer. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. (pascal_language::value_print_inner): New member function. * rust-lang.c (rust_language_data): Delete la_value_print_inner initializer. (rust_language::value_print_inner): New member function. * valprint.c (do_val_print): Update call to value_print_inner.
2020-06-17gdb: Convert language la_value_print field to a methodAndrew Burgess13-32/+75
This commit changes the language_data::la_value_print function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_value_print initializer. (ada_language::value_print): New member function. * c-lang.c (c_language_data): Delete la_value_print initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_language_data): Likewise. * language.c (unk_lang_value_print): Delete. (language_defn::value_print): Define new member function. (unknown_language_data): Delete la_value_print initializer. (unknown_language::value_print): New member function. (auto_language_data): Delete la_value_print initializer. (auto_language::value_print): New member function. * language.h (language_data): Delete la_value_print field. (language_defn::value_print): Declare new member function. (LA_VALUE_PRINT): Update call to value_print. * m2-lang.c (m2_language_data): Delete la_value_print initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. (pascal_language::value_print): New member function. * rust-lang.c (rust_language_data): Delete la_value_print initializer.
2020-06-17gdb: Convert language la_watch_location_expression field to a methodAndrew Burgess15-61/+86
This commit changes the language_data::la_watch_location_expression function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_watch_location_expression): Rename to ada_language::watch_location_expression. (ada_language_data): Delete la_watch_location_expression initializer. (ada_language::watch_location_expression): New member function, implementation from ada_watch_location_expression. * breakpoint.c (watch_command_1): Update call to watch_location_expression. * c-lang.c (c_watch_location_expression): Rename to language_defn::watch_location_expression. (c_language_data): Delete la_watch_location_expression initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * c-lang.h (c_watch_location_expression): Delete declaration. * d-lang.c (d_language_data): Delete la_watch_location_expression initializer. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_language_data): Likewise. * language.c (language_defn::watch_location_expression): Member function implementation from c_watch_location_expression. (unknown_language_data): Delete la_watch_location_expression initializer. (auto_language_data): Likewise. * language.h (language_data): Delete la_watch_location_expression field. (language_defn::watch_location_expression): Declare new member function. * m2-lang.c (m2_language_data): Delete la_watch_location_expression initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_watch_location_expression): Rename to rust_language::watch_location_expression. (rust_language_data): Delete la_watch_location_expression initializer. (rust_language::watch_location_expression): New member function, implementation from rust_watch_location_expression.
2020-06-17gdb: Convert language la_collect_symbol_completion_matches field to a methodAndrew Burgess15-198/+210
This commit changes the language_data::la_collect_symbol_completion_matches function pointer member variable into a member function of language_defn. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_collect_symbol_completion_matches): Rename to ada_language::collect_symbol_completion_matches. (ada_language_data): Delete la_collect_symbol_completion_matches initializer. (ada_language::collect_symbol_completion_matches): New member function, implementation from ada_collect_symbol_completion_matches. * c-lang.c (c_language_data): Delete la_collect_symbol_completion_matches initializer. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * f-lang.c (f_collect_symbol_completion_matches): Rename to f_language::collect_symbol_completion_matches. (f_language_data): Delete la_collect_symbol_completion_matches initializer. (f_language::collect_symbol_completion_matches) New member function, implementation from f_collect_symbol_completion_matches. * go-lang.c (go_language_data): Delete la_collect_symbol_completion_matches initializer. * language.c (unknown_language_data): Likewise. (auto_language_data): Likewise. * language.h (language_data): Delete la_collect_symbol_completion_matches field. (language_defn::collect_symbol_completion_matches): New member function. * m2-lang.c (m2_language_data): Delete la_collect_symbol_completion_matches initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_language_data): Likewise. * symtab.c (default_collect_symbol_completion_matches): Delete. (collect_symbol_completion_matches): Update call to collect_symbol_completion_matches. (collect_symbol_completion_matches_type): Likewise. * symtab.h (default_collect_symbol_completion_matches): Delete declaration.