aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.h
AgeCommit message (Collapse)AuthorFilesLines
2021-01-01Update copyright year range in all GDB filesJoel Brobecker1-1/+1
This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
2020-12-04gdb: move displaced stepping logic to gdbarch, allow starting concurrent ↵Simon Marchi1-9/+29
displaced steps Today, GDB only allows a single displaced stepping operation to happen per inferior at a time. There is a single displaced stepping buffer per inferior, whose address is fixed (obtained with gdbarch_displaced_step_location), managed by infrun.c. In the case of the AMD ROCm target [1] (in the context of which this work has been done), it is typical to have thousands of threads (or waves, in SMT terminology) executing the same code, hitting the same breakpoint (possibly conditional) and needing to to displaced step it at the same time. The limitation of only one displaced step executing at a any given time becomes a real bottleneck. To fix this bottleneck, we want to make it possible for threads of a same inferior to execute multiple displaced steps in parallel. This patch builds the foundation for that. In essence, this patch moves the task of preparing a displaced step and cleaning up after to gdbarch functions. This allows using different schemes for allocating and managing displaced stepping buffers for different platforms. The gdbarch decides how to assign a buffer to a thread that needs to execute a displaced step. On the ROCm target, we are able to allocate one displaced stepping buffer per thread, so a thread will never have to wait to execute a displaced step. On Linux, the entry point of the executable if used as the displaced stepping buffer, since we assume that this code won't get used after startup. From what I saw (I checked with a binary generated against glibc and musl), on AMD64 we have enough space there to fit two displaced stepping buffers. A subsequent patch makes AMD64/Linux use two buffers. In addition to having multiple displaced stepping buffers, there is also the idea of sharing displaced stepping buffers between threads. Two threads doing displaced steps for the same PC could use the same buffer at the same time. Two threads stepping over the same instruction (same opcode) at two different PCs may also be able to share a displaced stepping buffer. This is an idea for future patches, but the architecture built by this patch is made to allow this. Now, the implementation details. The main part of this patch is moving the responsibility of preparing and finishing a displaced step to the gdbarch. Before this patch, preparing a displaced step is driven by the displaced_step_prepare_throw function. It does some calls to the gdbarch to do some low-level operations, but the high-level logic is there. The steps are roughly: - Ask the gdbarch for the displaced step buffer location - Save the existing bytes in the displaced step buffer - Ask the gdbarch to copy the instruction into the displaced step buffer - Set the pc of the thread to the beginning of the displaced step buffer Similarly, the "fixup" phase, executed after the instruction was successfully single-stepped, is driven by the infrun code (function displaced_step_finish). The steps are roughly: - Restore the original bytes in the displaced stepping buffer - Ask the gdbarch to fixup the instruction result (adjust the target's registers or memory to do as if the instruction had been executed in its original location) The displaced_step_inferior_state::step_thread field indicates which thread (if any) is currently using the displaced stepping buffer, so it is used by displaced_step_prepare_throw to check if the displaced stepping buffer is free to use or not. This patch defers the whole task of preparing and cleaning up after a displaced step to the gdbarch. Two new main gdbarch methods are added, with the following semantics: - gdbarch_displaced_step_prepare: Prepare for the given thread to execute a displaced step of the instruction located at its current PC. Upon return, everything should be ready for GDB to resume the thread (with either a single step or continue, as indicated by gdbarch_displaced_step_hw_singlestep) to make it displaced step the instruction. - gdbarch_displaced_step_finish: Called when the thread stopped after having started a displaced step. Verify if the instruction was executed, if so apply any fixup required to compensate for the fact that the instruction was executed at a different place than its original pc. Release any resources that were allocated for this displaced step. Upon return, everything should be ready for GDB to resume the thread in its "normal" code path. The displaced_step_prepare_throw function now pretty much just offloads to gdbarch_displaced_step_prepare and the displaced_step_finish function offloads to gdbarch_displaced_step_finish. The gdbarch_displaced_step_location method is now unnecessary, so is removed. Indeed, the core of GDB doesn't know how many displaced step buffers there are nor where they are. To keep the existing behavior for existing architectures, the logic that was previously implemented in infrun.c for preparing and finishing a displaced step is moved to displaced-stepping.c, to the displaced_step_buffer class. Architectures are modified to implement the new gdbarch methods using this class. The behavior is not expected to change. The other important change (which arises from the above) is that the core of GDB no longer prevents concurrent displaced steps. Before this patch, start_step_over walks the global step over chain and tries to initiate a step over (whether it is in-line or displaced). It follows these rules: - if an in-line step is in progress (in any inferior), don't start any other step over - if a displaced step is in progress for an inferior, don't start another displaced step for that inferior After starting a displaced step for a given inferior, it won't start another displaced step for that inferior. In the new code, start_step_over simply tries to initiate step overs for all the threads in the list. But because threads may be added back to the global list as it iterates the global list, trying to initiate step overs, start_step_over now starts by stealing the global queue into a local queue and iterates on the local queue. In the typical case, each thread will either: - have initiated a displaced step and be resumed - have been added back by the global step over queue by displaced_step_prepare_throw, because the gdbarch will have returned that there aren't enough resources (i.e. buffers) to initiate a displaced step for that thread Lastly, if start_step_over initiates an in-line step, it stops iterating, and moves back whatever remaining threads it had in its local step over queue to the global step over queue. Two other gdbarch methods are added, to handle some slightly annoying corner cases. They feel awkwardly specific to these cases, but I don't see any way around them: - gdbarch_displaced_step_copy_insn_closure_by_addr: in arm_pc_is_thumb, arm-tdep.c wants to get the closure for a given buffer address. - gdbarch_displaced_step_restore_all_in_ptid: when a process forks (at least on Linux), the address space is copied. If some displaced step buffers were in use at the time of the fork, we need to restore the original bytes in the child's address space. These two adjustments are also made in infrun.c: - prepare_for_detach: there may be multiple threads doing displaced steps when we detach, so wait until all of them are done - handle_inferior_event: when we handle a fork event for a given thread, it's possible that other threads are doing a displaced step at the same time. Make sure to restore the displaced step buffer contents in the child for them. [1] https://github.com/ROCm-Developer-Tools/ROCgdb gdb/ChangeLog: * displaced-stepping.h (struct displaced_step_copy_insn_closure): Adjust comments. (struct displaced_step_inferior_state) <step_thread, step_gdbarch, step_closure, step_original, step_copy, step_saved_copy>: Remove fields. (struct displaced_step_thread_state): New. (struct displaced_step_buffer): New. * displaced-stepping.c (displaced_step_buffer::prepare): New. (write_memory_ptid): Move from infrun.c. (displaced_step_instruction_executed_successfully): New, factored out of displaced_step_finish. (displaced_step_buffer::finish): New. (displaced_step_buffer::copy_insn_closure_by_addr): New. (displaced_step_buffer::restore_in_ptid): New. * gdbarch.sh (displaced_step_location): Remove. (displaced_step_prepare, displaced_step_finish, displaced_step_copy_insn_closure_by_addr, displaced_step_restore_all_in_ptid): New. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * gdbthread.h (class thread_info) <displaced_step_state>: New field. (thread_step_over_chain_remove): New declaration. (thread_step_over_chain_next): New declaration. (thread_step_over_chain_length): New declaration. * thread.c (thread_step_over_chain_remove): Make non-static. (thread_step_over_chain_next): New. (global_thread_step_over_chain_next): Use thread_step_over_chain_next. (thread_step_over_chain_length): New. (global_thread_step_over_chain_enqueue): Add debug print. (global_thread_step_over_chain_remove): Add debug print. * infrun.h (get_displaced_step_copy_insn_closure_by_addr): Remove. * infrun.c (get_displaced_stepping_state): New. (displaced_step_in_progress_any_inferior): Remove. (displaced_step_in_progress_thread): Adjust. (displaced_step_in_progress): Adjust. (displaced_step_in_progress_any_thread): New. (get_displaced_step_copy_insn_closure_by_addr): Remove. (gdbarch_supports_displaced_stepping): Use gdbarch_displaced_step_prepare_p. (displaced_step_reset): Change parameter from inferior to thread. (displaced_step_prepare_throw): Implement using gdbarch_displaced_step_prepare. (write_memory_ptid): Move to displaced-step.c. (displaced_step_restore): Remove. (displaced_step_finish): Implement using gdbarch_displaced_step_finish. (start_step_over): Allow starting more than one displaced step. (prepare_for_detach): Handle possibly multiple threads doing displaced steps. (handle_inferior_event): Handle possibility that fork event happens while another thread displaced steps. * linux-tdep.h (linux_displaced_step_prepare): New. (linux_displaced_step_finish): New. (linux_displaced_step_copy_insn_closure_by_addr): New. (linux_displaced_step_restore_all_in_ptid): New. (linux_init_abi): Add supports_displaced_step parameter. * linux-tdep.c (struct linux_info) <disp_step_buf>: New field. (linux_displaced_step_prepare): New. (linux_displaced_step_finish): New. (linux_displaced_step_copy_insn_closure_by_addr): New. (linux_displaced_step_restore_all_in_ptid): New. (linux_init_abi): Add supports_displaced_step parameter, register displaced step methods if true. (_initialize_linux_tdep): Register inferior_execd observer. * amd64-linux-tdep.c (amd64_linux_init_abi_common): Add supports_displaced_step parameter, adjust call to linux_init_abi. Remove call to set_gdbarch_displaced_step_location. (amd64_linux_init_abi): Adjust call to amd64_linux_init_abi_common. (amd64_x32_linux_init_abi): Likewise. * aarch64-linux-tdep.c (aarch64_linux_init_abi): Adjust call to linux_init_abi. Remove call to set_gdbarch_displaced_step_location. * arm-linux-tdep.c (arm_linux_init_abi): Likewise. * i386-linux-tdep.c (i386_linux_init_abi): Likewise. * alpha-linux-tdep.c (alpha_linux_init_abi): Adjust call to linux_init_abi. * arc-linux-tdep.c (arc_linux_init_osabi): Likewise. * bfin-linux-tdep.c (bfin_linux_init_abi): Likewise. * cris-linux-tdep.c (cris_linux_init_abi): Likewise. * csky-linux-tdep.c (csky_linux_init_abi): Likewise. * frv-linux-tdep.c (frv_linux_init_abi): Likewise. * hppa-linux-tdep.c (hppa_linux_init_abi): Likewise. * ia64-linux-tdep.c (ia64_linux_init_abi): Likewise. * m32r-linux-tdep.c (m32r_linux_init_abi): Likewise. * m68k-linux-tdep.c (m68k_linux_init_abi): Likewise. * microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise. * mips-linux-tdep.c (mips_linux_init_abi): Likewise. * mn10300-linux-tdep.c (am33_linux_init_osabi): Likewise. * nios2-linux-tdep.c (nios2_linux_init_abi): Likewise. * or1k-linux-tdep.c (or1k_linux_init_abi): Likewise. * riscv-linux-tdep.c (riscv_linux_init_abi): Likewise. * s390-linux-tdep.c (s390_linux_init_abi_any): Likewise. * sh-linux-tdep.c (sh_linux_init_abi): Likewise. * sparc-linux-tdep.c (sparc32_linux_init_abi): Likewise. * sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise. * tic6x-linux-tdep.c (tic6x_uclinux_init_abi): Likewise. * tilegx-linux-tdep.c (tilegx_linux_init_abi): Likewise. * xtensa-linux-tdep.c (xtensa_linux_init_abi): Likewise. * ppc-linux-tdep.c (ppc_linux_init_abi): Adjust call to linux_init_abi. Remove call to set_gdbarch_displaced_step_location. * arm-tdep.c (arm_pc_is_thumb): Call gdbarch_displaced_step_copy_insn_closure_by_addr instead of get_displaced_step_copy_insn_closure_by_addr. * rs6000-aix-tdep.c (rs6000_aix_init_osabi): Adjust calls to clear gdbarch methods. * rs6000-tdep.c (struct ppc_inferior_data): New structure. (get_ppc_per_inferior): New function. (ppc_displaced_step_prepare): New function. (ppc_displaced_step_finish): New function. (ppc_displaced_step_restore_all_in_ptid): New function. (rs6000_gdbarch_init): Register new gdbarch methods. * s390-tdep.c (s390_gdbarch_init): Don't call set_gdbarch_displaced_step_location, set new gdbarch methods. gdb/testsuite/ChangeLog: * gdb.arch/amd64-disp-step-avx.exp: Adjust pattern. * gdb.threads/forking-threads-plus-breakpoint.exp: Likewise. * gdb.threads/non-stop-fair-events.exp: Likewise. Change-Id: I387cd235a442d0620ec43608fd3dc0097fcbf8c8
2020-12-04gdb: move displaced stepping types to displaced-stepping.{h,c}Simon Marchi1-0/+1
Move displaced-stepping related stuff unchanged to displaced-stepping.h and displaced-stepping.c. This helps make the following patch a bit smaller and easier to read. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add displaced-stepping.c. * aarch64-tdep.h: Include displaced-stepping.h. * displaced-stepping.h (struct displaced_step_copy_insn_closure): Move here. (displaced_step_copy_insn_closure_up): Move here. (struct buf_displaced_step_copy_insn_closure): Move here. (struct displaced_step_inferior_state): Move here. (debug_displaced): Move here. (displaced_debug_printf_1): Move here. (displaced_debug_printf): Move here. * displaced-stepping.c: New file. * gdbarch.sh: Include displaced-stepping.h in gdbarch.h. * gdbarch.h: Re-generate. * inferior.h: Include displaced-stepping.h. * infrun.h (debug_displaced): Move to displaced-stepping.h. (displaced_debug_printf_1): Likewise. (displaced_debug_printf): Likewise. (struct displaced_step_copy_insn_closure): Likewise. (displaced_step_copy_insn_closure_up): Likewise. (struct buf_displaced_step_copy_insn_closure): Likewise. (struct displaced_step_inferior_state): Likewise. * infrun.c (show_debug_displaced): Move to displaced-stepping.c. (displaced_debug_printf_1): Likewise. (displaced_step_copy_insn_closure::~displaced_step_copy_insn_closure): Likewise. (_initialize_infrun): Don't register "set/show debug displaced". Change-Id: I29935f5959b80425370630a45148fc06cd4227ca
2020-12-04gdb: rename displaced_step_closure to displaced_step_copy_insn_closureSimon Marchi1-4/+4
Since we're going to introduce other "displaced step" functions and another kind of displaced step closure, make it clear that this is the return type of the gdbarch_displaced_step_copy_insn function. gdb/ChangeLog: * infrun.h (get_displaced_step_closure_by_addr): Rename to... (get_displaced_step_copy_insn_closure_by_addr): ... this. Update all users. (displaced_step_closure): Rename to... (displaced_step_copy_insn_closure): ... this. Update all users. (displaced_step_closure_up): Rename to... (displaced_step_copy_insn_closure_up). ... this. Update all users. (buf_displaced_step_closure): Rename to... (buf_displaced_step_copy_insn_closure): ... this. Update all users. * infrun.c (get_displaced_step_closure_by_addr): Rename to... (get_displaced_step_copy_insn_closure_by_addr): ... this. Update all users. * aarch64-tdep.c (aarch64_displaced_step_closure): Rename to... (aarch64_displaced_step_copy_insn_closure): ... this. Update all users. * amd64-tdep.c (amd64_displaced_step_closure): Rename to... (amd64_displaced_step_copy_insn_closure): ... this. Update all users. * arm-tdep.h (arm_displaced_step_closure): Rename to... (arm_displaced_step_copy_insn_closure): ... this. Update all users. * i386-tdep.h (i386_displaced_step_closure): Rename to... (i386_displaced_step_copy_insn_closure): ... this. Update all users. * rs6000-tdep.c (ppc_displaced_step_closure): Rename to... (ppc_displaced_step_copy_insn_closure): ... this. Update all users. * s390-tdep.c (s390_displaced_step_closure): Rename to... (s390_displaced_step_copy_insn_closure): ... this. Update all users. * gdbarch.h: Re-generate. * gdbarch.c: Re-generate. Change-Id: I11f56dbcd4c3532fb195a08ba93bccf1d12a03c8
2020-11-19gdb: remove `other` parameter in read_core_file_mappings parameterSimon Marchi1-2/+2
The `void *other` parameter in read_core_file_mappings' loop_cb parameter is never used, remove it. gdb/ChangeLog: * gdbarch.sh (read_core_file_mappings): Remove `other` parameter in `loop_cb` parameter. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * arch-utils.c (default_read_core_file_mappings): Remove `other` parameter. * arch-utils.h (default_read_core_file_mappings): Likewise. * corelow.c (core_target::build_file_mappings): Likewise. * linux-tdep.c (linux_read_core_file_mappings): Likewise. (linux_core_info_proc_mappings): Likewise. Change-Id: I6f408b4962b61b8a603642a844772b3026625523
2020-11-02gdb, gdbserver, gdbsupport: fix leading space vs tabs issuesSimon Marchi1-2/+2
Many spots incorrectly use only spaces for indentation (for example, there are a lot of spots in ada-lang.c). I've always found it awkward when I needed to edit one of these spots: do I keep the original wrong indentation, or do I fix it? What if the lines around it are also wrong, do I fix them too? I probably don't want to fix them in the same patch, to avoid adding noise to my patch. So I propose to fix as much as possible once and for all (hopefully). One typical counter argument for this is that it makes code archeology more difficult, because git-blame will show this commit as the last change for these lines. My counter counter argument is: when git-blaming, you often need to do "blame the file at the parent commit" anyway, to go past some other refactor that touched the line you are interested in, but is not the change you are looking for. So you already need a somewhat efficient way to do this. Using some interactive tool, rather than plain git-blame, makes this trivial. For example, I use "tig blame <file>", where going back past the commit that changed the currently selected line is one keystroke. It looks like Magit in Emacs does it too (though I've never used it). Web viewers of Github and Gitlab do it too. My point is that it won't really make archeology more difficult. The other typical counter argument is that it will cause conflicts with existing patches. That's true... but it's a one time cost, and those are not conflicts that are difficult to resolve. I have also tried "git rebase --ignore-whitespace", it seems to work well. Although that will re-introduce the faulty indentation, so one needs to take care of fixing the indentation in the patch after that (which is easy). gdb/ChangeLog: * aarch64-linux-tdep.c: Fix indentation. * aarch64-ravenscar-thread.c: Fix indentation. * aarch64-tdep.c: Fix indentation. * aarch64-tdep.h: Fix indentation. * ada-lang.c: Fix indentation. * ada-lang.h: Fix indentation. * ada-tasks.c: Fix indentation. * ada-typeprint.c: Fix indentation. * ada-valprint.c: Fix indentation. * ada-varobj.c: Fix indentation. * addrmap.c: Fix indentation. * addrmap.h: Fix indentation. * agent.c: Fix indentation. * aix-thread.c: Fix indentation. * alpha-bsd-nat.c: Fix indentation. * alpha-linux-tdep.c: Fix indentation. * alpha-mdebug-tdep.c: Fix indentation. * alpha-nbsd-tdep.c: Fix indentation. * alpha-obsd-tdep.c: Fix indentation. * alpha-tdep.c: Fix indentation. * amd64-bsd-nat.c: Fix indentation. * amd64-darwin-tdep.c: Fix indentation. * amd64-linux-nat.c: Fix indentation. * amd64-linux-tdep.c: Fix indentation. * amd64-nat.c: Fix indentation. * amd64-obsd-tdep.c: Fix indentation. * amd64-tdep.c: Fix indentation. * amd64-windows-tdep.c: Fix indentation. * annotate.c: Fix indentation. * arc-tdep.c: Fix indentation. * arch-utils.c: Fix indentation. * arch/arm-get-next-pcs.c: Fix indentation. * arch/arm.c: Fix indentation. * arm-linux-nat.c: Fix indentation. * arm-linux-tdep.c: Fix indentation. * arm-nbsd-tdep.c: Fix indentation. * arm-pikeos-tdep.c: Fix indentation. * arm-tdep.c: Fix indentation. * arm-tdep.h: Fix indentation. * arm-wince-tdep.c: Fix indentation. * auto-load.c: Fix indentation. * auxv.c: Fix indentation. * avr-tdep.c: Fix indentation. * ax-gdb.c: Fix indentation. * ax-general.c: Fix indentation. * bfin-linux-tdep.c: Fix indentation. * block.c: Fix indentation. * block.h: Fix indentation. * blockframe.c: Fix indentation. * bpf-tdep.c: Fix indentation. * break-catch-sig.c: Fix indentation. * break-catch-syscall.c: Fix indentation. * break-catch-throw.c: Fix indentation. * breakpoint.c: Fix indentation. * breakpoint.h: Fix indentation. * bsd-uthread.c: Fix indentation. * btrace.c: Fix indentation. * build-id.c: Fix indentation. * buildsym-legacy.h: Fix indentation. * buildsym.c: Fix indentation. * c-typeprint.c: Fix indentation. * c-valprint.c: Fix indentation. * c-varobj.c: Fix indentation. * charset.c: Fix indentation. * cli/cli-cmds.c: Fix indentation. * cli/cli-decode.c: Fix indentation. * cli/cli-decode.h: Fix indentation. * cli/cli-script.c: Fix indentation. * cli/cli-setshow.c: Fix indentation. * coff-pe-read.c: Fix indentation. * coffread.c: Fix indentation. * compile/compile-cplus-types.c: Fix indentation. * compile/compile-object-load.c: Fix indentation. * compile/compile-object-run.c: Fix indentation. * completer.c: Fix indentation. * corefile.c: Fix indentation. * corelow.c: Fix indentation. * cp-abi.h: Fix indentation. * cp-namespace.c: Fix indentation. * cp-support.c: Fix indentation. * cp-valprint.c: Fix indentation. * cris-linux-tdep.c: Fix indentation. * cris-tdep.c: Fix indentation. * darwin-nat-info.c: Fix indentation. * darwin-nat.c: Fix indentation. * darwin-nat.h: Fix indentation. * dbxread.c: Fix indentation. * dcache.c: Fix indentation. * disasm.c: Fix indentation. * dtrace-probe.c: Fix indentation. * dwarf2/abbrev.c: Fix indentation. * dwarf2/attribute.c: Fix indentation. * dwarf2/expr.c: Fix indentation. * dwarf2/frame.c: Fix indentation. * dwarf2/index-cache.c: Fix indentation. * dwarf2/index-write.c: Fix indentation. * dwarf2/line-header.c: Fix indentation. * dwarf2/loc.c: Fix indentation. * dwarf2/macro.c: Fix indentation. * dwarf2/read.c: Fix indentation. * dwarf2/read.h: Fix indentation. * elfread.c: Fix indentation. * eval.c: Fix indentation. * event-top.c: Fix indentation. * exec.c: Fix indentation. * exec.h: Fix indentation. * expprint.c: Fix indentation. * f-lang.c: Fix indentation. * f-typeprint.c: Fix indentation. * f-valprint.c: Fix indentation. * fbsd-nat.c: Fix indentation. * fbsd-tdep.c: Fix indentation. * findvar.c: Fix indentation. * fork-child.c: Fix indentation. * frame-unwind.c: Fix indentation. * frame-unwind.h: Fix indentation. * frame.c: Fix indentation. * frv-linux-tdep.c: Fix indentation. * frv-tdep.c: Fix indentation. * frv-tdep.h: Fix indentation. * ft32-tdep.c: Fix indentation. * gcore.c: Fix indentation. * gdb_bfd.c: Fix indentation. * gdbarch.sh: Fix indentation. * gdbarch.c: Re-generate * gdbarch.h: Re-generate. * gdbcore.h: Fix indentation. * gdbthread.h: Fix indentation. * gdbtypes.c: Fix indentation. * gdbtypes.h: Fix indentation. * glibc-tdep.c: Fix indentation. * gnu-nat.c: Fix indentation. * gnu-nat.h: Fix indentation. * gnu-v2-abi.c: Fix indentation. * gnu-v3-abi.c: Fix indentation. * go32-nat.c: Fix indentation. * guile/guile-internal.h: Fix indentation. * guile/scm-cmd.c: Fix indentation. * guile/scm-frame.c: Fix indentation. * guile/scm-iterator.c: Fix indentation. * guile/scm-math.c: Fix indentation. * guile/scm-ports.c: Fix indentation. * guile/scm-pretty-print.c: Fix indentation. * guile/scm-value.c: Fix indentation. * h8300-tdep.c: Fix indentation. * hppa-linux-nat.c: Fix indentation. * hppa-linux-tdep.c: Fix indentation. * hppa-nbsd-nat.c: Fix indentation. * hppa-nbsd-tdep.c: Fix indentation. * hppa-obsd-nat.c: Fix indentation. * hppa-tdep.c: Fix indentation. * hppa-tdep.h: Fix indentation. * i386-bsd-nat.c: Fix indentation. * i386-darwin-nat.c: Fix indentation. * i386-darwin-tdep.c: Fix indentation. * i386-dicos-tdep.c: Fix indentation. * i386-gnu-nat.c: Fix indentation. * i386-linux-nat.c: Fix indentation. * i386-linux-tdep.c: Fix indentation. * i386-nto-tdep.c: Fix indentation. * i386-obsd-tdep.c: Fix indentation. * i386-sol2-nat.c: Fix indentation. * i386-tdep.c: Fix indentation. * i386-tdep.h: Fix indentation. * i386-windows-tdep.c: Fix indentation. * i387-tdep.c: Fix indentation. * i387-tdep.h: Fix indentation. * ia64-libunwind-tdep.c: Fix indentation. * ia64-libunwind-tdep.h: Fix indentation. * ia64-linux-nat.c: Fix indentation. * ia64-linux-tdep.c: Fix indentation. * ia64-tdep.c: Fix indentation. * ia64-tdep.h: Fix indentation. * ia64-vms-tdep.c: Fix indentation. * infcall.c: Fix indentation. * infcmd.c: Fix indentation. * inferior.c: Fix indentation. * infrun.c: Fix indentation. * iq2000-tdep.c: Fix indentation. * language.c: Fix indentation. * linespec.c: Fix indentation. * linux-fork.c: Fix indentation. * linux-nat.c: Fix indentation. * linux-tdep.c: Fix indentation. * linux-thread-db.c: Fix indentation. * lm32-tdep.c: Fix indentation. * m2-lang.c: Fix indentation. * m2-typeprint.c: Fix indentation. * m2-valprint.c: Fix indentation. * m32c-tdep.c: Fix indentation. * m32r-linux-tdep.c: Fix indentation. * m32r-tdep.c: Fix indentation. * m68hc11-tdep.c: Fix indentation. * m68k-bsd-nat.c: Fix indentation. * m68k-linux-nat.c: Fix indentation. * m68k-linux-tdep.c: Fix indentation. * m68k-tdep.c: Fix indentation. * machoread.c: Fix indentation. * macrocmd.c: Fix indentation. * macroexp.c: Fix indentation. * macroscope.c: Fix indentation. * macrotab.c: Fix indentation. * macrotab.h: Fix indentation. * main.c: Fix indentation. * mdebugread.c: Fix indentation. * mep-tdep.c: Fix indentation. * mi/mi-cmd-catch.c: Fix indentation. * mi/mi-cmd-disas.c: Fix indentation. * mi/mi-cmd-env.c: Fix indentation. * mi/mi-cmd-stack.c: Fix indentation. * mi/mi-cmd-var.c: Fix indentation. * mi/mi-cmds.c: Fix indentation. * mi/mi-main.c: Fix indentation. * mi/mi-parse.c: Fix indentation. * microblaze-tdep.c: Fix indentation. * minidebug.c: Fix indentation. * minsyms.c: Fix indentation. * mips-linux-nat.c: Fix indentation. * mips-linux-tdep.c: Fix indentation. * mips-nbsd-tdep.c: Fix indentation. * mips-tdep.c: Fix indentation. * mn10300-linux-tdep.c: Fix indentation. * mn10300-tdep.c: Fix indentation. * moxie-tdep.c: Fix indentation. * msp430-tdep.c: Fix indentation. * namespace.h: Fix indentation. * nat/fork-inferior.c: Fix indentation. * nat/gdb_ptrace.h: Fix indentation. * nat/linux-namespaces.c: Fix indentation. * nat/linux-osdata.c: Fix indentation. * nat/netbsd-nat.c: Fix indentation. * nat/x86-dregs.c: Fix indentation. * nbsd-nat.c: Fix indentation. * nbsd-tdep.c: Fix indentation. * nios2-linux-tdep.c: Fix indentation. * nios2-tdep.c: Fix indentation. * nto-procfs.c: Fix indentation. * nto-tdep.c: Fix indentation. * objfiles.c: Fix indentation. * objfiles.h: Fix indentation. * opencl-lang.c: Fix indentation. * or1k-tdep.c: Fix indentation. * osabi.c: Fix indentation. * osabi.h: Fix indentation. * osdata.c: Fix indentation. * p-lang.c: Fix indentation. * p-typeprint.c: Fix indentation. * p-valprint.c: Fix indentation. * parse.c: Fix indentation. * ppc-linux-nat.c: Fix indentation. * ppc-linux-tdep.c: Fix indentation. * ppc-nbsd-nat.c: Fix indentation. * ppc-nbsd-tdep.c: Fix indentation. * ppc-obsd-nat.c: Fix indentation. * ppc-ravenscar-thread.c: Fix indentation. * ppc-sysv-tdep.c: Fix indentation. * ppc64-tdep.c: Fix indentation. * printcmd.c: Fix indentation. * proc-api.c: Fix indentation. * producer.c: Fix indentation. * producer.h: Fix indentation. * prologue-value.c: Fix indentation. * prologue-value.h: Fix indentation. * psymtab.c: Fix indentation. * python/py-arch.c: Fix indentation. * python/py-bpevent.c: Fix indentation. * python/py-event.c: Fix indentation. * python/py-event.h: Fix indentation. * python/py-finishbreakpoint.c: Fix indentation. * python/py-frame.c: Fix indentation. * python/py-framefilter.c: Fix indentation. * python/py-inferior.c: Fix indentation. * python/py-infthread.c: Fix indentation. * python/py-objfile.c: Fix indentation. * python/py-prettyprint.c: Fix indentation. * python/py-registers.c: Fix indentation. * python/py-signalevent.c: Fix indentation. * python/py-stopevent.c: Fix indentation. * python/py-stopevent.h: Fix indentation. * python/py-threadevent.c: Fix indentation. * python/py-tui.c: Fix indentation. * python/py-unwind.c: Fix indentation. * python/py-value.c: Fix indentation. * python/py-xmethods.c: Fix indentation. * python/python-internal.h: Fix indentation. * python/python.c: Fix indentation. * ravenscar-thread.c: Fix indentation. * record-btrace.c: Fix indentation. * record-full.c: Fix indentation. * record.c: Fix indentation. * reggroups.c: Fix indentation. * regset.h: Fix indentation. * remote-fileio.c: Fix indentation. * remote.c: Fix indentation. * reverse.c: Fix indentation. * riscv-linux-tdep.c: Fix indentation. * riscv-ravenscar-thread.c: Fix indentation. * riscv-tdep.c: Fix indentation. * rl78-tdep.c: Fix indentation. * rs6000-aix-tdep.c: Fix indentation. * rs6000-lynx178-tdep.c: Fix indentation. * rs6000-nat.c: Fix indentation. * rs6000-tdep.c: Fix indentation. * rust-lang.c: Fix indentation. * rx-tdep.c: Fix indentation. * s12z-tdep.c: Fix indentation. * s390-linux-tdep.c: Fix indentation. * score-tdep.c: Fix indentation. * ser-base.c: Fix indentation. * ser-mingw.c: Fix indentation. * ser-uds.c: Fix indentation. * ser-unix.c: Fix indentation. * serial.c: Fix indentation. * sh-linux-tdep.c: Fix indentation. * sh-nbsd-tdep.c: Fix indentation. * sh-tdep.c: Fix indentation. * skip.c: Fix indentation. * sol-thread.c: Fix indentation. * solib-aix.c: Fix indentation. * solib-darwin.c: Fix indentation. * solib-frv.c: Fix indentation. * solib-svr4.c: Fix indentation. * solib.c: Fix indentation. * source.c: Fix indentation. * sparc-linux-tdep.c: Fix indentation. * sparc-nbsd-tdep.c: Fix indentation. * sparc-obsd-tdep.c: Fix indentation. * sparc-ravenscar-thread.c: Fix indentation. * sparc-tdep.c: Fix indentation. * sparc64-linux-tdep.c: Fix indentation. * sparc64-nbsd-tdep.c: Fix indentation. * sparc64-obsd-tdep.c: Fix indentation. * sparc64-tdep.c: Fix indentation. * stabsread.c: Fix indentation. * stack.c: Fix indentation. * stap-probe.c: Fix indentation. * stubs/ia64vms-stub.c: Fix indentation. * stubs/m32r-stub.c: Fix indentation. * stubs/m68k-stub.c: Fix indentation. * stubs/sh-stub.c: Fix indentation. * stubs/sparc-stub.c: Fix indentation. * symfile-mem.c: Fix indentation. * symfile.c: Fix indentation. * symfile.h: Fix indentation. * symmisc.c: Fix indentation. * symtab.c: Fix indentation. * symtab.h: Fix indentation. * target-float.c: Fix indentation. * target.c: Fix indentation. * target.h: Fix indentation. * tic6x-tdep.c: Fix indentation. * tilegx-linux-tdep.c: Fix indentation. * tilegx-tdep.c: Fix indentation. * top.c: Fix indentation. * tracefile-tfile.c: Fix indentation. * tracepoint.c: Fix indentation. * tui/tui-disasm.c: Fix indentation. * tui/tui-io.c: Fix indentation. * tui/tui-regs.c: Fix indentation. * tui/tui-stack.c: Fix indentation. * tui/tui-win.c: Fix indentation. * tui/tui-winsource.c: Fix indentation. * tui/tui.c: Fix indentation. * typeprint.c: Fix indentation. * ui-out.h: Fix indentation. * unittests/copy_bitwise-selftests.c: Fix indentation. * unittests/memory-map-selftests.c: Fix indentation. * utils.c: Fix indentation. * v850-tdep.c: Fix indentation. * valarith.c: Fix indentation. * valops.c: Fix indentation. * valprint.c: Fix indentation. * valprint.h: Fix indentation. * value.c: Fix indentation. * value.h: Fix indentation. * varobj.c: Fix indentation. * vax-tdep.c: Fix indentation. * windows-nat.c: Fix indentation. * windows-tdep.c: Fix indentation. * xcoffread.c: Fix indentation. * xml-syscall.c: Fix indentation. * xml-tdesc.c: Fix indentation. * xstormy16-tdep.c: Fix indentation. * xtensa-config.c: Fix indentation. * xtensa-linux-nat.c: Fix indentation. * xtensa-linux-tdep.c: Fix indentation. * xtensa-tdep.c: Fix indentation. gdbserver/ChangeLog: * ax.cc: Fix indentation. * dll.cc: Fix indentation. * inferiors.h: Fix indentation. * linux-low.cc: Fix indentation. * linux-nios2-low.cc: Fix indentation. * linux-ppc-ipa.cc: Fix indentation. * linux-ppc-low.cc: Fix indentation. * linux-x86-low.cc: Fix indentation. * linux-xtensa-low.cc: Fix indentation. * regcache.cc: Fix indentation. * server.cc: Fix indentation. * tracepoint.cc: Fix indentation. gdbsupport/ChangeLog: * common-exceptions.h: Fix indentation. * event-loop.cc: Fix indentation. * fileio.cc: Fix indentation. * filestuff.cc: Fix indentation. * gdb-dlfcn.cc: Fix indentation. * gdb_string_view.h: Fix indentation. * job-control.cc: Fix indentation. * signals.cc: Fix indentation. Change-Id: I4bad7ae6be0fbe14168b8ebafb98ffe14964a695
2020-10-29gdb: fix documentation of gdbarch_displaced_step_hw_singlestepSimon Marchi1-8/+7
The last commit missed updating the doc of gdbarch_displaced_step_hw_singlestep to avoid mentioning the removed parameter, this one fixes it. gdb/ChangeLog: * gdbarch.sh (displaced_step_hw_singlestep): Adjust documentation. * gdbarch.h: Re-generate. Change-Id: I33675d9a6c253443eee707e8285d16615ce20aaa
2020-10-29gdb: remove parameter of gdbarch_displaced_step_hw_singlestepSimon Marchi1-2/+2
I noticed that the closure parameter of gdbarch_displaced_step_hw_singlestep is never used by any implementation of the method, so this patch removes it. gdb/ChangeLog: * gdbarch.sh (displaced_step_hw_singlestep): Remove closure parameter. * aarch64-tdep.c (aarch64_displaced_step_hw_singlestep): Likewise. * aarch64-tdep.h (aarch64_displaced_step_hw_singlestep): Likewise. * arch-utils.c (default_displaced_step_hw_singlestep): Likewise. * arch-utils.h (default_displaced_step_hw_singlestep): Likewise. * rs6000-tdep.c (ppc_displaced_step_hw_singlestep): Likewise. * s390-tdep.c (s390_displaced_step_hw_singlestep): Likewise. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * infrun.c (resume_1): Adjust. Change-Id: I7354f0b22afc2692ebff0cd700a462db8f389fc1
2020-10-21gdb: make gdbarch_make_corefile_notes return a unique ptrSimon Marchi1-2/+2
This patch starts by making the gdbarch_make_corefile_notes function return a gdb::unique_xmalloc_ptr<char> and takes care of the fallouts, mostly in linux-tdep.c and fbsd-tdep.c. The difficulty in these files is that they use the BFD API for writing core files, where you pass in a pointer to a malloc-ed buffer (or NULL in the beginning), it re-allocs it if needed, and returns you the possibly updated pointer. I therefore used this pattern everywhere: note_data.reset (elfcore_write_note (obfd, note_data.release (), ...) This hands over the ownership of note_data to the BFD function for the duration of the call, and then puts its back in note_data right after the call. gdb/ChangeLog: * gdbarch.sh (make_corefile_notes): Return unique pointer. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * gcore.c (write_gcore_file_1): Adjust. * fbsd-tdep.c (struct fbsd_collect_regset_section_cb_data): Add constructor. <note_data>: Change type to unique pointer. <abort_iteration>: Change type to bool. (fbsd_collect_regset_section_cb): Adjust to unique pointer. (fbsd_collect_thread_registers): Return void, adjust. (struct fbsd_corefile_thread_data): Add construtor. <note_data>: Change type to unique pointer. (fbsd_corefile_thread): Adjust. (fbsd_make_corefile_notes): Return unique pointer, adjust. * linux-tdep.c (linux_make_mappings_corefile_notes): Change type to unique pointer, adjust. (struct linux_collect_regset_section_cb_data): Add constructor. <note_data>: Change type to unique pointer. <abort_iteration>: Change type to bool. (linux_collect_thread_registers): Return void, adjust. (struct linux_corefile_thread_data): Add constructor. <note_data>: Change type to unique pointer. (linux_corefile_thread): Adjust. (linux_make_corefile_notes): Return unique pointer, adjust. Change-Id: I1e03476bb47b87c6acb3e12204d193f38cc4e02b
2020-10-20gdb: make gdbarch_displaced_step_hw_singlestep return boolSimon Marchi1-2/+2
Replace the int-used-as-a-bool with a bool. gdb/ChangeLog: * gdbarch.sh (displaced_step_hw_singlestep): Return bool. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * aarch64-tdep.c (aarch64_displaced_step_hw_singlestep): Return bool. * aarch64-tdep.h (aarch64_displaced_step_hw_singlestep): Likewise. * arch-utils.h (default_displaced_step_hw_singlestep): Likewise. * arch-utils.c (default_displaced_step_hw_singlestep): Likewise. * rs6000-tdep.c (ppc_displaced_step_hw_singlestep): Likewise. * s390-tdep.c (s390_displaced_step_hw_singlestep): Likewise. Change-Id: I76a78366dc5c0afb03f8f4bddf9f4e8d68fe3114
2020-10-20gdb: make gdbarch predicates return boolSimon Marchi1-61/+61
gdbarch predicates (functions suffixed _p to check whether a gdbarch implements a given method) currently return int. Make them return bool. There is no expected behavior change. gdb/ChangeLog: * gdbarch.sh: Make generated predicates return bool. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. Change-Id: Ie7ebc1acae62df83da9085ba69327fca551c5a30
2020-09-14Use type_instance_flags more throughoutPedro Alves1-8/+8
A later patch in this series will rewrite enum_flags fixing some API holes. That would cause build failures around code using type_instance_flags. Or rather, that should be using it, but wasn't. This patch fixes it by using type_instance_flags throughout instead of plain integers. Note that we can't make the seemingly obvious change to struct type::instance_flags: - unsigned instance_flags : 9; + ENUM_BITFIELD (type_instance_flag_value) instance_flags : 9; Because G++ complains then that 9 bits isn't sufficient for holding all values of type_instance_flag_value. So the patch adds an type::instance_flags() method, which takes care of casting appropriately, and adds a separate type::set_instance_flags method, following the pattern of the ongoing TYPE_XXX macro elimination. This converts uses of TYPE_INSTANCE_FLAGS to type::instance_flags() in the places where the code was already being touched, but there are still many references to the TYPE_INSTANCE_FLAGS macro left behind. Those could/should be fully replaced at some point. gdb/ChangeLog: * avr-tdep.c (avr_address_class_type_flags): Return type_instance_flags. (avr_address_class_type_flags_to_name): Take a type_instance_flags. (avr_address_class_name_to_type_flags): Return bool and take a type_instance_flags. * d-lang.c (build_d_types): Use type::set_instance_flags. * ft32-tdep.c (ft32_address_class_type_flags): Return type_instance_flags. (ft32_address_class_type_flags_to_name): Take a type_instance_flags. (ft32_address_class_name_to_type_flags): Return bool and take a type_instance_flags. (ft32_gdbarch_init): Use type::set_instance_flags. * eval.c (fake_method::fake_method): Use type::set_instance_flags. * gdbarch.h, gdbarch.c: Regenerate. * gdbarch.sh (address_class_type_flags): Use type_instance_flags. (address_class_name_to_type_flags): Use type_instance_flags and bool. * gdbtypes.c (address_space_name_to_int) (address_space_int_to_name, make_qualified_type): Use type_instance_flags. (make_qualified_type): Use type_instance_flags and type::set_instance_flags. (make_type_with_address_space, make_cv_type, make_vector_type) (check_typedef): Use type_instance_flags. (recursive_dump_type): Cast type_instance_flags to unsigned for printing. (copy_type_recursive): Use type::set_instance_flags. (gdbtypes_post_init): Use type::set_instance_flags. * gdbtypes.h (struct type) <instance_flags>: Rename to ... <m_instance_flags>: ... this. <instance_flags, set_instance_flags>: New methods. (TYPE_INSTANCE_FLAGS): Use the instance_flags method. (SET_TYPE_INSTANCE_FLAGS): New. (address_space_name_to_int, address_space_int_to_name) (make_type_with_address_space): Pass flags using type_instance_flags instead of int. * stabsread.c (cleanup_undefined_types_noname): Use type::set_instance_flags. * s390-tdep.c (s390_address_class_type_flags): Return type_instance_flags. (s390_address_class_type_flags_to_name): Take a type_instance_flags. (s390_address_class_name_to_type_flags): Return bool and take a type_instance_flags. * type-stack.c (type_stack::follow_types): Use type_instance_flags. * dwarf2/read.c (read_tag_pointer_type): Use type_instance_flags.
2020-09-11Add bfloat16 support for AVX512 register view.Felix Willgerodt1-1/+7
This adds support for the bfloat16 datatype, which can be seen as a short version of FP32, skipping the least significant 16 bits of the mantissa. Since the datatype is currently only supported by the AVX512 registers, the printing of bfloat16 values is only supported for xmm, ymm and zmm registers. gdb/ChangeLog: 2020-09-11 Moritz Riesterer <moritz.riesterer@intel.com> Felix Willgerodt <Felix.Willgerodt@intel.com> * gdbarch.sh: Added bfloat16 type. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbtypes.c (floatformats_bfloat16): New struct. (gdbtypes_post_init): Add builtin_bfloat16. * gdbtypes.h (struct builtin_type) <builtin_bfloat16>: New member. (floatformats_bfloat16): New struct. * i386-tdep.c (i386_zmm_type): Add field "v32_bfloat16" (i386_ymm_type): Add field "v16_bfloat16" (i386_gdbarch_init): Add set_gdbarch_bfloat16_format. * target-descriptions.c (make_gdb_type): Add case TDESC_TYPE_BFLOAT16. * gdbsupport/tdesc.cc (tdesc_predefined_types): New member bfloat16. * gdbsupport/tdesc.h (tdesc_type_kind): New member TDESC_TYPE_BFLOAT16. * features/i386/64bit-avx512.xml: Add bfloat16 type. * features/i386/64bit-avx512.c: Regenerated. * features/i386/64bit-sse.xml: Add bfloat16 type. * features/i386/64bit-sse.c: Regenerated. gdb/testsuite/ChangeLog: 2020-09-11 Moritz Riesterer <moritz.riesterer@intel.com> Felix Willgerodt <Felix.Willgerodt@intel.com> * x86-avx512bf16.c: New file. * x86-avx512bf16.exp: Likewise. * lib/gdb.exp (skip_avx512bf16_tests): New function.
2020-07-22Add new gdbarch method, read_core_file_mappingsKevin Buettner1-0/+6
The new gdbarch method, read_core_file_mappings, will be used for reading file-backed mappings from a core file. It'll be used for two purposes: 1) to construct a table of file-backed mappings in corelow.c, and 2) for display of core file mappings. For Linux, I tried a different approach in which knowledge of the note format was placed directly in corelow.c. This seemed okay at first; it was only one note format and the note format was fairly simple. After looking at FreeBSD's note/mapping reading code, I concluded that it's best to leave architecture specific details for decoding the note in (architecture specific) tdep files. With regard to display of core file mappings, I experimented with placing the mappings display code in corelow.c. It has access to the file-backed mappings which were read in when the core file was loaded. And, better, still common code could be used for all architectures. But, again, the FreeBSD mapping code convinced me that this was not the best approach since it has even more mapping info than Linux. Display code which would work well for Linux will leave out mappings as well as protection info for mappings. So, for these reasons, I'm introducing a new gdbarch method for reading core file mappings. gdb/ChangeLog: * arch-utils.c (default_read_core_file_mappings): New function. * arch-utils.c (default_read_core_file_mappings): Declare. * gdbarch.sh (read_core_file_mappings): New gdbarch method. * gdbarch.h, gdbarch.c: Regenerate.
2020-07-21Retire the now-unused gdbarch handle_segmentation_fault hook.John Baldwin1-11/+0
* gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (handle_segmentation_fault): Remove method. * infrun.c (handle_segmentation_fault): Remove. (print_signal_received_reason): Remove call to handle_segmentation_fault.
2020-07-21Add a new gdbarch hook to report additional signal information.John Baldwin1-0/+10
This is a more general version of the existing handle_segmentation_fault hook that is able to report information for an arbitrary signal, not just SIGSEGV. gdb/ChangeLog: * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (report_signal_info): New method. * infrun.c (print_signal_received_reason): Invoke gdbarch report_signal_info hook if present.
2020-07-06gdb: Remove deprecated_set_gdbarch_dataAndrew Burgess1-3/+0
There are currently two remaining uses of deprecated_set_gdbarch_data, both of which are needed because during gdbarch initialisation we call gdbarch_data for a data field that is registered using: gdbarch_data_register_post_init (....) However, in both of these cases, the only thing that the call back needs from the gdbarch struct is its obstack. Given this there is nothing stopping us changing the post-init hooks into pre-init hooks. The pre-init hooks don't get passed the full gdbarch, they only get passed its obstack. The IA64 change is completely untested. The user-regs change has been tested a little by locally adding some user-regs to the x86-64 target, and also by running the RISC-V tests, which do use user-regs. gdb/ChangeLog: * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (deprecated_set_gdbarch_data): Delete. (gdbarch_data): Use internal_error for the case where deprecated_set_gdbarch_data was originally needed. * ia64-libunwind-tdep.c (libunwind_descr_init): Update parameters, and use passed in obstack. (libunwind_frame_set_descr): Should no longer get back NULL from gdbarch_data. (_initialize_libunwind_frame): Register as a pre-init gdbarch data type. * user-regs.c (user_regs_init): Update parameters, and use passed in obstack. (user_reg_add): Should no longer get back NULL from gdbarch_data. (_initialize_user_regs): Register as a pre-init gdbarch data type.
2020-06-29gdb: fix documentation of gdbarch_displaced_step_copy_insnSimon Marchi1-3/+1
I spotted something that looks wrong in the doc of gdbarch_displaced_step_copy_insn. It says that if the function returns NULL, it means that it has emulated the behavior of the instruction and written the result to REGS. However, it says below that the function may return NULL to indicate that the instruction can't be single-stepped out-of-line, in which case the core steps the instruction in-line. The two are contradictory. The right one is the latter, if the function returns NULL, the core falls back to in-line stepping. I checked all the implementations of this function and they all agree with this. gdb/ChangeLog: * gdbarch.sh (displaced_step_copy_insn): Update doc. * gdbarch.h: Re-generate. Change-Id: I98163cdd38970cde4c77680e249b10f5d2d5bf9b
2020-06-25Remove obsolete gdbarch_static_transform_nameRainer Orth1-8/+0
gdbarch_static_transform_name is completely Solaris-specific or rather specific to the Studio compilers. Studio cc has deprecated Stabs support in the 12.4 release back in 2015, GCC has defaulted to DWARF-2 on Solaris 7+ since 2004 and Stabs themselves are pretty much obsolete, so the whole code can go. Tested on sparcv9-sun-solaris2.11 and x86_64-pc-linux-gnu with --enable-targets=all. * sol2-tdep.c (sol2_static_transform_name): Remove. (sol2_init_abi): Don't register it. * gdbarch.sh (static_transform_name): Remove. * gdbarch.c, gdbarch.h: Regenerate. * dbxread.c (read_dbx_symtab) <'S'>: Remove call to gdbarch_static_transform_name. * mdebugread.c (parse_partial_symbols) <'S'>: Likewise. * stabsread.c (define_symbol) <'X'>: Remove. (define_symbol) <'S'>: Remove gdbarch_static_transform_name handling. <'V'>: Likewise. * xcoffread.c (scan_xcoff_symtab): Remove gdbarch. <'S'>: Remove call to gdbarch_static_transform_name.
2020-05-24gdb: make gdbarch.sh write gdbarch.{c,h} directlySimon Marchi1-11/+1
It was suggested in this thread [1] that gdbarch.sh should write to gdbarch.h and gdbarch.c directly. This patch implements that. When running gdbarch.sh, we currently need to move new-gdbarch.c over gdbarch.c and new-gdbarch.h over gdbarch.h. It might have been useful at some point to not have gdbarch.sh overwrite gdbarch.h and gdbarch.c, but with git it's really unnecessary. Any changes to gdbarch.sh can be inspected using `git diff`. A next step would be to have the Makefile automatically run gdbarch.sh if it sees that gdbarch.c and gdbarch.h are out of date. Or maybe even remove gdbarch.c and gdbarch.h from the tree and generate them in the build directory when building. But that requires more thinking and discussions, and I think that this change is already useful in itself. [1] https://sourceware.org/pipermail/gdb-patches/2020-May/168265.html gdb/ChangeLog; * gdbarch.sh: Write to gdbarch.c/gdbarch.h directly. Don't compare old and new versions. (compare_new): Remove. Change-Id: I7970a9e8af0afc0145cb5a28e73d94fbaa1e25b9
2020-03-16gdb: move enum gdb_osabi to osabi.hSimon Marchi1-0/+1
I think it makes sense to have it there instead of in the catch-all defs.h. gdb/ChangeLog: * defs.h (enum gdb_osabi): Move to... * osabi.h (enum gdb_osabi): ... here. * gdbarch.sh: Include osabi.h in gdbarch.h. * gdbarch.h: Re-generate.
2020-02-14gdb: introduce displaced_step_closure_up type aliasSimon Marchi1-3/+3
To help with readability, add the type displaced_step_closure_up, an alias for std::unique_ptr<displaced_step_closure>, and use it throughout the code base. gdb/ChangeLog: * aarch64-tdep.c (aarch64_displaced_step_copy_insn): Use displaced_step_closure_up. * aarch64-tdep.h (aarch64_displaced_step_copy_insn): Likewise. (struct displaced_step_closure_up): * amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise. * amd64-tdep.h (amd64_displaced_step_copy_insn): Likewise. * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise. * gdbarch.sh (displaced_step_copy_insn): Likewise. * gdbarch.c, gdbarch.h: Re-generate. * i386-linux-tdep.c (i386_linux_displaced_step_copy_insn): Use displaced_step_closure_up. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. * i386-tdep.h (i386_displaced_step_copy_insn): Likewise. * infrun.h (displaced_step_closure_up): New type alias. (struct displaced_step_inferior_state) <step_closure>: Change type to displaced_step_closure_up. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Use displaced_step_closure_up. * s390-tdep.c (s390_displaced_step_copy_insn): Likewise.
2020-02-14gdb: make gdbarch_displaced_step_copy_insn return an std::unique_ptrSimon Marchi1-2/+2
This callback dynamically allocates a specialized displaced_step_closure, and gives the ownership of the object to its caller. So I think it would make sense for the callback to return an std::unique_ptr, this is what this patch implements. gdb/ChangeLog: * gdbarch.sh (displaced_step_copy_insn): Change return type to an std::unique_ptr. * gdbarch.c: Re-generate. * gdbarch.h: Re-generate. * infrun.c (displaced_step_prepare_throw): Adjust to std::unique_ptr change. * aarch64-tdep.c (aarch64_displaced_step_copy_insn): Change return type to std::unique_ptr. * aarch64-tdep.h (aarch64_displaced_step_copy_insn): Likewise. * amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise. * amd64-tdep.h (amd64_displaced_step_copy_insn): Likewise. * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise. * i386-linux-tdep.c (i386_linux_displaced_step_copy_insn): Likewise. * i386-tdep.c (i386_displaced_step_copy_insn): Likewise. * i386-tdep.h (i386_displaced_step_copy_insn): Likewise. * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise. * s390-tdep.c (s390_displaced_step_copy_insn): Likewise.
2020-01-29Recognize more program breakpoint patternsLuis Machado1-0/+7
New in v3: - Code cleanups based on reviews. New in v2: - Fixed misc problems based on reviews. - Switched to using gdbarch_program_breakpoint_here_p as opposed to gdbarch_insn_is_breakpoint. - Fixed matching of brk instructions. Previously the mask was incorrect, which was showing up as a few failures in the testsuite. Now it is clean. - New testcase (separate patch). - Moved program_breakpoint_here () to arch-utils.c and made it the default implementation of gdbarch_program_breakpoint_here_p. -- It was reported to me that program breakpoints (permanent ones inserted into the code itself) other than the one GDB uses for AArch64 (0xd4200000) do not generate visible stops when continuing, and GDB will continue spinning infinitely. This happens because GDB, upon hitting one of those program breakpoints, thinks the SIGTRAP came from a delayed breakpoint hit... (gdb) x/i $pc => 0x4005c0 <problem_function>: brk #0x90f (gdb) c Continuing. infrun: clear_proceed_status_thread (process 14198) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 14198 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: delayed software breakpoint trap, ignoring infrun: no stepping, continue infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14198] at 0x4005c0 infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14198.14198.0 [process 14198], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP ... ... which is not the case. If the program breakpoint is one GDB recognizes, then it will stop when it hits it. (gdb) x/i $pc => 0x4005c0 <problem_function>: brk #0x0 (gdb) c Continuing. infrun: clear_proceed_status_thread (process 14193) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 14193 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 14193] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 14193.14193.0 [process 14193], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: random signal (GDB_SIGNAL_TRAP) infrun: stop_waiting infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun: process 14193 not executing infrun: stop_all_threads, pass=1, iterations=1 infrun: process 14193 not executing infrun: stop_all_threads done Program received signal SIGTRAP, Trace/breakpoint trap. problem_function () at brk_0.c:7 7 asm("brk %0\n\t" ::"n"(0x0)); infrun: infrun_async(0) Otherwise GDB will keep trying to resume the inferior and will keep seeing the SIGTRAP's, without stopping. To the user it appears GDB has gone into an infinite loop, interruptible only by Ctrl-C. Also, windbg seems to use a different variation of AArch64 breakpoint compared to GDB. This causes problems when debugging Windows on ARM binaries, when program breakpoints are being used. The proposed patch creates a new gdbarch method (gdbarch_program_breakpoint_here_p) that tells GDB whether the underlying instruction is a breakpoint instruction or not. This is more general than only checking for the instruction GDB uses as breakpoint. The existing logic is still preserved for targets that do not implement this new gdbarch method. The end result is like so: (gdb) x/i $pc => 0x4005c0 <problem_function>: brk #0x90f (gdb) c Continuing. infrun: clear_proceed_status_thread (process 16417) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 16417 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 16417] at 0x4005c0 infrun: infrun_async(1) infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 16417.16417.0 [process 16417], infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: handle_inferior_event status->kind = stopped, signal = GDB_SIGNAL_TRAP infrun: stop_pc = 0x4005c0 infrun: random signal (GDB_SIGNAL_TRAP) infrun: stop_waiting infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun: process 16417 not executing infrun: stop_all_threads, pass=1, iterations=1 infrun: process 16417 not executing infrun: stop_all_threads done Program received signal SIGTRAP, Trace/breakpoint trap. problem_function () at brk.c:7 7 asm("brk %0\n\t" ::"n"(0x900 + 0xf)); infrun: infrun_async(0) gdb/ChangeLog: 2020-01-29 Luis Machado <luis.machado@linaro.org> * aarch64-tdep.c (BRK_INSN_MASK): Define to 0xffe0001f. (BRK_INSN_MASK): Define to 0xd4200000. (aarch64_program_breakpoint_here_p): New function. (aarch64_gdbarch_init): Set gdbarch_program_breakpoint_here_p hook. * arch-utils.c (default_program_breakpoint_here_p): Moved from breakpoint.c. * arch-utils.h (default_program_breakpoint_here_p): Moved from breakpoint.h * breakpoint.c (bp_loc_is_permanent): Changed return type to bool and call gdbarch_program_breakpoint_here_p. (program_breakpoint_here): Moved to arch-utils.c, renamed to default_program_breakpoint_here_p, changed return type to bool and simplified. * breakpoint.h (program_breakpoint_here): Moved prototype to arch-utils.h, renamed to default_program_breakpoint_here_p and changed return type to bool. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (program_breakpoint_here_p): New method. * infrun.c (handle_signal_stop): Call gdbarch_program_breakpoint_here_p.
2020-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
gdb/ChangeLog: Update copyright year range in all GDB files.
2019-12-04Remove gdbarch_bits_big_endianTom Tromey1-6/+0
From what I can tell, set_gdbarch_bits_big_endian has never been used. That is, all architectures since its introduction have simply used the default, which is simply check the architecture's byte-endianness. Because this interferes with the scalar_storage_order code, this patch removes this gdbarch setting entirely. In some places, type_byte_order is used rather than the plain gdbarch. gdb/ChangeLog 2019-12-04 Tom Tromey <tromey@adacore.com> * ada-lang.c (decode_constrained_packed_array) (ada_value_assign, value_assign_to_component): Update. * dwarf2loc.c (rw_pieced_value, access_memory) (dwarf2_compile_expr_to_ax): Update. * dwarf2read.c (dwarf2_add_field): Update. * eval.c (evaluate_subexp_standard): Update. * gdbarch.c, gdbarch.h: Rebuild. * gdbarch.sh (bits_big_endian): Remove. * gdbtypes.h (union field_location): Update comment. * target-descriptions.c (make_gdb_type): Update. * valarith.c (value_bit_index): Update. * value.c (struct value) <bitpos>: Update comment. (unpack_bits_as_long, modify_field): Update. * value.h (value_bitpos): Update comment. Change-Id: I379b5e0c408ec8742f7a6c6b721108e73ed1b018
2019-10-15Change gcc_target_options to return std::stringTom Tromey1-3/+3
This patch was inspired by a recent review that recommended using std::string in a new implementation of the gcc_target_options gdbarch function. It changes this function to return std::string rather than an ordinary xmalloc'd string. I believe this caught a latent memory leak in compile.c:get_args. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-10-15 Tom Tromey <tromey@adacore.com> * gdbarch.h, gdbarch.c: Rebuild. * gdbarch.sh (gcc_target_options): Change return type to std::string. * compile/compile.c (get_args): Update. * nios2-tdep.c (nios2_gcc_target_options): Return std::string. * arm-linux-tdep.c (arm_linux_gcc_target_options): Return std::string. * aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return std::string. * arch-utils.c (default_gcc_target_options): Return std::string. * arch-utils.h (default_gcc_target_options): Return std::string. * s390-tdep.c (s390_gcc_target_options): Return std::string. Change-Id: I51f61703426a323089e646da8f22320a2cafbc1f
2019-08-16Move [PAC] into a new MI field addr_flagsAlan Hayward1-0/+6
Add a new print_pc which prints both the PC and a new field addr_flags. Call this wherever the PC is printed in stack.c. Add a new gdbarch method get_pc_address_flags to obtain the addr_flag contents. By default returns an empty string, on AArch64 this returns PAC if the address has been masked in the frame. Document this in the manual and NEWS file. gdb/ChangeLog: * NEWS (Other MI changes): New subsection. * aarch64-tdep.c (aarch64_get_pc_address_flags): New function. (aarch64_gdbarch_init): Add aarch64_get_pc_address_flags. * arch-utils.c (default_get_pc_address_flags): New function. * arch-utils.h (default_get_pc_address_flags): New declaration. * gdbarch.sh: Add get_pc_address_flags. * gdbarch.c: Regenerate. * gdbarch.h: Likewise. * stack.c (print_pc): New function. (print_frame_info) (print_frame): Call print_pc. gdb/doc/ChangeLog: * gdb.texinfo (AArch64 Pointer Authentication) (GDB/MI Breakpoint Information) (Frame Information): Document addr_field.
2019-07-17gdb: Remove a non-const reference parameterAndrew Burgess1-2/+2
Non-const reference parameter should be avoided according to the GDB coding standard: https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Avoid_non-const_reference_parameters.2C_use_pointers_instead This commit updates the gdbarch method gdbarch_stap_adjust_register, and the one implementation i386_stap_adjust_register to avoid using a non-const reference parameter. I've also removed the kfail from the testsuite for bug 24541, as this issue is now resolved. gdb/ChangeLog: PR breakpoints/24541 * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh: Adjust return type and parameter types for 'stap_adjust_register'. (i386_stap_adjust_register): Adjust signature and return new register name. * stap-probe.c (stap_parse_register_operand): Adjust use of 'gdbarch_stap_adjust_register'. gdb/testsuite/ChangeLog: PR breakpoints/24541 * gdb.mi/mi-catch-cpp-exceptions.exp: Remove kfail due to 24541.
2019-06-28Adjust i386 registers on SystemTap probes' arguments (PR breakpoints/24541)Sergio Durigan Junior1-0/+30
This bug has been reported on PR breakpoints/24541, but it is possible to reproduce it easily by running: make check-gdb TESTS=gdb.base/stap-probe.exp RUNTESTFLAGS='--target_board unix/-m32' The underlying cause is kind of complex, and involves decisions made by GCC and the sys/sdt.h header file about how to represent a probe argument that lives in a register in 32-bit programs. I'll use Andrew's example on the bug to illustrate the problem. libstdc++ has a probe named "throw" with two arguments. On i386, the probe is: stapsdt 0x00000028 NT_STAPSDT (SystemTap probe descriptors) Provider: libstdcxx Name: throw Location: 0x00072c96, Base: 0x00133d64, Semaphore: 0x00000000 Arguments: 4@%si 4@%di I.e., the first argument is an unsigned 32-bit value (represented by the "4@") that lives on %si, and the second argument is an unsigned 32-bit value that lives on %di. Note the discrepancy between the argument size reported by the probe (32-bit) and the register size being used to store the value (16-bit). However, if you take a look at the disassemble of a program that uses this probe, you will see: 00072c80 <__cxa_throw@@CXXABI_1.3>: 72c80: 57 push %edi 72c81: 56 push %esi 72c82: 53 push %ebx 72c83: 8b 74 24 10 mov 0x10(%esp),%esi 72c87: e8 74 bf ff ff call 6ec00 <__cxa_finalize@plt+0x980> 72c8c: 81 c3 74 e3 10 00 add $0x10e374,%ebx 72c92: 8b 7c 24 14 mov 0x14(%esp),%edi 72c96: 90 nop <----------------- PROBE IS HERE 72c97: e8 d4 a2 ff ff call 6cf70 <__cxa_get_globals@plt> 72c9c: 83 40 04 01 addl $0x1,0x4(%eax) 72ca0: 83 ec 04 sub $0x4,%esp 72ca3: ff 74 24 1c pushl 0x1c(%esp) 72ca7: 57 push %edi 72ca8: 56 push %esi 72ca9: e8 62 a3 ff ff call 6d010 <__cxa_init_primary_exception@plt> 72cae: 8d 70 40 lea 0x40(%eax),%esi 72cb1: c7 00 01 00 00 00 movl $0x1,(%eax) 72cb7: 89 34 24 mov %esi,(%esp) 72cba: e8 61 96 ff ff call 6c320 <_Unwind_RaiseException@plt> 72cbf: 89 34 24 mov %esi,(%esp) 72cc2: e8 c9 84 ff ff call 6b190 <__cxa_begin_catch@plt> 72cc7: e8 d4 b3 ff ff call 6e0a0 <_ZSt9terminatev@plt> 72ccc: 66 90 xchg %ax,%ax 72cce: 66 90 xchg %ax,%ax Note how the program is actually using %edi, and not %di, to store the second argument. This is the problem here. GDB will basically read the probe argument, then read the contents of %di, and then cast this value to uint32_t, which causes the wrong value to be obtained. In the gdb.base/stap-probe.exp case, this makes GDB read the wrong memory location, and not be able to display a test string. In Andrew's example, this causes GDB to actually stop at a "catch throw" when it should actually have *not* stopped. After some discussion with Frank Eigler and Jakub Jelinek, it was decided that this bug should be fixed on the client side (i.e., the program that actually reads the probes), and this is why I'm proposing this patch. The idea is simple: we will have a gdbarch method, which, for now, is only used by i386. The generic code that deals with register operands on gdb/stap-probe.c will call this method if it exists, passing the current parse information, the register name and its number. The i386 method will then verify if the register size is greater or equal than the size reported by the stap probe (the "4@" part). If it is, we're fine. Otherwise, it will check if we're dealing with any of the "extendable" registers (like ax, bx, si, di, sp, etc.). If we are, it will change the register name to include the "e" prefix. I have tested the patch here in many scenarios, and it fixes Andrew's bug and also the regressions I mentioned before, on gdb.base/stap-probe.exp. No regressions where found on other tests. Comments? gdb/ChangeLog: 2019-06-27 Sergio Durigan Junior <sergiodj@redhat.com> PR breakpoints/24541 * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh: Add 'stap_adjust_register'. * i386-tdep.c: Include '<unordered_set>'. (i386_stap_adjust_register): New function. (i386_elf_init_abi): Register 'i386_stap_adjust_register'. * stap-probe.c (stap_parse_register_operand): Call 'gdbarch_stap_adjust_register'.
2019-04-04Make base class for parser_stateTom Tromey1-3/+3
This makes a new base class, expr_builder, for parser_state. This separates the state needed to construct an expression from the state needed by the parsers. gdb/ChangeLog 2019-04-04 Tom Tromey <tom@tromey.com> * gdbarch.h, gdbarch.c: Rebuild. * gdbarch.sh (dtrace_parse_probe_argument): Change type. * stap-probe.h: (struct stap_parse_info): Replace "parser_state" with "expr_builder". * parser-defs.h (struct expr_builder): Rename from "parser_state". (parser_state): New class. * parse.c (expr_builder): Rename. (expr_builder::release): Rename. (write_exp_elt, write_exp_elt_opcode, write_exp_elt_sym) (write_exp_elt_msym, write_exp_elt_block, write_exp_elt_objfile) (write_exp_elt_longcst, write_exp_elt_floatcst) (write_exp_elt_type, write_exp_elt_intern, write_exp_string) (write_exp_string_vector, write_exp_bitstring) (write_exp_msymbol, mark_struct_expression) (write_dollar_variable) (insert_type_address_space, increase_expout_size): Replace "parser_state" with "expr_builder". * dtrace-probe.c: Replace "parser_state" with "expr_builder". * amd64-linux-tdep.c (amd64_dtrace_parse_probe_argument): Replace "parser_state" with "expr_builder".
2019-03-13Change pid_to_str to return std::stringTom Tromey1-2/+2
Currently the target pid_to_str method returns a const char *, so many implementations have a static buffer that they update. This patch changes these methods to return a std::string instead. I think this is cleaner and avoids possible gotchas when calling pid_to_str on different ptids in a single statement. (Though no such calls exist currently.) This also updates various helper functions, and the gdbarch pid_to_str methods. I also made a best effort to fix all the callers, but I can't build some of the *-nat.c files. Tested by the buildbot. gdb/ChangeLog 2019-03-13 Tom Tromey <tromey@adacore.com> * i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers) (i386_gnu_nat_target::store_registers): Update. * target-debug.h (target_debug_print_std_string): New macro. * x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update. * windows-tdep.c (display_one_tib): Update. * tui/tui-stack.c (tui_make_status_line): Update. * top.c (print_inferior_quit_action): Update. * thread.c (thr_try_catch_cmd): Update. (add_thread_with_info): Update. (thread_target_id_str): Update. (thr_try_catch_cmd): Update. (thread_command): Update. (thread_find_command): Update. * record-btrace.c (record_btrace_target::info_record) (record_btrace_resume_thread, record_btrace_target::resume) (record_btrace_cancel_resume, record_btrace_step_thread) (record_btrace_target::wait, record_btrace_target::wait) (record_btrace_target::wait, record_btrace_target::stop): Update. * progspace.c (print_program_space): Update. * process-stratum-target.c (process_stratum_target::thread_address_space): Update. * linux-fork.c (linux_fork_mourn_inferior) (detach_checkpoint_command, info_checkpoints_command) (linux_fork_context): Update. (linux_fork_detach): Update. (class scoped_switch_fork_info): Update. (delete_checkpoint_command): Update. * infrun.c (follow_fork_inferior): Update. (follow_fork_inferior): Update. (proceed_after_vfork_done): Update. (handle_vfork_child_exec_or_exit): Update. (follow_exec): Update. (displaced_step_prepare_throw): Update. (displaced_step_restore): Update. (start_step_over): Update. (resume_1): Update. (clear_proceed_status_thread): Update. (proceed): Update. (print_target_wait_results): Update. (do_target_wait): Update. (context_switch): Update. (stop_all_threads): Update. (restart_threads): Update. (finish_step_over): Update. (handle_signal_stop): Update. (switch_back_to_stepped_thread): Update. (keep_going_pass_signal): Update. (print_exited_reason): Update. (normal_stop): Update. * inferior.c (inferior_pid_to_str): Change return type. (print_selected_inferior): Update. (add_inferior): Update. (detach_inferior): Update. * dummy-frame.c (fprint_dummy_frames): Update. * dcache.c (dcache_info_1): Update. * btrace.c (btrace_enable, btrace_disable, btrace_teardown) (btrace_fetch, btrace_clear): Update. * linux-tdep.c (linux_core_pid_to_str): Change return type. * i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Change return type. * fbsd-tdep.c (fbsd_core_pid_to_str): Change return type. * sol2-tdep.h (sol2_core_pid_to_str): Change return type. * sol2-tdep.c (sol2_core_pid_to_str): Change return type. * gdbarch.c, gdbarch.h: Rebuild. * gdbarch.sh (core_pid_to_str): Change return type. * windows-nat.c (struct windows_nat_target) <pid_to_str>: Change return type. (windows_nat_target::pid_to_str): Change return type. (windows_delete_thread): Update. (windows_nat_target::attach): Update. (windows_nat_target::files_info): Update. * target-delegates.c: Rebuild. * sol-thread.c (class sol_thread_target) <pid_to_str>: Change return type. (sol_thread_target::pid_to_str): Change return type. * remote.c (class remote_target) <pid_to_str>: Change return type. (remote_target::pid_to_str): Change return type. (extended_remote_target::attach, remote_target::remote_stop_ns) (remote_target::remote_notif_remove_queued_reply) (remote_target::push_stop_reply, remote_target::disable_btrace): Update. (extended_remote_target::attach): Update. * remote-sim.c (struct gdbsim_target) <pid_to_str>: Change return type. (gdbsim_target::pid_to_str): Change return type. * ravenscar-thread.c (struct ravenscar_thread_target) <pid_to_str>: Change return type. (ravenscar_thread_target::pid_to_str): Change return type. * procfs.c (class procfs_target) <pid_to_str>: Change return type. (procfs_target::pid_to_str): Change return type. (procfs_target::attach): Update. (procfs_target::detach): Update. (procfs_target::fetch_registers): Update. (procfs_target::store_registers): Update. (procfs_target::wait): Update. (procfs_target::files_info): Update. * obsd-nat.c (obsd_nat_target::pid_to_str): Change return type. * nto-procfs.c (struct nto_procfs_target) <pid_to_str>: Change return type. (nto_procfs_target::pid_to_str): Change return type. (nto_procfs_target::files_info, nto_procfs_target::attach): Update. * linux-thread-db.c (class thread_db_target) <pid_to_str>: Change return type. * linux-nat.c (linux_nat_target::pid_to_str): Change return type. (exit_lwp): Update. (attach_proc_task_lwp_callback, get_detach_signal) (detach_one_lwp, resume_lwp, linux_nat_target::resume) (linux_nat_target::resume, wait_lwp, stop_callback) (maybe_clear_ignore_sigint, stop_wait_callback, status_callback) (save_stop_reason, select_event_lwp, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps) (linux_nat_target::wait, linux_nat_stop_lwp): Update. * inf-ptrace.c (inf_ptrace_target::pid_to_str): Change return type. (inf_ptrace_target::attach): Update. (inf_ptrace_target::files_info): Update. * go32-nat.c (struct go32_nat_target) <pid_to_str>: Change return type. (go32_nat_target::pid_to_str): Change return type. * gnu-nat.c (gnu_nat_target::pid_to_str): Change return type. (gnu_nat_target::wait): Update. (gnu_nat_target::wait): Update. (gnu_nat_target::resume): Update. * fbsd-nat.c (fbsd_nat_target::pid_to_str): Change return type. (fbsd_nat_target::wait): Update. * darwin-nat.c (darwin_nat_target::pid_to_str): Change return type. (darwin_nat_target::attach): Update. * corelow.c (class core_target) <pid_to_str>: Change return type. (core_target::pid_to_str): Change return type. * target.c (normal_pid_to_str): Change return type. (default_pid_to_str): Likewise. (target_pid_to_str): Change return type. (target_translate_tls_address): Update. (target_announce_detach): Update. * bsd-uthread.c (struct bsd_uthread_target) <pid_to_str>: Change return type. (bsd_uthread_target::pid_to_str): Change return type. * bsd-kvm.c (class bsd_kvm_target) <pid_to_str>: Change return type. (bsd_kvm_target::pid_to_str): Change return type. * aix-thread.c (class aix_thread_target) <pid_to_str>: Change return type. (aix_thread_target::pid_to_str): Change return type. * target.h (struct target_ops) <pid_to_str>: Change return type. (target_pid_to_str, normal_pid_to_str): Likewise. * obsd-nat.h (class obsd_nat_target) <pid_to_str>: Change return type. * linux-nat.h (class linux_nat_target) <pid_to_str>: Change return type. * inf-ptrace.h (struct inf_ptrace_target) <pid_to_str>: Change return type. * gnu-nat.h (struct gnu_nat_target) <pid_to_str>: Change return type. * fbsd-nat.h (class fbsd_nat_target) <pid_to_str>: Change return type. * darwin-nat.h (class darwin_nat_target) <pid_to_str>: Change return type.
2019-03-12Add a new gdbarch method to resolve the address of TLS variables.John Baldwin1-0/+12
Permit TLS variable addresses to be resolved purely by an ABI rather than requiring a target method. This doesn't try the target method if the ABI function is present (even if the ABI function fails) to simplify error handling. gdb/ChangeLog: * gdbarch.sh (get_thread_local_address): New method. * gdbarch.h, gdbarch.c: Regenerate. * target.c (target_translate_tls_address): Use gdbarch_get_thread_local_address if present instead of target::get_thread_local_address.
2019-02-27gdb: Restructure type_align and gdbarch_type_alignAndrew Burgess1-1/+4
This commit restructures the relationship between the type_align function and the gdbarch_type_align method. The problem being addressed with this commit is this; previously the type_align function was structured so that for "basic" types (int, float, etc) the gdbarch_type_align hook was called, which for "compound" types (arrays, structs, etc) the common type_align code has a fixed method for how to extract a "basic" type and would then call itself on that "basic" type. The problem is that if an architecture wants to modify the alignment rules for a "compound" type then this is not currently possible. In the revised structure, all types pass through the gdbarch_type_align method. If this method returns 0 then this indicates that the architecture has no special rules for this type, and GDB should apply the default rules for alignment. However, the architecture is free to provide an alignment for any type, both "basic" and "compound". After this commit the default alignment rules now all live in the type_align function, the default_type_align only ever returns 0, meaning apply the default rules. I've updated the 3 targets (arc, i386, and nios2) that already override the gdbarch_type_align method to fit the new scheme. Tested on X86-64/GNU Linux with no regressions. gdb/ChangeLog: * arc-tdep.c (arc_type_align): Provide alignment for basic types, return 0 for other types. * arch-utils.c (default_type_align): Always return 0. * gdbarch.h: Regenerate. * gdbarch.sh (type_align): Extend comment. * gdbtypes.c (type_align): Add additional comments, always call gdbarch_type_align before applying the default rules. * i386-tdep.c (i386_type_align): Return 0 as the default rule, generic code will then apply a suitable default. * nios2-tdep.c (nios2_type_align): Provide alignment for basic types, return 0 for other types.
2019-01-01Update copyright year range in all GDB files.Joel Brobecker1-1/+1
This commit applies all changes made after running the gdb/copyright.py script. Note that one file was flagged by the script, due to an invalid copyright header (gdb/unittests/basic_string_view/element_access/char/empty.cc). As the file was copied from GCC's libstdc++-v3 testsuite, this commit leaves this file untouched for the time being; a patch to fix the header was sent to gcc-patches first. gdb/ChangeLog: Update copyright year range in all GDB files.
2018-12-19gdb: Add default frame methods to gdbarchAndrew Burgess1-5/+8
Supply default gdbarch methods for gdbarch_dummy_id, gdbarch_unwind_pc, and gdbarch_unwind_sp. This patch doesn't actually convert any targets to use these methods, and so, there will be no user visible changes after this commit. The implementations for default_dummy_id and default_unwind_sp are fairly straight forward, these just take on the pattern used by most targets. Once these default methods are in place then most targets will be able to switch over. The implementation for default_unwind_pc is also fairly straight forward, but maybe needs some explanation. This patch has gone through a number of iterations: https://sourceware.org/ml/gdb-patches/2018-03/msg00165.html https://sourceware.org/ml/gdb-patches/2018-03/msg00306.html https://sourceware.org/ml/gdb-patches/2018-06/msg00090.html https://sourceware.org/ml/gdb-patches/2018-09/msg00127.html and the implementation of default_unwind_pc has changed over this time. Originally, I took an implementation like this: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { int pc_regnum = gdbarch_pc_regnum (gdbarch); return frame_unwind_register_unsigned (next_frame, pc_regnum); } This is basically a clone of default_unwind_sp, but using $pc. It was pointed out that we could potentially do better, and in version 2 the implementation became: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { struct type *type; int pc_regnum; CORE_ADDR addr; struct value *value; pc_regnum = gdbarch_pc_regnum (gdbarch); value = frame_unwind_register_value (next_frame, pc_regnum); type = builtin_type (gdbarch)->builtin_func_ptr; addr = extract_typed_address (value_contents_all (value), type); addr = gdbarch_addr_bits_remove (gdbarch, addr); release_value (value); value_free (value); return addr; } The idea was to try split out some of the steps of unwinding the $pc, steps that are on some (or many) targets no-ops, and so allow targets that do override these methods, to make use of default_unwind_pc. This implementation remained in place for version 2, 3, and 4. However, I realised that I'd made a mistake, most targets simply use frame_unwind_register_unsigned to unwind the $pc, and this throws an error if the register value is optimized out or unavailable. My new proposed implementation doesn't do this, I was going to end up breaking many targets. I considered duplicating the code from frame_unwind_register_unsigned that throws the errors into my new default_unwind_pc, however, this felt really overly complex. So, what I instead went with was to simply revert back to using frame_unwind_register_unsigned. Almost all existing targets already use this. Some of the ones that don't can be converted to, which means almost all targets could end up using the default. One addition I have made over the version 1 implementation is to add a call to gdbarch_addr_bits_remove. For most targets this is a no-op, but for a handful, having this call in place will mean that they can use the default method. After all this, the new default_unwind_pc now looks like this: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { int pc_regnum = gdbarch_pc_regnum (gdbarch); CORE_ADDR pc = frame_unwind_register_unsigned (next_frame, pc_regnum); pc = gdbarch_addr_bits_remove (gdbarch, pc); return pc; } gdb/ChangeLog: * gdb/dummy-frame.c (default_dummy_id): Defined new function. * gdb/dummy-frame.h (default_dummy_id): Declare new function. * gdb/frame-unwind.c (default_unwind_pc): Define new function. (default_unwind_sp): Define new function. * gdb/frame-unwind.h (default_unwind_pc): Declare new function. (default_unwind_sp): Declare new function. * gdb/frame.c (frame_unwind_pc): Assume gdbarch_unwind_pc is available. (get_frame_sp): Assume that gdbarch_unwind_sp is available. * gdb/gdbarch.c: Regenerate. * gdb/gdbarch.h: Regenerate. * gdb/gdbarch.sh: Update definition of dummy_id, unwind_pc, and unwind_sp. Add additional header files to be included in generated file.
2018-12-13Add an optional "alias" attribute to syscall entries.John Baldwin1-3/+0
When setting a syscall catchpoint by name, catch syscalls whose name or alias matches the requested string. When the ABI of a system call is changed in the FreeBSD kernel, this is implemented by leaving a compatibility system call using the old ABI at the existing "slot" and allocating a new system call for the version using the new ABI. For example, new fields were added to the 'struct kevent' used by the kevent() system call in FreeBSD 12. The previous kevent() system call in FreeBSD 12 kernels is now called freebsd11_kevent() and is still used by older binaries compiled against the older ABI. The freebsd11_kevent() system call can be tagged with an "alias" attribute of "kevent" permitting 'catch syscall kevent' to catch both system calls and providing the expected user behavior for both old and new binaries. It also provides the expected behavior if GDB is compiled on an older host (such as a FreeBSD 11 host). gdb/ChangeLog: * NEWS: Add entry documenting system call aliases. * break-catch-syscall.c (catch_syscall_split_args): Pass 'result' to get_syscalls_by_name. * gdbarch.sh (UNKNOWN_SYSCALL): Remove. * gdbarch.h: Regenerate. * syscalls/gdb-syscalls.dtd (syscall): Add alias attribute. * xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_name): Rename from get_syscall_by_name. Now accepts a pointer to a vector of integers and returns a bool. [HAVE_LIBEXPAT] (struct syscall_desc): Add alias member. (syscall_create_syscall_desc): Add alias parameter and pass it to syscall_desc constructor. (syscall_start_syscall): Handle alias attribute. (syscall_attr): Add alias attribute. (xml_get_syscalls_by_name): Rename from xml_get_syscall_number. Now accepts a pointer to a vector of integers and returns a bool. Add syscalls whose alias or name matches the requested name. (get_syscalls_by_name): Rename from get_syscall_by_name. Now accepts a pointer to a vector of integers and returns a bool. * xml-syscall.h (get_syscalls_by_name): Likewise. gdb/doc/ChangeLog: * gdb.texinfo (Set Catchpoints): Add an anchor for 'catch syscall'. (Native): Add a FreeBSD subsection. (FreeBSD): Document use of system call aliases for compatibility system calls.
2018-11-16Pass return_method to _push_dummy_callAlan Hayward1-2/+2
gdb/ChangeLog: * aarch64-tdep.c (aarch64_push_dummy_call): Replace arg with return_method. * alpha-tdep.c (alpha_push_dummy_call): Likewise. * amd64-tdep.c (amd64_push_arguments): Likewise. (amd64_push_dummy_call): Likewise. * amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise. * arc-tdep.c (arc_push_dummy_call): Likewise. * arm-tdep.c (arm_push_dummy_call): Likewise. * avr-tdep.c (avr_push_dummy_call): Likewise. * bfin-tdep.c (bfin_push_dummy_call): Likewise. * cris-tdep.c (cris_push_dummy_call): Likewise. * csky-tdep.c (csky_push_dummy_call): Likewise. * frv-tdep.c (frv_push_dummy_call): Likewise. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * gdbarch.sh (gdbarch_push_dummy_call): Replace arg with return_method. * h8300-tdep.c (h8300_push_dummy_call): Likewise. * hppa-tdep.c (hppa32_push_dummy_call): Likewise. (hppa64_push_dummy_call): Likewise. * i386-darwin-tdep.c (i386_darwin_push_dummy_call): Likewise. * i386-tdep.c (i386_push_dummy_call): Likewise. * ia64-tdep.c (ia64_push_dummy_call): Likewise. * infcall.c (call_function_by_hand_dummy): Likewise. * iq2000-tdep.c (iq2000_push_dummy_call): Likewise. * lm32-tdep.c (lm32_push_dummy_call): Likewise. * m32c-tdep.c (m32c_push_dummy_call): Likewise. * m32r-tdep.c (m32r_push_dummy_call): Likewise. * m68hc11-tdep.c (m68hc11_push_dummy_call): Likewise. * m68k-tdep.c (m68k_push_dummy_call): Likewise. * mep-tdep.c (mep_push_dummy_call): Likewise. * mips-tdep.c (mips_eabi_push_dummy_call): Likewise. (mips_n32n64_push_dummy_call): Likewise. (mips_o32_push_dummy_call): Likewise. (mips_o64_push_dummy_call): Likewise. * mn10300-tdep.c (mn10300_push_dummy_call): Likewise. * msp430-tdep.c (msp430_push_dummy_call): Likewise. * nds32-tdep.c (nds32_push_dummy_call): Likewise. * nios2-tdep.c (nios2_push_dummy_call): Likewise. * or1k-tdep.c (or1k_push_dummy_call): Likewise. * ppc-sysv-tdep.c (ppc_sysv_abi_push_dummy_call): Likewise. (ppc64_sysv_abi_push_dummy_call): Likewise. * ppc-tdep.h (ppc_sysv_abi_push_dummy_call): Likewise. (ppc64_sysv_abi_push_dummy_call): Likewise. * riscv-tdep.c (riscv_push_dummy_call): Likewise. * rl78-tdep.c (rl78_push_dummy_call): Likewise. * rs6000-aix-tdep.c (rs6000_push_dummy_call): Likewise. * rs6000-lynx178-tdep.c (rs6000_lynx178_push_dummy_call): Likewise. * rx-tdep.c (rx_push_dummy_call): Likewise. * s390-tdep.c (s390_push_dummy_call): Likewise. * score-tdep.c (score_push_dummy_call): Likewise. * sh-tdep.c (sh_push_dummy_call_fpu): Likewise. (sh_push_dummy_call_nofpu): Likewise. * sparc-tdep.c (sparc32_store_arguments): Likewise. (sparc32_push_dummy_call): Likewise. * sparc64-tdep.c (sparc64_store_arguments): Likewise. (sparc64_push_dummy_call): Likewise. * spu-tdep.c (spu_push_dummy_call): Likewise. * tic6x-tdep.c (tic6x_push_dummy_call): Likewise. * tilegx-tdep.c (tilegx_push_dummy_call): Likewise. * v850-tdep.c (v850_push_dummy_call): Likewise. * vax-tdep.c (vax_push_dummy_call): Likewise. * xstormy16-tdep.c (xstormy16_push_dummy_call): Likewise. * xtensa-tdep.c (xtensa_push_dummy_call): Likewise.
2018-11-16Use enum for return method for dummy callsAlan Hayward1-0/+23
In call_function_by_hand_dummy, struct_return and hidden_first_param_p are used to represent a single concept. Replace with an enum. gdb/ChangeLog: * gdbarch.sh (enum function_call_return_method): Add enum. * gdbarch.h: Regenerate. * infcall.c (call_function_by_hand_dummy): Replace vars with enum.
2018-10-21Introduce gdbarch_num_cooked_regsSimon Marchi1-0/+8
The expression gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch) is used quite often to find the number of cooked registers (raw + pseudo registers). This patch introduces gdbarch_num_cooked_regs, which does the equivalent. It substantially reduces required wrapping in some places, so should improve readability. There is a for loop in m68hc11_frame_unwind_cache that had iterated until (the equivalent of) gdbarch_num_cooked_regs (gdbarch) - 1. During review, we concluded that this is most likely an off-by-one mistake, so I replaced it with gdbarch_num_cooked_regs (gdbarch). gdb/ChangeLog: * gdbarch.sh (gdbarch_num_cooked_regs): New. * gdbarch.h: Re-generate. * ax-gdb.c (gen_expr): Use gdbarch_num_cooked_regs. * dwarf2-frame.c (dwarf2_frame_cache): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * findvar.c (value_of_register): Likewise. (value_of_register_lazy): Likewise. (address_from_register): Likewise. * frame.c (get_frame_register_bytes): Likewise. * gdbarch-selftests.c (register_to_value_test): Likewise. * h8300-tdep.c (h8300_register_type): Likewise. * i386-tdep.c (i386_dbx_reg_to_regnum): Likewise. (i386_svr4_reg_to_regnum): Likewise. * infcmd.c (default_print_registers_info): Likewise. (registers_info): Likewise. (print_vector_info): Likewise. (default_print_float_info): Likewise. * m68hc11-tdep.c (m68hc11_frame_unwind_cache): Likewise. * mdebugread.c (mdebug_reg_to_regnum): Likewise. * mi/mi-main.c (mi_cmd_data_list_register_names): Likewise. (mi_cmd_data_list_changed_registers): Likewise. (mi_cmd_data_list_register_values): Likewise. (mi_cmd_data_write_register_values): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mips-tdep.c (print_gp_register_row): Likewise. (mips_print_registers_info): Likewise. * nds32-tdep.c (nds32_gdbarch_init): Likewise. * regcache.c (init_regcache_descr): Likewise. (register_size): Likewise. (register_dump::dump): Likewise. (cooked_read_test): Likewise. (cooked_write_test): Likewise. * rs6000-tdep.c (rs6000_register_sim_regno): Likewise. (rs6000_gdbarch_init): Likewise. * stabsread.c (stab_reg_to_regnum): Likewise. * stack.c (info_frame_command): Likewise. * target-descriptions.c (tdesc_register_name): Likewise. * trad-frame.c (trad_frame_alloc_saved_regs): Likewise. * tui/tui-regs.c (tui_show_register_group): Likewise. * user-regs.c (user_reg_map_name_to_regnum): Likewise. (user_reg_map_regnum_to_name): Likewise. (value_of_user_reg): Likewise. (maintenance_print_user_registers): Likewise. * xtensa-tdep.c (xtensa_find_register_by_name): Likewise. (xtensa_register_name): Likewise. (xtensa_register_type): Likewise. (xtensa_reg_to_regnum): Likewise. (xtensa_pseudo_register_read): Likewise. (xtensa_pseudo_register_write): Likewise.
2018-08-31Regenerate gdbarch.hPedro Alves1-1/+2
The previous commit included a stale gdbarch.h from an earlier version of that patch by mistake. gdb/ChangeLog: 2018-08-31 Pedro Alves <palves@redhat.com> * gdbarch.h: Regenerate.
2018-08-31Add comment describing continuable/steppable/non-steppable watchpointsPedro Alves1-0/+2
These weren't described anywhere in the sources. gdb/ChangeLog: 2018-08-31 Pedro Alves <palves@redhat.com> * gdbarch.sh (have_nonsteppable_watchpoint): Add comment. * target.h (Hardware watchpoint interfaces): Describe continuable/steppable/non-steppable watchpoints. * gdbarch.h, gdbarch.c: Regenerate.
2018-08-13Split size in regset section iteratorsAlan Hayward1-5/+7
In the existing code, when using the regset section iteration functions, the size parameter is used in different ways. With collect, size is used to create the buffer in which to write the regset. (see linux-tdep.c::linux_collect_regset_section_cb). With supply, size is used to confirm the existing regset is the correct size. If REGSET_VARIABLE_SIZE is set then the regset can be bigger than size. Effectively, size is the minimum possible size of the regset. (see corelow.c::get_core_register_section). There are currently no targets with both REGSET_VARIABLE_SIZE and a collect function. In SVE, a corefile can contain one of two formats after the header, both of which are different sizes. However, when writing a core file, we always want to write out the full bigger size. To allow support of collects for REGSET_VARIABLE_SIZE we need two sizes. This is done by adding supply_size and collect_size. gdb/ * aarch64-fbsd-tdep.c (aarch64_fbsd_iterate_over_regset_sections): Add supply_size and collect_size. * aarch64-linux-tdep.c (aarch64_linux_iterate_over_regset_sections): Likewise. * alpha-linux-tdep.c (alpha_linux_iterate_over_regset_sections): * alpha-nbsd-tdep.c (alphanbsd_iterate_over_regset_sections): Likewise. * amd64-fbsd-tdep.c (amd64fbsd_iterate_over_regset_sections): Likewise. * amd64-linux-tdep.c (amd64_linux_iterate_over_regset_sections): Likewise. * arm-bsd-tdep.c (armbsd_iterate_over_regset_sections): Likewise. * arm-fbsd-tdep.c (arm_fbsd_iterate_over_regset_sections): Likewise. * arm-linux-tdep.c (arm_linux_iterate_over_regset_sections): Likewise. * corelow.c (get_core_registers_cb): Likewise. (core_target::fetch_registers): Likewise. * fbsd-tdep.c (fbsd_collect_regset_section_cb): Likewise. * frv-linux-tdep.c (frv_linux_iterate_over_regset_sections): Likewise. * gdbarch.h (void): Regenerate. * gdbarch.sh: Add supply_size and collect_size. * hppa-linux-tdep.c (hppa_linux_iterate_over_regset_sections): Likewise. * hppa-nbsd-tdep.c (hppanbsd_iterate_over_regset_sections): Likewise. * hppa-obsd-tdep.c (hppaobsd_iterate_over_regset_sections): Likewise. * i386-fbsd-tdep.c (i386fbsd_iterate_over_regset_sections): Likewise. * i386-linux-tdep.c (i386_linux_iterate_over_regset_sections): Likewise. * i386-tdep.c (i386_iterate_over_regset_sections): Likewise. * ia64-linux-tdep.c (ia64_linux_iterate_over_regset_sections): Likewise. * linux-tdep.c (linux_collect_regset_section_cb): Likewise. * m32r-linux-tdep.c (m32r_linux_iterate_over_regset_sections): Likewise. * m68k-bsd-tdep.c (m68kbsd_iterate_over_regset_sections): Likewise. * m68k-linux-tdep.c (m68k_linux_iterate_over_regset_sections): Likewise. * mips-fbsd-tdep.c (mips_fbsd_iterate_over_regset_sections): Likewise. * mips-linux-tdep.c (mips_linux_iterate_over_regset_sections): Likewise. * mips-nbsd-tdep.c (mipsnbsd_iterate_over_regset_sections): Likewise. * mips64-obsd-tdep.c (mips64obsd_iterate_over_regset_sections): Likewise. * mn10300-linux-tdep.c (am33_iterate_over_regset_sections): Likewise. * nios2-linux-tdep.c (nios2_iterate_over_regset_sections): Likewise. * ppc-fbsd-tdep.c (ppcfbsd_iterate_over_regset_sections): Likewise. * ppc-linux-tdep.c (ppc_linux_iterate_over_regset_sections): Likewise. * ppc-nbsd-tdep.c (ppcnbsd_iterate_over_regset_sections): Likewise. * ppc-obsd-tdep.c (ppcobsd_iterate_over_regset_sections): Likewise. * riscv-linux-tdep.c (riscv_linux_iterate_over_regset_sections): Likewise. * rs6000-aix-tdep.c (rs6000_aix_iterate_over_regset_sections): Likewise. * s390-linux-tdep.c (s390_iterate_over_regset_sections): Likewise. * score-tdep.c (score7_linux_iterate_over_regset_sections): Likewise. * sh-tdep.c (sh_iterate_over_regset_sections): Likewise. * sparc-tdep.c (sparc_iterate_over_regset_sections): Likewise. * tilegx-linux-tdep.c (tilegx_iterate_over_regset_sections): Likewise. * vax-tdep.c (vax_iterate_over_regset_sections): Likewise. * xtensa-tdep.c (xtensa_iterate_over_regset_sections): Likewise.
2018-07-02GDB PR tdep/8282: MIPS: Wire in `set disassembler-options'Maciej W. Rozycki1-2/+5
Implement MIPS target support for passing options to the disassembler, complementing commit 65b48a81404c ("GDB: Add support for the new set/show disassembler-options commands."). This includes options that expect an argument, so adjust the generic code and data structures used so as to handle such options. So as to give backends syntax flexibility no specific delimiter has been defined to separate options from their respective arguments, so it has to be included as the last character of the option name. Completion code however has not been adjusted and consequently option arguments cannot be completed at this time. Also the MIPS target has non-empty defaults for the options, so that ABI names for the general-purpose registers respect our `set mips abi ...' setting rather than always being determined from the ELF headers of the binary file selected. Handle these defaults as implicit options, never shown to the user and always prepended to the user-specified options, so that the latters can override the defaults. The resulting output for the MIPS target is as follows: (gdb) show disassembler-options The current disassembler options are '' The following disassembler options are supported for use with the 'set disassembler-options <option>[,<option>...]' command: no-aliases Use canonical instruction forms. msa Recognize MSA instructions. virt Recognize the virtualization ASE instructions. xpa Recognize the eXtended Physical Address (XPA) ASE instructions. ginv Recognize the Global INValidate (GINV) ASE instructions. gpr-names=ABI Print GPR names according to specified ABI. Default: based on binary being disassembled. fpr-names=ABI Print FPR names according to specified ABI. Default: numeric. cp0-names=ARCH Print CP0 register names according to specified architecture. Default: based on binary being disassembled. hwr-names=ARCH Print HWR names according to specified architecture. Default: based on binary being disassembled. reg-names=ABI Print GPR and FPR names according to specified ABI. reg-names=ARCH Print CP0 register and HWR names according to specified architecture. For the options above, the following values are supported for "ABI": numeric 32 n32 64 For the options above, the following values are supported for "ARCH": numeric r3000 r3900 r4000 r4010 vr4100 vr4111 vr4120 r4300 r4400 r4600 r4650 r5000 vr5400 vr5500 r5900 r6000 rm7000 rm9000 r8000 r10000 r12000 r14000 r16000 mips5 mips32 mips32r2 mips32r3 mips32r5 mips32r6 mips64 mips64r2 mips64r3 mips64r5 mips64r6 interaptiv-mr2 sb1 loongson2e loongson2f loongson3a octeon octeon+ octeon2 octeon3 xlr xlp (gdb) which corresponds to what `objdump --help' used to print for the MIPS target, with minor formatting changes, most notably option argument lists being wrapped, but also the amount of white space separating options from the respective descriptions. The relevant part the new code is now also used by `objdump --help', which means these formatting changes apply to both outputs, except for argument list wrapping, which is GDB-specific. This also adds a separating new line between the heading and option lists where descriptions are provided, hence: (gdb) set architecture s390:31-bit (gdb) show disassembler-options The current disassembler options are '' The following disassembler options are supported for use with the 'set disassembler-options <option>[,<option>...]' command: esa Disassemble in ESA architecture mode zarch Disassemble in z/Architecture mode insnlength Print unknown instructions according to length from first two bits (gdb) but: (gdb) set architecture powerpc:common (gdb) show disassembler-options The current disassembler options are '' The following disassembler options are supported for use with the 'set disassembler-options <option>[,<option>...]' command: 403, 405, 440, 464, 476, 601, 603, 604, 620, 7400, 7410, 7450, 7455, 750cl, 821, 850, 860, a2, altivec, any, booke, booke32, cell, com, e200z4, e300, e500, e500mc, e500mc64, e5500, e6500, e500x2, efs, efs2, power4, power5, power6, power7, power8, power9, ppc, ppc32, 32, ppc64, 64, ppc64bridge, ppcps, pwr, pwr2, pwr4, pwr5, pwr5x, pwr6, pwr7, pwr8, pwr9, pwrx, raw, spe, spe2, titan, vle, vsx (gdb) Existing affected target backends have been adjusted accordingly. This has been verified manually with: (gdb) set architecture arm (gdb) set architecture powerpc:common (gdb) set architecture s390:31-bit to cause no issues with the `show disassembler-options' and `set disassembler-options' commands. A test case for the MIPS target has also been provided, covering the default settings with ABI overrides as well as disassembler option overrides. 2018-07-02 Maciej W. Rozycki <macro@mips.com> Simon Marchi <simon.marchi@polymtl.ca> include/ PR tdep/8282 * dis-asm.h (disasm_option_arg_t): New typedef. (disasm_options_and_args_t): Likewise. (disasm_options_t): Add `arg' member, document members. (disassembler_options_mips): New prototype. (disassembler_options_arm, disassembler_options_powerpc) (disassembler_options_s390): Update prototypes. opcodes/ PR tdep/8282 * mips-dis.c (mips_option_arg_t): New enumeration. (mips_options): New variable. (disassembler_options_mips): New function. (print_mips_disassembler_options): Reimplement in terms of `disassembler_options_mips'. * arm-dis.c (disassembler_options_arm): Adapt to using the `disasm_options_and_args_t' structure. * ppc-dis.c (disassembler_options_powerpc): Likewise. * s390-dis.c (disassembler_options_s390): Likewise. gdb/ PR tdep/8282 * disasm.h (gdb_disassembler): Add `m_disassembler_options_holder'. member * disasm.c (get_all_disassembler_options): New function. (gdb_disassembler::gdb_disassembler): Use it. (gdb_buffered_insn_length_init_dis): Likewise. (gdb_buffered_insn_length): Adjust accordingly. (set_disassembler_options): Handle options with arguments. (show_disassembler_options_sfunc): Likewise. Add a leading new line if showing options with descriptions. (disassembler_options_completer): Adapt to using the `disasm_options_and_args_t' structure. * mips-tdep.c (mips_disassembler_options): New variable. (mips_disassembler_options_o32): Likewise. (mips_disassembler_options_n32): Likewise. (mips_disassembler_options_n64): Likewise. (gdb_print_insn_mips): Don't set `disassembler_options'. (gdb_print_insn_mips_n32, gdb_print_insn_mips_n64): Remove functions. (mips_gdbarch_init): Always set `gdbarch_print_insn' to `gdb_print_insn_mips'. Set `gdbarch_disassembler_options', `gdbarch_disassembler_options_implicit' and `gdbarch_valid_disassembler_options'. * arm-tdep.c (_initialize_arm_tdep): Adapt to using the `disasm_options_and_args_t' structure. * gdbarch.sh (disassembler_options_implicit): New `gdbarch' method. (valid_disassembler_options): Switch from `disasm_options_t' to the `disasm_options_and_args_t' structure. * NEWS: Document `set disassembler-options' support for the MIPS target. * gdbarch.h: Regenerate. * gdbarch.c: Regenerate. gdb/doc/ PR tdep/8282 * gdb.texinfo (Source and Machine Code): Document `set disassembler-options' support for the MIPS target. gdb/testsuite/ PR tdep/8282 * gdb.arch/mips-disassembler-options.exp: New test. * gdb.arch/mips-disassembler-options.s: New test source.
2018-06-21Use thread_info and inferior pointers more throughoutPedro Alves1-2/+2
This is more preparation bits for multi-target support. In a multi-target scenario, we need to address the case of different processes/threads running on different targets that happen to have the same PID/PTID. E.g., we can have both process 123 in target 1, and process 123 in target 2, while they're in reality different processes running on different machines. Or maybe we've loaded multiple instances of the same core file. Etc. To address this, in my WIP multi-target branch, threads and processes are uniquely identified by the (process_stratum target_ops *, ptid_t) and (process_stratum target_ops *, pid) tuples respectively. I.e., each process_stratum instance has its own thread/process number space. As you can imagine, that requires passing around target_ops * pointers in a number of functions where we're currently passing only a ptid_t or an int. E.g., when we look up a thread_info object by ptid_t in find_thread_ptid, the ptid_t alone isn't sufficient. In many cases though, we already have the thread_info or inferior pointer handy, but we "lose" it somewhere along the call stack, only to look it up again by ptid_t/pid. Since thread_info or inferior objects know their parent target, if we pass around thread_info or inferior pointers when possible, we avoid having to add extra target_ops parameters to many functions, and also, we eliminate a number of by ptid_t/int lookups. So that's what this patch does. In a bit more detail: - Changes a number of functions and methods to take a thread_info or inferior pointer instead of a ptid_t or int parameter. - Changes a number of structure fields from ptid_t/int to inferior or thread_info pointers. - Uses the inferior_thread() function whenever possible instead of inferior_ptid. - Uses thread_info pointers directly when possible instead of the is_running/is_stopped etc. routines that require a lookup. - A number of functions are eliminated along the way, such as: int valid_gdb_inferior_id (int num); int pid_to_gdb_inferior_id (int pid); int gdb_inferior_id_to_pid (int num); int in_inferior_list (int pid); - A few structures and places hold a thread_info pointer across inferior execution, so now they take a strong reference to the (refcounted) thread_info object to avoid the thread_info pointer getting stale. This is done in enable_thread_stack_temporaries and in the infcall.c code. - Related, there's a spot in infcall.c where using a RAII object to handle the refcount would be handy, so a gdb::ref_ptr specialization for thread_info is added (thread_info_ref, in gdbthread.h), along with a gdb_ref_ptr policy that works for all refcounted_object types (in common/refcounted-object.h). gdb/ChangeLog: 2018-06-21 Pedro Alves <palves@redhat.com> * ada-lang.h (ada_get_task_number): Take a thread_info pointer instead of a ptid_t. All callers adjusted. * ada-tasks.c (ada_get_task_number): Likewise. All callers adjusted. (print_ada_task_info, display_current_task_id, task_command_1): Adjust. * breakpoint.c (watchpoint_in_thread_scope): Adjust to use inferior_thread. (breakpoint_kind): Adjust. (remove_breakpoints_pid): Rename to ... (remove_breakpoints_inf): ... this. Adjust to take an inferior pointer. All callers adjusted. (bpstat_clear_actions): Use inferior_thread. (get_bpstat_thread): New. (bpstat_do_actions): Use it. (bpstat_check_breakpoint_conditions, bpstat_stop_status): Adjust to take a thread_info pointer. All callers adjusted. (set_longjmp_breakpoint_for_call_dummy, set_momentary_breakpoint) (breakpoint_re_set_thread): Use inferior_thread. * breakpoint.h (struct inferior): Forward declare. (bpstat_stop_status): Update. (remove_breakpoints_pid): Delete. (remove_breakpoints_inf): New. * bsd-uthread.c (bsd_uthread_target::wait) (bsd_uthread_target::update_thread_list): Use find_thread_ptid. * btrace.c (btrace_add_pc, btrace_enable, btrace_fetch) (maint_btrace_packet_history_cmd) (maint_btrace_clear_packet_history_cmd): Adjust. (maint_btrace_clear_cmd, maint_info_btrace_cmd): Adjust to use inferior_thread. * cli/cli-interp.c: Include "inferior.h". * common/refcounted-object.h (struct refcounted_object_ref_policy): New. * compile/compile-object-load.c: Include gdbthread.h. (store_regs): Use inferior_thread. * corelow.c (core_target::close): Use current_inferior. (core_target_open): Adjust to use first_thread_of_inferior and use the current inferior. * ctf.c (ctf_target::close): Adjust to use current_inferior. * dummy-frame.c (dummy_frame_id) <ptid>: Delete, replaced by ... <thread>: ... this new field. All references adjusted. (dummy_frame_pop, dummy_frame_discard, register_dummy_frame_dtor): Take a thread_info pointer instead of a ptid_t. * dummy-frame.h (dummy_frame_push, dummy_frame_pop) (dummy_frame_discard, register_dummy_frame_dtor): Take a thread_info pointer instead of a ptid_t. * elfread.c: Include "inferior.h". (elf_gnu_ifunc_resolver_stop, elf_gnu_ifunc_resolver_return_stop): Use inferior_thread. * eval.c (evaluate_subexp): Likewise. * frame.c (frame_pop, has_stack_frames, find_frame_sal): Use inferior_thread. * gdb_proc_service.h (struct thread_info): Forward declare. (struct ps_prochandle) <ptid>: Delete, replaced by ... <thread>: ... this new field. All references adjusted. * gdbarch.h, gdbarch.c: Regenerate. * gdbarch.sh (get_syscall_number): Replace 'ptid' parameter with a 'thread' parameter. All implementations and callers adjusted. * gdbthread.h (thread_info) <set_running>: New method. (delete_thread, delete_thread_silent): Take a thread_info pointer instead of a ptid. (global_thread_id_to_ptid, ptid_to_global_thread_id): Delete. (first_thread_of_process): Delete, replaced by ... (first_thread_of_inferior): ... this new function. All callers adjusted. (any_live_thread_of_process): Delete, replaced by ... (any_live_thread_of_inferior): ... this new function. All callers adjusted. (switch_to_thread, switch_to_no_thread): Declare. (is_executing): Delete. (enable_thread_stack_temporaries): Update comment. <enable_thread_stack_temporaries>: Take a thread_info pointer instead of a ptid_t. Incref the thread. <~enable_thread_stack_temporaries>: Decref the thread. <m_ptid>: Delete <m_thr>: New. (thread_stack_temporaries_enabled_p, push_thread_stack_temporary) (get_last_thread_stack_temporary) (value_in_thread_stack_temporaries, can_access_registers_thread): Take a thread_info pointer instead of a ptid_t. All callers adjusted. * infcall.c (get_call_return_value): Use inferior_thread. (run_inferior_call): Work with thread pointers instead of ptid_t. (call_function_by_hand_dummy): Work with thread pointers instead of ptid_t. Use thread_info_ref. * infcmd.c (proceed_thread_callback): Access thread's state directly. (ensure_valid_thread, ensure_not_running): Use inferior_thread, access thread's state directly. (continue_command): Use inferior_thread. (info_program_command): Use find_thread_ptid and access thread state directly. (proceed_after_attach_callback): Use thread state directly. (notice_new_inferior): Take a thread_info pointer instead of a ptid_t. All callers adjusted. (exit_inferior): Take an inferior pointer instead of a pid. All callers adjusted. (exit_inferior_silent): New. (detach_inferior): Delete. (valid_gdb_inferior_id, pid_to_gdb_inferior_id) (gdb_inferior_id_to_pid, in_inferior_list): Delete. (detach_inferior_command, kill_inferior_command): Use find_inferior_id instead of valid_gdb_inferior_id and gdb_inferior_id_to_pid. (inferior_command): Use inferior and thread pointers. * inferior.h (struct thread_info): Forward declare. (notice_new_inferior): Take a thread_info pointer instead of a ptid_t. All callers adjusted. (detach_inferior): Delete declaration. (exit_inferior, exit_inferior_silent): Take an inferior pointer instead of a pid. All callers adjusted. (gdb_inferior_id_to_pid, pid_to_gdb_inferior_id, in_inferior_list) (valid_gdb_inferior_id): Delete. * infrun.c (follow_fork_inferior, proceed_after_vfork_done) (handle_vfork_child_exec_or_exit, follow_exec): Adjust. (struct displaced_step_inferior_state) <pid>: Delete, replaced by ... <inf>: ... this new field. <step_ptid>: Delete, replaced by ... <step_thread>: ... this new field. (get_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (displaced_step_in_progress_any_inferior): Adjust. (displaced_step_in_progress_thread): Take a thread pointer instead of a ptid_t. All callers adjusted. (displaced_step_in_progress, add_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (get_displaced_step_closure_by_addr): Adjust. (remove_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (displaced_step_prepare_throw, displaced_step_prepare) (displaced_step_fixup): Take a thread pointer instead of a ptid_t. All callers adjusted. (start_step_over): Adjust. (infrun_thread_ptid_changed): Remove bit updating ptids in the displaced step queue. (do_target_resume): Adjust. (fetch_inferior_event): Use inferior_thread. (context_switch, get_inferior_stop_soon): Take an execution_control_state pointer instead of a ptid_t. All callers adjusted. (switch_to_thread_cleanup): Delete. (stop_all_threads): Use scoped_restore_current_thread. * inline-frame.c: Include "gdbthread.h". (inline_state) <inline_state>: Take a thread pointer instead of a ptid_t. All callers adjusted. <ptid>: Delete, replaced by ... <thread>: ... this new field. (find_inline_frame_state): Take a thread pointer instead of a ptid_t. All callers adjusted. (skip_inline_frames, step_into_inline_frame) (inline_skipped_frames, inline_skipped_symbol): Take a thread pointer instead of a ptid_t. All callers adjusted. * inline-frame.h (skip_inline_frames, step_into_inline_frame) (inline_skipped_frames, inline_skipped_symbol): Likewise. * linux-fork.c (delete_checkpoint_command): Adjust to use thread pointers directly. * linux-nat.c (get_detach_signal): Likewise. * linux-thread-db.c (thread_from_lwp): New 'stopped' parameter. (thread_db_notice_clone): Adjust. (thread_db_find_new_threads_silently) (thread_db_find_new_threads_2, thread_db_find_new_threads_1): Take a thread pointer instead of a ptid_t. All callers adjusted. * mi/mi-cmd-var.c: Include "inferior.h". (mi_cmd_var_update_iter): Update to use thread pointers. * mi/mi-interp.c (mi_new_thread): Update to use the thread's inferior directly. (mi_output_running_pid, mi_inferior_count): Delete, bits factored out to ... (mi_output_running): ... this new function. (mi_on_resume_1): Adjust to use it. (mi_user_selected_context_changed): Adjust to use inferior_thread. * mi/mi-main.c (proceed_thread): Adjust to use thread pointers directly. (interrupt_thread_callback): : Adjust to use thread and inferior pointers. * proc-service.c: Include "gdbthread.h". (ps_pglobal_lookup): Adjust to use the thread's inferior directly. * progspace-and-thread.c: Include "inferior.h". * progspace.c: Include "inferior.h". * python/py-exitedevent.c (create_exited_event_object): Adjust to hold a reference to an inferior_object. * python/py-finishbreakpoint.c (bpfinishpy_init): Adjust to use inferior_thread. * python/py-inferior.c (struct inferior_object): Give the type a tag name instead of a typedef. (python_on_normal_stop): No need to check if the current thread is listed. (inferior_to_inferior_object): Change return type to inferior_object. All callers adjusted. (find_thread_object): Delete, bits factored out to ... (thread_to_thread_object): ... this new function. * python/py-infthread.c (create_thread_object): Use inferior_to_inferior_object. (thpy_is_stopped): Use thread pointer directly. (gdbpy_selected_thread): Use inferior_thread. * python/py-record-btrace.c (btpy_list_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (btpy_insn_or_gap_new): Drop const. (btpy_list_new): Take a thread pointer instead of a ptid_t. All callers adjusted. * python/py-record.c: Include "gdbthread.h". (recpy_insn_new, recpy_func_new): Take a thread pointer instead of a ptid_t. All callers adjusted. (gdbpy_current_recording): Use inferior_thread. * python/py-record.h (recpy_record_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (recpy_element_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (recpy_insn_new, recpy_func_new): Take a thread pointer instead of a ptid_t. All callers adjusted. * python/py-threadevent.c: Include "gdbthread.h". (get_event_thread): Use thread_to_thread_object. * python/python-internal.h (struct inferior_object): Forward declare. (find_thread_object, find_inferior_object): Delete declarations. (thread_to_thread_object, inferior_to_inferior_object): New declarations. * record-btrace.c: Include "inferior.h". (require_btrace_thread): Use inferior_thread. (record_btrace_frame_sniffer) (record_btrace_tailcall_frame_sniffer): Use inferior_thread. (get_thread_current_frame): Use scoped_restore_current_thread and switch_to_thread. (get_thread_current_frame): Use thread pointer directly. (record_btrace_replay_at_breakpoint): Use thread's inferior pointer directly. * record-full.c: Include "inferior.h". * regcache.c: Include "gdbthread.h". (get_thread_arch_regcache): Use the inferior's address space directly. (get_thread_regcache, registers_changed_thread): New. * regcache.h (get_thread_regcache(thread_info *thread)): New overload. (registers_changed_thread): New. (remote_target) <remote_detach_1>: Swap order of parameters. (remote_add_thread): <remote_add_thread>: Return the new thread. (get_remote_thread_info(ptid_t)): New overload. (remote_target::remote_notice_new_inferior): Use thread pointers directly. (remote_target::process_initial_stop_replies): Use thread_info::set_running. (remote_target::remote_detach_1, remote_target::detach) (extended_remote_target::detach): Adjust. * stack.c (frame_show_address): Use inferior_thread. * target-debug.h (target_debug_print_thread_info_pp): New. * target-delegates.c: Regenerate. * target.c (default_thread_address_space): Delete. (memory_xfer_partial_1): Use current_inferior. (target_detach): Use current_inferior. (target_thread_address_space): Delete. (generic_mourn_inferior): Use current_inferior. * target.h (struct target_ops) <thread_address_space>: Delete. (target_thread_address_space): Delete. * thread.c (init_thread_list): Use ALL_THREADS_SAFE. Use thread pointers directly. (delete_thread_1, delete_thread, delete_thread_silent): Take a thread pointer instead of a ptid_t. Adjust all callers. (ptid_to_global_thread_id, global_thread_id_to_ptid): Delete. (first_thread_of_process): Delete, replaced by ... (first_thread_of_inferior): ... this new function. All callers adjusted. (any_thread_of_process): Rename to ... (any_thread_of_inferior): ... this, and take an inferior pointer. (any_live_thread_of_process): Rename to ... (any_live_thread_of_inferior): ... this, and take an inferior pointer. (thread_stack_temporaries_enabled_p, push_thread_stack_temporary) (value_in_thread_stack_temporaries) (get_last_thread_stack_temporary): Take a thread pointer instead of a ptid_t. Adjust all callers. (thread_info::set_running): New. (validate_registers_access): Use inferior_thread. (can_access_registers_ptid): Rename to ... (can_access_registers_thread): ... this, and take a thread pointer. (print_thread_info_1): Adjust to compare thread pointers instead of ptids. (switch_to_no_thread, switch_to_thread): Make extern. (scoped_restore_current_thread::~scoped_restore_current_thread): Use m_thread pointer directly. (scoped_restore_current_thread::scoped_restore_current_thread): Use inferior_thread. (thread_command): Use thread pointer directly. (thread_num_make_value_helper): Use inferior_thread. * top.c (execute_command): Use inferior_thread. * tui/tui-interp.c: Include "inferior.h". * varobj.c (varobj_create): Use inferior_thread. (value_of_root_1): Use find_thread_global_id instead of global_thread_id_to_ptid.
2018-05-20Introduce obstack_new, poison other "typed" obstack functionsSimon Marchi1-3/+7
Since we use obstacks with objects that are not default constructible, we sometimes need to manually call the constructor by hand using placement new: foo *f = obstack_alloc (obstack, sizeof (foo)); f = new (f) foo; It's possible to use allocate_on_obstack instead, but there are types that we sometimes want to allocate on an obstack, and sometimes on the regular heap. This patch introduces a utility to make this pattern simpler if allocate_on_obstack is not an option: foo *f = obstack_new<foo> (obstack); Right now there's only one usage (in tdesc_data_init). To help catch places where we would forget to call new when allocating such an object on an obstack, this patch also poisons some other methods of allocating an instance of a type on an obstack: - OBSTACK_ZALLOC/OBSTACK_CALLOC - XOBNEW/XOBNEW - GDBARCH_OBSTACK_ZALLOC/GDBARCH_OBSTACK_CALLOC Unfortunately, there's no way to catch wrong usages of obstack_alloc. By pulling on that string though, it tripped on allocating struct template_symbol using OBSTACK_ZALLOC. The criterion currently used to know whether it's safe to "malloc" an instance of a struct is whether it is a POD. Because it inherits from struct symbol, template_symbol is not a POD. This criterion is a bit too strict however, it should still safe to allocate memory for a template_symbol and memset it to 0. We didn't use is_trivially_constructible as the criterion in the first place only because it is not available in gcc < 5. So here I considered two alternatives: 1. Relax that criterion to use std::is_trivially_constructible and add a bit more glue code to make it work with gcc < 5 2. Continue pulling on the string and change how the symbol structures are allocated and initialized I managed to do both, but I decided to go with #1 to keep this patch simpler and more focused. When building with a compiler that does not have is_trivially_constructible, the check will just not be enforced. gdb/ChangeLog: * common/traits.h (HAVE_IS_TRIVIALLY_COPYABLE): Define if compiler supports std::is_trivially_constructible. * common/poison.h: Include obstack.h. (IsMallocable): Define to is_trivially_constructible if the compiler supports it, define to true_type otherwise. (xobnew): New. (XOBNEW): Redefine. (xobnewvec): New. (XOBNEWVEC): Redefine. * gdb_obstack.h (obstack_zalloc): New. (OBSTACK_ZALLOC): Redefine. (obstack_calloc): New. (OBSTACK_CALLOC): Redefine. (obstack_new): New. * gdbarch.sh: Include gdb_obstack in gdbarch.h. (gdbarch_obstack): New declaration in gdbarch.h, definition in gdbarch.c. (GDBARCH_OBSTACK_CALLOC, GDBARCH_OBSTACK_ZALLOC): Use obstack_calloc/obstack_zalloc. (gdbarch_obstack_zalloc): Remove. * target-descriptions.c (tdesc_data_init): Use obstack_new.
2018-04-30Remove long_long_align_bit gdbarch attributeTom Tromey1-6/+0
This removes the long_long_align_bit gdbarch attribute in favor of type_align. This uncovered two possible issues. First, arc-tdep.c claimed that long long alignment was 32 bits, but as discussed on the list, ARC has a maximum alignment of 32 bits, so I've added an arc_type_align function to account for this. Second, jit.c, the sole user of long_long_align_bit, was confusing "long long" with uint64_t. The relevant structure is defined in the JIT API part of the manual as: struct jit_code_entry { struct jit_code_entry *next_entry; struct jit_code_entry *prev_entry; const char *symfile_addr; uint64_t symfile_size; }; I've changed this code to use uint64_t. 2018-04-30 Tom Tromey <tom@tromey.com> * jit.c (jit_read_code_entry): Use type_align. * i386-tdep.c (i386_gdbarch_init): Don't call set_gdbarch_long_long_align_bit. * gdbarch.sh: Remove long_long_align_bit. * gdbarch.c, gdbarch.h: Rebuild. * arc-tdep.c (arc_type_align): New function. (arc_gdbarch_init): Use arc_type_align. Don't call set_gdbarch_long_long_align_bit.
2018-04-30Add initial type alignment supportTom Tromey1-0/+6
This adds some basic type alignment support to gdb. It changes struct type to store the alignment, and updates dwarf2read.c to handle DW_AT_alignment. It also adds a new gdbarch method and updates i386-tdep.c. None of this new functionality is used anywhere yet, so tests will wait until the next patch. 2018-04-30 Tom Tromey <tom@tromey.com> * i386-tdep.c (i386_type_align): New function. (i386_gdbarch_init): Update. * gdbarch.sh (type_align): New method. * gdbarch.c, gdbarch.h: Rebuild. * arch-utils.h (default_type_align): Declare. * arch-utils.c (default_type_align): New function. * gdbtypes.h (TYPE_ALIGN_BITS): New define. (struct type) <align_log2>: New field. <instance_flags>: Now a bitfield. (TYPE_RAW_ALIGN): New macro. (type_align, type_raw_align, set_type_align): Declare. * gdbtypes.c (type_align, type_raw_align, set_type_align): New functions. * dwarf2read.c (quirk_rust_enum): Set type alignment. (get_alignment, maybe_set_alignment): New functions. (read_structure_type, read_enumeration_type, read_array_type) (read_set_type, read_tag_pointer_type, read_tag_reference_type) (read_subrange_type, read_base_type): Set type alignment.
2018-04-13infrun: step through indirect branch thunksMarkus Metzger1-0/+6
With version 7.3 GCC supports new options -mindirect-branch=<choice> -mfunction-return=<choice> The choices are: keep behaves as before thunk jumps through a thunk thunk-external jumps through an external thunk thunk-inline jumps through an inlined thunk For thunk and thunk-external, GDB would, on a call to the thunk, step into the thunk and then resume to its caller assuming that this is an undebuggable function. On a return thunk, GDB would stop inside the thunk. Make GDB step through such thunks instead. Before: Temporary breakpoint 1, main () at gdb.base/step-indirect-call-thunk.c:37 37 x = apply (inc, 41); (gdb) s apply (op=0x80483e6 <inc>, x=41) at gdb.base/step-indirect-call-thunk.c:29 29 return op (x); (gdb) 30 } After: Temporary breakpoint 1, main () at gdb.base/step-indirect-call-thunk.c:37 37 x = apply (inc, 41); (gdb) s apply (op=0x80483e6 <inc>, x=41) at gdb.base/step-indirect-call-thunk.c:29 29 return op (x); (gdb) inc (x=41) at gdb.base/step-indirect-call-thunk.c:23 23 return x + 1; This is independent of the step-mode. In order to step into the thunk, you would need to use stepi. When stepping over an indirect call thunk, GDB would first step through the thunk, then recognize that it stepped into a sub-routine and resume to the caller (of the thunk). Not sure whether this is worth optimizing. Thunk detection is implemented via gdbarch. I implemented the methods for IA. Other architectures may run into unexpected fails. The tests assume a fixed number of instruction steps to reach a thunk. This depends on the compiler as well as the architecture. They may need adjustments when we add support for more architectures. Or we can simply drop those tests that cover being able to step into thunks using instruction stepping. When using an older GCC, the tests will fail to build and will be reported as untested: Running .../gdb.base/step-indirect-call-thunk.exp ... gdb compile failed, \ gcc: error: unrecognized command line option '-mindirect-branch=thunk' gcc: error: unrecognized command line option '-mfunction-return=thunk' === gdb Summary === # of untested testcases 1 gdb/ * infrun.c (process_event_stop_test): Call gdbarch_in_indirect_branch_thunk. * gdbarch.sh (in_indirect_branch_thunk): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * x86-tdep.h: New. * x86-tdep.c: New. * Makefile.in (ALL_TARGET_OBS): Add x86-tdep.o. (HFILES_NO_SRCDIR): Add x86-tdep.h. (ALLDEPFILES): Add x86-tdep.c. * arch-utils.h (default_in_indirect_branch_thunk): New. * arch-utils.c (default_in_indirect_branch_thunk): New. * i386-tdep: Include x86-tdep.h. (i386_in_indirect_branch_thunk): New. (i386_elf_init_abi): Set in_indirect_branch_thunk gdbarch function. * amd64-tdep: Include x86-tdep.h. (amd64_in_indirect_branch_thunk): New. (amd64_init_abi): Set in_indirect_branch_thunk gdbarch function. testsuite/ * gdb.base/step-indirect-call-thunk.exp: New. * gdb.base/step-indirect-call-thunk.c: New. * gdb.reverse/step-indirect-call-thunk.exp: New. * gdb.reverse/step-indirect-call-thunk.c: New.
2018-02-24Remove cleanups from check_fast_tracepoint_salsTom Tromey1-2/+2
This changes the gdbarch fast_tracepoint_valid_at method to use a std::string as its out parameter, and then updates all the uses. This allows removing a cleanup from breakpoint.c. Regression tested by the buildbot. ChangeLog 2018-02-24 Tom Tromey <tom@tromey.com> * i386-tdep.c (i386_fast_tracepoint_valid_at): "msg" now a std::string. * gdbarch.sh (fast_tracepoint_valid_at): Change "msg" to a std::string*. * gdbarch.c: Rebuild. * gdbarch.h: Rebuild. * breakpoint.c (check_fast_tracepoint_sals): Use std::string. * arch-utils.h (default_fast_tracepoint_valid_at): Update. * arch-utils.c (default_fast_tracepoint_valid_at): "msg" now a std::string*.