1. 04 Dec, 2020 28 commits
    • Simon Marchi's avatar
      gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps · 187b041e
      Simon Marchi authored
      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
        - 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
      	* 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_restore_all_in_ptid): New.
      	* gdbarch.c: Re-generate.
      	* gdbarch.h: Re-generate.
      	* gdbthread.h (class thread_info) <displaced_step_state>: New
      	(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_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):
      	* 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
      	(displaced_step_reset): Change parameter from inferior to
      	(displaced_step_prepare_throw): Implement using
      	(write_memory_ptid): Move to displaced-step.c.
      	(displaced_step_restore): Remove.
      	(displaced_step_finish): Implement using
      	(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
      	(amd64_linux_init_abi): Adjust call to
      	(amd64_x32_linux_init_abi): Likewise.
      	* aarch64-linux-tdep.c (aarch64_linux_init_abi): Adjust call to
      	linux_init_abi.  Remove call to
      	* 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
      	* 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
      	* arm-tdep.c (arm_pc_is_thumb): Call
      	gdbarch_displaced_step_copy_insn_closure_by_addr instead of
      	* 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.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
    • Simon Marchi's avatar
      gdb: move displaced stepping types to displaced-stepping.{h,c} · c7acb87b
      Simon Marchi authored
      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.
      	* 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.
      	(_initialize_infrun): Don't register "set/show debug displaced".
      Change-Id: I29935f5959b80425370630a45148fc06cd4227ca
    • Simon Marchi's avatar
      gdb: pass inferior to get_linux_inferior_data · 94b24c74
      Simon Marchi authored
      Pass to get_linux_inferior_data the inferior for which we want to obtain
      the linux-specific data, rather than assuming the current inferior.
      This helps slightly reduce the diff in the upcoming main patch.
      Update the sole caller to pass the current inferior.
      	* linux-tdep.c (get_linux_inferior_data): Add inferior
      	(linux_vsyscall_range): Pass current inferior.
      Change-Id: Ie4b61190e4a2e89b5b55a140cfecd4de66d92393
    • Simon Marchi's avatar
      gdb: introduce status enum for displaced step prepare/finish · bab37966
      Simon Marchi authored
      This is a preparatory patch to reduce the size of the diff of the
      upcoming main patch.  It introduces enum types for the return values of
      displaced step "prepare" and "finish" operations.  I find that this
      expresses better the intention of the code, rather than returning
      arbitrary integer values (-1, 0 and 1) which are difficult to remember.
      That makes the code easier to read.
      I put the new enum types in a new displaced-stepping.h file, because I
      introduce that file in a later patch anyway.  Putting it there avoids
      having to move it later.
      There is one change in behavior for displaced_step_finish: it currently
      returns 0 if the thread wasn't doing a displaced step and 1 if the
      thread was doing a displaced step which was executed successfully.  It
      turns out that this distinction is not needed by any caller, so I've
      merged these two cases into "_OK", rather than adding an extra
      	* infrun.c (displaced_step_prepare_throw): Change return type to
      	(displaced_step_prepare): Likewise.
      	(displaced_step_finish): Change return type to
      	(resume_1): Adjust.
      	(stop_all_threads): Adjust.
      	* displaced-stepping.h: New file.
      Change-Id: I5c8fe07212cd398d5b486b5936d9d0807acd3788
    • Simon Marchi's avatar
      gdb: rename displaced_step_fixup to displaced_step_finish · 7def77a1
      Simon Marchi authored
      This is a preparatory patch to reduce a little bit the diff size of the
      main patch later in this series.  It renames the displaced_step_fixup
      function in infrun.c to displaced_step_finish.
      The rationale is to better differentiate the low and high level
      We first have the low level operation of writing an instruction to a
      displaced buffer, called "copy_insn".  The mirror low level operation to
      fix up the state after having executed the instruction is "fixup".  The
      high level operation of preparing a thread for a displaced step (which
      includes doing the "copy_insn" and some more bookkeeping) is called
      "prepare" (as in displaced_step_prepare).  The mirror high level
      operation to cleaning up after a displaced step (which includes doing
      the "fixup" and some more bookkeeping) is currently also called "fixup"
      (as in displaced_step_fixup), just like the low level operation.
      I think that choosing a different name for the low and high level
      cleanup operation makes it clearer, hence "finish".
      	* infrun.c (displaced_step_fixup): Rename to...
      	(displaced_step_finish): ... this, update all callers.
      Change-Id: Id32f48c1e2091d09854c77fcedcc14d2519957a2
    • Simon Marchi's avatar
      gdb: rename displaced_step_closure to displaced_step_copy_insn_closure · 1152d984
      Simon Marchi authored
      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.
      	* 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
      	(buf_displaced_step_closure): Rename to...
      	(buf_displaced_step_copy_insn_closure): ... this.  Update all
      	* 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
      	* arm-tdep.h (arm_displaced_step_closure): Rename to...
      	(arm_displaced_step_copy_insn_closure): ... this.  Update all
      	* i386-tdep.h (i386_displaced_step_closure): Rename to...
      	(i386_displaced_step_copy_insn_closure): ... this.  Update all
      	* rs6000-tdep.c (ppc_displaced_step_closure): Rename to...
      	(ppc_displaced_step_copy_insn_closure): ... this.  Update all
      	* s390-tdep.c (s390_displaced_step_closure): Rename to...
      	(s390_displaced_step_copy_insn_closure): ... this.  Update all
      	* gdbarch.h: Re-generate.
      	* gdbarch.c: Re-generate.
      Change-Id: I11f56dbcd4c3532fb195a08ba93bccf1d12a03c8
    • Simon Marchi's avatar
      gdb: rename things related to step over chains · 28d5518b
      Simon Marchi authored
      Rename step_over_queue_head to global_thread_step_over_chain_head, to
      make it more obvious when reading code that we are touching the global
      queue.  Rename all functions that operate on it to have "global" in
      their name, to make it clear on which chain they operate on.  Also, in a
      subsequent patch, we'll need both global and non-global versions of
      these functions, so it will be easier to do the distinction if they are
      named properly.
      Normalize the naming to use "chain" everywhere instead of sometimes
      "queue", sometimes "chain".
      I also reworded a few comments in gdbthread.h.  They implied that the
      step over chain is per-inferior, when in reality there is only one
      global chain, not one per inferior, as far as I understand.
      	* gdbthread.h (thread_step_over_chain_enqueue): Rename to...
      	(global_thread_step_over_chain_enqueue): ... this.  Update all
      	(thread_step_over_chain_remove): Rename to...
      	(global_thread_step_over_chain_remove): ... this.  Update all
      	(thread_step_over_chain_next): Rename to...
      	(global_thread_step_over_chain_next): ... this.  Update all
      	* infrun.h (step_over_queue_head): Rename to...
      	(global_thread_step_over_chain_head): ... this.  Update all
      	* infrun.c (step_over_queue_head): Rename to...
      	(global_thread_step_over_chain_head): ... this.  Update all
      	* thread.c (step_over_chain_remove): Rename to...
      	(thread_step_over_chain_remove): ... this.  Update all users.
      	(thread_step_over_chain_next): Rename to...
      	(global_thread_step_over_chain_next): ... this.  Update all
      	(thread_step_over_chain_enqueue): Rename to...
      	(global_thread_step_over_chain_enqueue): ... this.  Update all
      	(thread_step_over_chain_remove): Rename to...
      	(global_thread_step_over_chain_remove): ... this.  Update all
      Change-Id: Iabbf57d83c01321ca199d83fadb57f5b04e4d6d9
    • Simon Marchi's avatar
      gdb: get rid of get_displaced_stepping_state · f5f01699
      Simon Marchi authored
      Remove function get_displaced_stepping_state.  When it was introduced,
      inferiors' displaced stepping state was kept in a linked list in
      infrun.c, so it was handy.  Nowadays, the state is kept inside struct
      inferior directly, so we can just access it directly instead.
      	* infrun.c (get_displaced_stepping_state): Remove, change
      	callers to access the field directly.
      Change-Id: I9a733e32e29c7ebf856ab0befe1076bbb8c7af69
    • Simon Marchi's avatar
      gdb: restore displaced step buffer bytes when another thread forks · c0aba012
      Simon Marchi authored
      In handle_inferior_event, where we handle forks, we make sure to restore
      the bytes of the displaced stepping buffer in the child's address
      space.  However, we only do it when the forking thread was the one
      doing a displaced step.  It could happen that a thread forks while
      another one is doing a displaced step.  In this case, we also need to
      restore the bytes in the child.
      Move the byte-restoring code outside of the condition that checks
      whether the event thread was displaced stepping.
      	* infrun.c (handle_inferior_event): Restore displaced step
      	buffer bytes in child process when handling fork, even if fork
      	happened in another thread than the displaced-stepping one.
      Change-Id: Ibb0daaeb123aba03f4fb4b4d820754eb2436bc69
    • Simon Marchi's avatar
      gdb: clear inferior displaced stepping state and in-line step-over info on exec · 3b7a962d
      Simon Marchi authored
      When a process does an exec, all its program space is replaced with the
      newly loaded executable.  All non-main threads disappear and the main
      thread starts executing at the entry point of the new executable.
      Things can go wrong if a displaced step operation is in progress while
      we process the exec event.
      If the main thread is the one executing the displaced step: when that
      thread (now executing in the new executable) stops somewhere (say, at a
      breakpoint), displaced_step_fixup will run and clear up the state.  We
      will execute the "fixup" phase for the instruction we single-stepped in
      the old program space.  We are now in a completely different context,
      so doing the fixup may corrupt the state.
      If it is a non-main thread that is doing the displaced step: while
      handling the exec event, GDB deletes the thread_info representing that
      thread (since the thread doesn't exist in the inferior after the exec).
      But inferior::displaced_step_state::step_thread will still point to it.
      When handling events later, this condition, in displaced_step_fixup,
      will likely never be true:
          /* Was this event for the thread we displaced?  */
          if (displaced->step_thread != event_thread)
            return 0;
      ... since displaced->step_thread points to a deleted thread (unless that
      storage gets re-used for a new thread_info, but that wouldn't be good
      either).  This effectively makes the displaced stepping buffer occupied
      for ever.  When a thread in the new program space will want to do a
      displaced step, it will wait for ever.
      I think we simply need to reset the displaced stepping state of the
      inferior on exec.  Everything execution-related that existed before the
      exec is now gone.
      Similarly, if a thread does an in-line step over an exec syscall
      instruction, nothing clears the in-line step over info when the event is
      handled.  So it the in-line step over info stays there indefinitely, and
      things hang because we can never start another step over.  To fix this,
      I added a call to clear_step_over_info in infrun_inferior_execd.
      Add a test with a program with two threads that does an exec.  The test
      includes the following axes:
      - whether it's the leader thread or the other thread that does the exec.
      - whether the exec'r and exec'd program have different text segment
        addresses.  This is to hopefully catch cases where the displaced
        stepping info doesn't get reset, and GDB later tries to restore bytes
        of the old address space in the new address space.  If the mapped
        addresses are different, we should get some memory error.   This
        happens without the patch applied:
        $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true -ex "b main" -ex r -ex "b my_execve_syscall if 0"  -ex "set displaced-stepping on"
        Breakpoint 1, main (argc=1, argv=0x7fffffffde38) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.threads/step-over-exec.c:69
        69        argv0 = argv[0];
        Breakpoint 2 at 0x60133a: file /home/simark/src/binutils-gdb/gdb/testsuite/lib/my-syscalls.S, line 34.
        (gdb) c
        [New Thread 0x7ffff7c62640 (LWP 1455423)]
        Leader going in exec.
        Exec-ing /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true-execd
        [Thread 0x7ffff7c62640 (LWP 1455423) exited]
        process 1455418 is executing new program: /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/step-over-exec/step-over-exec-execr-thread-leader-diff-text-segs-true-execd
        Error in re-setting breakpoint 2: Function "my_execve_syscall" not defined.
        No unwaited-for children left.
        (gdb) n
        Single stepping until exit from function _start,
        which has no line number information.
        Cannot access memory at address 0x6010d2
      - Whether displaced stepping is allowed or not, so that we end up
        testing both displaced stepping and in-line stepping on arches that do
        support displaced stepping (otherwise, it just tests in-line stepping
        twice I suppose)
      To be able to precisely put a breakpoint on the syscall instruction, I
      added a small assembly file (lib/my-syscalls.S) that contains minimal
      Linux syscall wrappers.  I prefer that to the strategy used in
      gdb.base/step-over-syscall.exp, which is to stepi into the glibc wrapper
      until we find something that looks like a syscall instruction, I find
      that more predictable.
      	* infrun.c (infrun_inferior_execd): New function.
      	(_initialize_infrun): Attach inferior_execd observer.
      	* gdb.threads/step-over-exec.exp: New.
      	* gdb.threads/step-over-exec.c: New.
      	* gdb.threads/step-over-exec-execd.c: New.
      	* lib/my-syscalls.S: New.
      	* lib/my-syscalls.h: New.
      Change-Id: I1bbc8538e683f53af5b980091849086f4fec5ff9
    • Simon Marchi's avatar
      gdb: add inferior_execd observable · 42a4fec5
      Simon Marchi authored
      I want to add another action (clearing displaced stepping state) that
      happens when an inferior execs.  I think it would be cleaner to have an
      observer for this event, rather than have infrun know about each other
      Replace the calls to solib_create_inferior_hook and
      jit_inferior_created_hook in follow_exec by observers.
      	* observable.h (inferior_execd): Declare new observable.
      	* observable.c (inferior_execd): Declare new observable.
      	* infrun.c (follow_exec): Notify inferior_execd observer.
      	* jit.c (jit_inferior_created_hook): Make static.
      	(_initialize_jit): Register inferior_execd observer.
      	* jit.h (jit_inferior_created_hook): Remove declaration.
      	* solib.c (_initialize_solib): Register inferior_execd observer.
      Change-Id: I000cce00094e23baa67df693d912646b6ae38e44
    • Tom de Vries's avatar
      [gdb] Fix heap-buffer-overflow in completion_tracker::build_completion_result · aafdfb4e
      Tom de Vries authored
      When building gdb with address sanitizer and running test-case
      gdb.base/completion.exp, we run into:
      ==5743==ERROR: AddressSanitizer: heap-buffer-overflow on address \
        0x60200025c02f at pc 0x000000cd9d64 bp 0x7fff3297da30 sp 0x7fff3297da28
      READ of size 1 at 0x60200025c02f thread T0
          #0 0xcd9d63 in completion_tracker::build_completion_result(char const*, \
                           int, int) gdb/completer.c:2258
      0x60200025c02f is located 1 bytes to the left of 1-byte region \
      This can be reproduced using just:
      $ gdb
      (gdb) p/d[TAB]
      The problem is in this code in completion_tracker::build_completion_result:
            bool completion_suppress_append
              = (suppress_append_ws ()
                 || match_list[0][strlen (match_list[0]) - 1] == ' ');
      If strlen (match_list[0]) == 0, then we access match_list[0][-1].
      Fix this by testing if the memory access is in bounds before doing the memory
      Tested on x86_64-linux.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	PR gdb/27003
      	* completer.c (completion_tracker::build_completion_result): Don't
      	access match_list[0][-1].
    • Tom Tromey's avatar
      Remove redundant typedefs · f99b5177
      Tom Tromey authored
      I was inspired by this patch of Simon's:
      ... to remove other typedefs that are no longer necessary now that gdb
      uses C++.
      I didn't remove absolutely every one -- I didn't touch the tdep files.
      However, I removed many of them.  In some cases, I removed an existing
      different struct tag.
      2020-12-04  Tom Tromey  <tromey@adacore.com>
      	* linespec.c (struct linespec_token): Rename; remove typedef.
      	* guile/scm-block.c (struct block_smob): Remove typedef.
      	(struct block_syms_progress_smob): Likewise.
      	* guile/scm-symbol.c (struct symbol_smob): Remove typedef.
      	* guile/scm-symtab.c (symtab_smob): Remove typedef.
      	(struct sal_smob): Remove typedef.
      	* guile/scm-param.c (struct param_smob): Remove typedef.
      	* guile/scm-progspace.c (struct pspace_smob): Rename.
      	* guile/scm-objfile.c (struct objfile_smob): Rename.
      	* guile/scm-iterator.c (struct iterator_smob): Rename.
      	* guile/scm-frame.c (struct frame_smob): Rename.
      	* guile/scm-arch.c (struct arch_smob): Rename.
      	* guile/scm-type.c (struct field_smob): Remove typedef.
      	(struct type_smob): Rename.
      	* guile/scm-cmd.c (struct command_smob): Remove typedef.
      	* guile/scm-ports.c (struct ioscm_memory_port): Remove typedef.
      	* guile/scm-value.c (struct value_smob): Remove typedef.
      	* guile/scm-lazy-string.c (lazy_string_smob): Remove typedef.
      	* guile/guile-internal.h (struct scheme_variable)
      	(struct scheme_function, struct scheme_integer_constant)
      	(struct gdb_smob, struct chained_gdb_smob)
      	(struct eqable_gdb_smob, arch_smob, frame_smob, iterator_smob)
      	(objfile_smob, pspace_smob, type_smob): Remove typedef.
      	* guile/scm-pretty-print.c (pretty_printer_smob): Remove typedef.
      	(struct pretty_printer_worker_smob): Remove typedef.
      	* guile/scm-exception.c (struct exception_smob): Remove typedef.
      	* python/py-block.c (struct block_object): Remove typedef.
      	(block_syms_iterator_object): Update.
      	(set_block): Update.
      	(block_syms_iterator_object): Remove typedef.
      	* python/py-inferior.c (struct membuf_object): Remove typedef.
      	* python/py-symtab.c (struct symtab_object): Remove typedef.
      	(set_symtab): Update.
      	(sal_object): Remove typedef.
      	(set_sal): Update.
      	* python/py-frame.c (frame_object): Remove typedef.
      	* python/py-record-btrace.c (struct btpy_list_object): Remove
      	* python/py-arch.c (struct arch_object): Remove typedef.
      	* python/py-linetable.c (struct linetable_entry_object)
      	(linetable_object, struct ltpy_iterator_object): Remove typedef.
      	* python/py-events.h (eventregistry_object): Remove typedef.
      	(struct events_object): Remove typedef.
      	* python/python-internal.h (gdbpy_breakpoint_object): Remove
      	(thread_object): Remove typedef.
      	* python/py-progspace.c (pspace_object): Remove typedef.
      	* python/py-value.c (struct value_object): Remove typedef.
      	* python/py-record.h (recpy_record_object): Remove typedef.
      	(struct recpy_element_object): Remove typedef.
      	* python/py-lazy-string.c (lazy_string_object): Remove typedef.
      	* python/py-objfile.c (objfile_object): Remove typedef.
      	* python/py-cmd.c (struct cmdpy_object): Remove typedef.
      	* python/py-type.c (type_object): Remove typedef.
      	(typy_iterator_object): Update.
      	(set_type): Update.
      	(field_object): Remove typedef.
      	(typy_iterator_object): Remove typedef.
      	* python/py-registers.c (register_descriptor_iterator_object):
      	Remove typedef.
      	(struct register_descriptor_object)
      	(struct reggroup_iterator_object, struct reggroup_object): Remove
      	* python/py-record.c (recpy_gap_object): Remove typedef.
      	* python/py-symbol.c (symbol_object): Remove typedef.
      	(set_symbol): Update.
      	* python/py-event.h (event_object): Remove typedef.
      	* python/py-param.c (parmpy_object): Remove typedef.
      	* python/py-instruction.c (struct py_insn_obj): Remove typedef.
      	* python/py-unwind.c (struct pending_frame_object): Remove typedef.
      	(unwind_info_object, struct cached_frame_info): Likewise.
    • Simon Marchi's avatar
      gdb/testsuite: make declare_labels use better default label names · e633b117
      Simon Marchi authored
      When using the single-element form of argument to declare_labels, the
      generated label (in the assembly file) is of the format ".LlabelN",
      where N is a number.
      I propose making it use the name of the label by default.  Calling:
          declare_labels foo
      will generate the ".LfooN" in the assembly file (again, where N is a
      number).  When debugging the output of the DWARF assembler, it makes it
      easier to map labels to the source.  Also, when defining the same label
      twice by mistake in the Tcl code (like I d id), it's easier to track the
      error from the message to the root cause:
          -/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/implptrpiece/implptrpiece-dw.S:62: Error: symbol `.Llabel5' is already defined
          +/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/implptrpiece/implptrpiece-dw.S:62: Error: symbol `.Lvar_label5' is already defined
      This doesn't change anything for the test cases, it just makes the
      assembly output a bit nicer.
      	* lib/dwarf.exp (declare_labels): Use name as text if text is
      	not provided.
      Change-Id: I63856c1fa6390498fd5b9d66f471f817ff0a465c
    • Bernd Edlinger's avatar
      Fix building gdb release from tar file without makeinfo · ab954e4a
      Bernd Edlinger authored
      Add GDBvn.texi and version.subst to the release tar file,
      so the gdb.info does not need makeinfo.
      This avoids the need for makeinfo to be available.
      2020-12-04  Bernd Edlinger  <bernd.edlinger@hotmail.de>
      	* Makefile.in: Delete GDBvn.texi and version.subst only in
      	the maintainer-clean target.
    • Shahab Vahedi's avatar
      Update gdb/ChangeLog to reflect the PR for a bug fix · 10806efd
      Shahab Vahedi authored
      This is just an update in the gdb/ChangeLog to reflect a newly
      created PR [27015] for a bugfix commit:
      10c19fad  arc: Write correct "eret" value during register collection
    • Tom Tromey's avatar
      Constify value_internal_function_name · 91f87213
      Tom Tromey authored
      I noticed that value_internal_function_name should have a const return
      type.  This patch makes this change.
      2020-12-04  Tom Tromey  <tromey@adacore.com>
      	* value.c (value_internal_function_name): Make return type const.
      	* value.h (value_internal_function_name): Make return type const.
    • Luis Machado's avatar
      Fix shifting of negative value · 5382f971
      Luis Machado authored
      When UBSan is enabled, I noticed runtime errors complaining of shifting
      of negative numbers.
      This patch fixes this by reusing existing macros from the ARM port.
      It also removes unused macros from AArch64's port.
      2020-12-04  Luis Machado  <luis.machado@linaro.org>
      	* aarch64-tdep.c (submask, bit, bits): Remove.
      	* arch/aarch64-insn.c (extract_signed_bitfield): Remove.
      	(aarch64_decode_adr, aarch64_decode_b aarch64_decode_bcond)
      	(aarch64_decode_cb, aarch64_decode_tb)
      	(aarch64_decode_ldr_literal): Use sbits to extract a signed
      	* arch/aarch64-insn.h (submask, bits, bit, sbits): New macros.
    • Tom de Vries's avatar
      [gdb/testsuite] Make gdb.arch/amd64-gs_base.exp unsupported for i386 · 67748e0f
      Tom de Vries authored
      With target board unix/-m32 I run into:
      (gdb) print /x $fs_base^M
      $1 = void^M
      (gdb) FAIL: gdb.arch/amd64-gs_base.exp: print fs_base
      The problem is that the fs_base register is not supported for i386.
      Fix this by making the test unsupported if fs_base/gs_base don't show up in
      info register sys output.
      Tested on x86_64-linux.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	PR testsuite/26990
      	* gdb.arch/amd64-gs_base.exp: Handle -m32 where fs_base and gs_base
      	are unsupported.
    • Tom de Vries's avatar
      [gdb/tdep] Handle static field in i386_16_byte_align_p · b6a6aa07
      Tom de Vries authored
      When running test-case on gdb.cp/many-args.exp with target board unix/-m32, I
      run into:
      (gdb) p check_val (ref_val, ref_val, ... , ref_val, ref_val)^M
      $1 = false^M
      (gdb) FAIL: gdb.cp/many-args.exp: check passing many structures
      The test source contains struct ss:
      typedef int v4si __attribute__ ((vector_size (16)));
      struct ss
        static v4si static_field;
        unsigned char aa;
      and i386_16_byte_align_p returns true for this type.
      Fix this by skipping static fields in i386_16_byte_align_p.
      Tested on x86_64-linux.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	PR tdep/27007
      	* i386-tdep.c (i386_16_byte_align_p): Skip static fields.
    • Tom de Vries's avatar
      [gdb/testsuite] Fix control-flow in gdb.reverse/insn-reverse.exp · a8d13675
      Tom de Vries authored
      In gdb.reverse/insn-reverse.exp, we have loop containing a call to
      gdb_test_multiple, which itself contains a break:
        for {} {$count < 500} {incr count} {
          gdb_test_multiple "x/i \$pc" "" {
      On SLE-11 with:
      $ runtest --version
      Expect version is
      Tcl version is          8.5
      Framework version is    1.4.4
      the break doesn't seem to have the effect of breaking out of the loop.
      The break does have the effect of terminating evaluation of the expect clause,
      which means we don't set insn_array, after which we run into:
      ERROR: tcl error sourcing src/gdb/testsuite/gdb.reverse/insn-reverse.exp.
      ERROR: can't read "insn_array(5)": no such element in array
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	* gdb.reverse/insn-reverse.exp: Don't break inside gdb_test_multiple
    • Tom de Vries's avatar
      [gdb/testsuite] Fix count usage in gdb.reverse/insn-reverse.exp · f17727b3
      Tom de Vries authored
      Consider the test-case gdb.reverse/insn-reverse.exp.
      After the loop setting count, the valid entries in various arrays range from 0
      to $count - 1 inclusive.
      Then $count is decremented:
             incr count -1
      after which the valid entries range from 0 to $count inclusive.
      The first subsequent loop handles that properly:
             for {set i $count} {$i >= 0} {incr i -1} {
      but the following loop does not, because it treats $count as exclusive bound:
      	for {set i 0} {$i < $count} {incr i} {
      Fix this by removing the incr, and using $count - 1 as starting value in the
      first loop.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	* gdb.reverse/insn-reverse.exp: Fix count handling.
    • Tom de Vries's avatar
      [gdb/testsuite] Fix gdb.reverse/insn-reverse-x86.c for -m32 · a1499830
      Tom de Vries authored
      When running test-case gdb.reverse/insn-reverse.exp with target board
      unix/-m32, we get:
      spawn -ignore SIGHUP gcc -fno-stack-protector -fdiagnostics-color=never \
        -c -g -m32 -o insn-reverse0.o insn-reverse.c^M
      insn-reverse-x86.c: Assembler messages:^M
      insn-reverse-x86.c:88: Error: bad register name `%r8w'^M
      Fix this by guarding x86_64 assembly in insn-reverse-x86.c with #ifdef
      Tested on x86_64-linux, with native and unix/-m32.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	* gdb.reverse/insn-reverse-x86.c: Guard x86_64 assembly with #ifdef
    • Tom de Vries's avatar
      [gdb/testsuite] Handle SIGILL in gdb.reverse/insn-reverse.exp · 9c027c2f
      Tom de Vries authored
      Consider test-case gdb.reverse/insn-reverse.exp.
      It runs a number of subtests, dependent on the architecture, f.i. for
      x86_64 it runs subtests rdrand and rdseed.
      For each subtest, it checks whether the subtest is supported and otherwise
      bails out of that subtest.
      However, there may be a problem with the support test or the information it
      relies on, and if it states that a subtest is supported while it is actually
      not, we may run into a SIGILL, as f.i. described in PR21166, which results in
      tcl errors like this:
      ERROR: tcl error sourcing src/gdb/testsuite/gdb.reverse/insn-reverse.exp.
      ERROR: can't read "insn_array(5)": no such element in array
      We can emulate this by inserting a sigfpe in function rdrand in
      insn-reverse-x86.c, like this:
        volatile int a = 0; volatile int b = 1; volatile int c = b / a;
      The problem is that the loop in the test-case attempts to stepi over of all
      insn in rdrand, but because of the signal it will never get to the last insn.
      Handle this by detecting that the stepi made no progress, and bailing out of
      the loop.
      Furthermore, make running of the subtests independent, such that a SIGILL in
      subtest rdrand does not affect running of subtest rdseed.
      Tested on x86_64-linux.
      2020-12-04  Tom de Vries  <tdevries@suse.de>
      	* gdb.reverse/insn-reverse.c (test_nr): New var.
      	(usage, parse_args): New function.
      	(main): Call parse_args.  Only run test for test_nr.
      	* gdb.reverse/insn-reverse.exp: Detect lack of progress in stepi loop
      	and bail out.  Run subtests individually, using an inferior arg
      	specifying the subtest.
    • Andreas Krebbel's avatar
      IBM Z: Add risbgz and risbgnz extended mnemonics · c524d11e
      Andreas Krebbel authored
      These two extended mnemonics are documented in the Principles of
      Operations manual but currently not supported by Binutils. They
      provide aliases for already supported instructions with the zero flag
      being set.  The flag otherwise is mingled into one of the immediate
      operands what makes asm code much harder to read.
      	* s390-opc.txt: Add risbgz and risbgnz.
      	* s390-opc.c (U6_26): New operand type.
      	(INSTR_RIE_RRUUU2, MASK_RIE_RRUUU2): New instruction format and
      	* testsuite/gas/s390/zarch-z10.s: Add tests for risbgz.
      	* testsuite/gas/s390/zarch-z10.d: Add regexp for risbgz.
      	* testsuite/gas/s390/zarch-zEC12.s: Add tests for risbgnz.
      	* testsuite/gas/s390/zarch-zEC12.d: Add regexp for risbgnz.
    • Alan Modra's avatar
      asan: readelf: memory leaks · 288f0ba2
      Alan Modra authored
      This tidies some code used by readelf, hopefully fixing some
      intermittent oss-fuzz bug reports that likely could only be reproduced
      by feeding readelf two or more object files on the command line.  The
      second and subsequent file may see non-zero state in .bss variables,
      and non-initial values in .data variables.  This patch fixes some of
      those, and moves some .data variables to .rodata.
      	* dwarf.c (frame_display_row): Do without static variable "sloc".
      	(cu_tu_indexes_read): Move to file scope.
      	(free_debug_memory): Reset it here, along with level_type_signed.
      	Free and clear a number of other static variables.
      	* readelf.c (arm_attr_public_tag <table>): Constify, updating..
      	(arm_attr_tag_*): ..all these uses.
      	(process_mips_specific): Free "rels" on error path.
    • Alan Modra's avatar
      PR26978, Inconsistency for strong foo@v1 and weak foo@@v1 · 726d7d1e
      Alan Modra authored
      Prior to this patch
        ld -shared --version-script=pr26979.ver pr26978a.o pr26978b.o
      results in
        ld: pr26978b.o: in function `foo_v1':
        (.text+0x0): multiple definition of `foo@v1'
        ld: pr26978b.o:(*IND*+0x0): multiple definition of `foo'
        ld -shared --version-script=pr26979.ver pr26978b.o pr26978a.o
      results in no error, but some odd dynamic symbols.
        ... 0 NOTYPE  GLOBAL DEFAULT    7 foo@v1
        ... 0 NOTYPE  WEAK   DEFAULT    7 foo@@v1
      When linking an undecorated reference to foo against such a shared
      library, ld complains about multiple definitions of foo@v1 while gold
      creates a dynamic reference to foo@v1.  That results in foo@v1 being
      used at runtime.
      While we could error in both cases, it is reasonable to say foo@v1 and
      foo@@v1 are in fact the same symbol.  (Same name, same version.  The
      only real difference is that foo@@v1 satisfies a reference to plain
      foo, while foo@v1 does not.)  Just as merging a weak undecorated sym
      with a strong sym results in the strong sym prevailing, so should the
      strong foo@v1 prevail.  And since there is a definition that satisfies
      plain foo, the foo@@v1 variety of dynamic symbol should be emitted at
      the foo@v1 value.  That makes the testcase that currently links
      continue to produce a shared library, and that shared library can now
      be used by both ld and gold with the same runtime behaviour as when
      using gold with the odd dynamic symbol library.
      	PR 26978
      	* elflink.c (_bfd_elf_add_default_symbol): Handle the case where
      	a new weak sym@@ver should be overridden by an existing sym@ver.
      	(elf_link_add_object_symbols): Don't _bfd_elf_add_default_symbol
      	for a new weak sym@ver when sym@@ver already exists.
      	* linker.c (link_action): Choose MIND for previous indirect,
      	current def, rather than MDEF.
      	(_bfd_generic_link_add_one_symbol <MIND>): Handle redefinition of
      	weak indirect symbol.
      	* testsuite/ld-elf/pr26978a.d,
      	* testsuite/ld-elf/pr26978a.s,
      	* testsuite/ld-elf/pr26978b.d,
      	* testsuite/ld-elf/pr26978b.s: New tests.
    • GDB Administrator's avatar
      Automatic date update in version.in · 099ee20a
      GDB Administrator authored
  2. 03 Dec, 2020 5 commits
    • Simon Marchi's avatar
      gdb: fix logic of find_comp_unit and set_comp_unit · 0bc2e38d
      Simon Marchi authored
      The logic in find_comp_unit and set_comp_unit is reversed.  When the BFD
      requires relocation, we want to put the comp_unit structure in the
      map where the comp_unit objects are not shared, that is the one indexed
      by objfile.  If the BFD does not require relocation, then, we can share
      a single comp_unit structure for all users of that BFD, so we want to
      put it in the BFD-indexed map.  The comments on top of
      dwarf2_frame_bfd_data and dwarf2_frame_objfile_data make that clear.
      Fix it by swapping the two in find_comp_unit and set_comp_unit.
      I don't have a test for this, because I don't see how to write one in a
      reasonable amount of time.
      	PR gdb/26876
      	* dwarf2/frame.c (find_comp_unit, set_comp_unit): Reverse use of
      	dwarf2_frame_bfd_data and dwarf2_frame_objfile_data.
      Change-Id: I80c1ee7ad8425fa4947de65b170973d05f5a52ec
    • Andreas Krebbel's avatar
      IBM Z: Add support for HLASM extended mnemonics · b10b530a
      Andreas Krebbel authored
      Add extended mnemonics used in the HLASM assembler.  All of them are
      just aliases for instructions we already support and help when
      assembling code which was written for the HLASM assembler.
      The HLASM mnemonics are documented here:
      See the 'Branching with extended mnemonic codes' chapter.
      objdump will still print the existing mnemonics with the exception of
      relative nop branches (i.e. conditional branches with an empty
      condition code mask).  Now we have jnop and jgnop which will be used
      by objdump when possible.
      The same change have been applied to the LLVM assembler:
      	* s390-opc.txt: Add extended mnemonics.
      	* testsuite/gas/s390/esa-g5.s: Test new extended mnemonics.
      	* testsuite/gas/s390/esa-g5.d: Likewise.
      	* testsuite/gas/s390/esa-z900.s: Likewise.
      	* testsuite/gas/s390/esa-z900.d: Likewise.
      	* testsuite/gas/s390/zarch-z900.s: Likewise.
      	* testsuite/gas/s390/zarch-z900.d: Likewise.
      	* testsuite/ld-s390/tlsbin_64.dd: The newly added jgnop mnemonic
      	replaces long relative branches with empty condition code mask.
    • Maciej W. Rozycki's avatar
      VAX/LD/testsuite: Wrap excessively long lines · 9a5c1ed8
      Maciej W. Rozycki authored
      A couple of lines in the vax-elf.exp test script exceed 80 characters;
      wrap them.
      	* testsuite/ld-vax-elf/vax-elf.exp: Wrap excessively long lines
    • Alan Modra's avatar
      [GOLD] PR26936 test · c6162010
      Alan Modra authored
      Fails if you configure with --disable-x86-used-note.  Fix that.
      	* testsuite/Makefile.am (pr26936a.o): Pass -mx86-used-note=yes.
      	(pr26936b.o, pr26936c.o, pr26936d.o): Likewise.
      	* testsuite/Makefile.in: Regenerate.
    • GDB Administrator's avatar
      Automatic date update in version.in · 317c8bbc
      GDB Administrator authored
  3. 02 Dec, 2020 7 commits
    • Hans-Peter Nilsson's avatar
      testsuite/ld-elf/pr26936.d: Pass -W. · 5f410aa5
      Hans-Peter Nilsson authored
      Required for the expected "CU:" to be emitted for long
      source-paths.  See binutils/dwarf.c:
       if (do_wide || strlen (directory) < 76)
         printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
         printf ("%s:\n", file_table[0].name);
    • Andrew Burgess's avatar
      gdb/riscv: rewrite target description validation, add rv32e support · 25428040
      Andrew Burgess authored
      This commit started as adding rv32e support to gdb.  The rv32e
      architecture is a cut-down rv32i, it only has 16 x-registers compared
      to the usual 32, and an rv32e target should not have any floating
      point registers.
      In order to add this I needed to adjust the target description
      validation checks that are performed from riscv_gdbarch_init, and I
      finally got fed up with the current scheme of doing these checks and
      rewrote this code.
      Unfortunately the rv32e changes are currently mixed in with the
      rewrite of the validation scheme.  I could split these apart if anyone
      is really interested in seeing these two ideas as separate patches.
      The main idea behind this change is that where previously I tried to
      have a purely data driven approach, a set of tables one for each
      expected feature, and then a single generic function that would
      validate a feature given a table, I have created a new class for each
      feature.  Each class has its own check member function which allows
      the logic for how to check each feature to be different.  I think the
      new scheme is much easier to follow.
      There are some other changes that I made to the validation code as
      part of this commit.
      I've relaxed some of the checks related to the floating point CSRs.
      Previously the 3 CSRs fflags, frm, and fcsr all had to be present in
      either the fpu feature or the csr feature.  This requirement is now
      relaxed, if the CSRs are not present then gdb will not reject the
      target description.  My thinking here is that there's no gdb
      functionality that specifically requires these registers, and so, if a
      target offers a description without these registers nothing else in
      gdb should stop working.
      And as part of the rv32e support targets now only have to provide the
      first 16 x-registers and $pc.  The second half of the x-registers (x16
      -> x31) are now optional.
      	* arch/riscv.c: Include 'rv32e-xregs.c'.
      	(riscv_create_target_description): Update to handle rv32e.
      	* arch/riscv.h (struct riscv_gdbarch_features) <embedded>: New
      	member variable.
      	<operator==>: Update to account for new field.
      	<hash>: Likewise.
      	* features/Makefile (FEATURE_XMLFILES): Add riscv/rv32e-xregs.xml.
      	* features/riscv/rv32e-xregs.c: Generated.
      	* features/riscv/rv32e-xregs.xml: New file.
      	* riscv-tdep.c (riscv_debug_breakpoints): Move from later in the
      	(riscv_debug_infcall): Likewise.
      	(riscv_debug_unwinder): Likewise.
      	(riscv_debug_gdbarch): Likewise.
      	(enum riscv_register_required_status): Delete.
      	(struct riscv_register_feature): Add constructor, delete default
      	constructor, copy, and assign constructors.
      	(struct riscv_register_feature::register_info) <required>: Delete.
      	<check>: Update comment and arguments.
      	(struct riscv_register_feature) <name>: Change to member function.
      	<prefer_first_name>: Delete.
      	<tdesc_feature>: New member function.
      	<registers>: Rename to...
      	<m_registers>: ...this.
      	<m_feature_name>: New member variable.
      	(riscv_register_feature::register_info::check): Update arguments.
      	(riscv_xreg_feature): Rewrite as class, create a single static
      	instance of the class.
      	(riscv_freg_feature): Likewise.
      	(riscv_virtual_feature): Likewise.
      	(riscv_csr_feature): Likewise.
      	(riscv_create_csr_aliases): Has become a member function inside
      	riscv_csr_feature class.
      	(riscv_abi_embedded): New function definition.
      	(riscv_register_name): Adjust to use new feature objects.
      	(struct riscv_call_info) <riscv_call_info>: Check for rv32e abi,
      	and adjust available argument registers.
      	(riscv_features_from_gdbarch_info): Check for EF_RISCV_RVE flag.
      	(riscv_check_tdesc_feature): Delete.
      	(riscv_tdesc_unknown_reg): Adjust to use new feature objects.
      	(riscv_gdbarch_init): Delete target description checking code, and
      	instead call to the new feature objects to perform the checks.
      	Reorder handling of no abi information case, allows small code
      	(_initialize_riscv_tdep): Remove call, this is now done in the
      	riscv_csr_feature constructor.
      	* riscv-tdep.h (riscv_abi_embedded): Declare.
    • Andrew Burgess's avatar
      gdb/riscv: remove csr aliases created with DECLARE_CSR_ALIAS · 533b2ae0
      Andrew Burgess authored
      In this commit:
        commit 767a879e
        Date:   Tue Jun 9 17:38:30 2020 +0100
            gdb/riscv: Improved register alias name creation
      RISC-V GDB was changed to make use of the DECLARE_CSR_ALIAS macro to
      define register aliases for some CSRs.  Actually, only one alias was
      created 'dscratch' as an alias for 'dscratch0'.  All of the other
      DECLARE_CSR_ALIAS lines (from include/opcode/riscv-opc.h) were
      filtered out.
      In this commit:
        commit 08ccfccf
        Date:   Mon Jun 8 10:54:53 2020 +0800
            RISC-V: Support debug and float CSR as the unprivileged ones.
      Changes were made to include/opcode/riscv-opc.h so that GDB no longer
      created even the dscratch alias.
      This caused a test failure in gdb.arch/riscv-tdesc-regs.exp.
      In looking at how to address this failure I think that the best
      strategy is, for now at least, to just remove the code that tries to
      create aliases with DECLARE_CSR_ALIAS.
      My thoughts are that:
        1. At least some of the aliases are for CSRs where the register now
        has a completely different use.  Being able to reference the CSR
        using a completely inappropriate name just seems confusing.  This
        was solved by the filtering added in the first commit referenced
        above.  But we certainly don't want to blindly add all aliases.
        2. Names presented in a target description are always honoured, so
        if a user has a legacy target then they should just start sending a
        target description with their legacy register names in, this problem
        is then solved.
        3. It's easy enough to figure out which CSRs a target has with the
        info registers command, so missing an alias shouldn't be a big
        4.  Allowing users to use names for registers that differ from the
        names the target announces doesn't feel like a critical feature.  If
        in the future targets want multiple names for a register then maybe
        we could/should extend target descriptions to allow the target to
        send aliases as well as the primary name.... but that can wait for
        another day.
      So in this commit I remove the use of DECLARE_CSR_ALIAS, and remove
      the test that was failing.
      	* riscv-tdep.c (riscv_create_csr_aliases): Remove use of
      	* gdb.arch/riscv-tdesc-regs.exp: Remove unwanted test.
    • Andrew Burgess's avatar
      gdb/riscv: place unknown csrs into the correct register groups · e4502042
      Andrew Burgess authored
      Unknown riscv CSRs should not be in the 'general' group, but should be
      in the system and csr register groups.
      To see this in action connect to QEMU, this target advertises two
      registers dscratch and mucounteren which are unknown to GDB (these are
      legacy CSRs).  Before this commit these registers would show up in the
      output of:
        (gdb) info registers
        dscratch       Could not fetch register "dscratch"; remote failure reply 'E14'
        mucounteren    Could not fetch register "mucounteren"; remote failure reply 'E14'
      Ignore the errors, this is just a QEMU annoyance, it advertises these
      CSRs, but doesn't actually let GDB read them.  These registers don't
      show up in the output of either:
        (gdb) info registers csr
        (gdb) info registers system
      After this commit this situation is reveresed, which makes more sense
      to me.
      	* riscv-tdep.c (riscv_is_unknown_csr): New function,
      	implementation moved from riscv_register_reggroup_p.
      	(riscv_register_reggroup_p): Update group handling for unknown
      	* gdb.arch/riscv-tdesc-regs.exp (get_expected_result): New proc,
      	update test to use this.
    • Enze Li's avatar
      Add gnu global outputs to .gitignore · 7ddfb1a8
      Enze Li authored
      GNU Global outputs can be safely ignored.
      2020-12-02  Enze Li  <lienze2010@hotmail.com>
      	* .gitignore: Add gnu global outputs.
      Change-Id: I04ce68ab3279426195793adb56f834a34ee72ea2
    • Simon Marchi's avatar
      Sync .gitignore with gcc · 12bf6525
      Simon Marchi authored
      Bring in a few lines that are in gcc's .gitignore but not binutils-gdb's
      	* .gitignore: Sync with gcc.
      Change-Id: I8900ddfbb5ab8cce6236e1905fdbb52fb4c291e2
    • Sergio Durigan Junior's avatar
      Search for DWZ files in debug-file-directories as well · 2bf3b79d
      Sergio Durigan Junior authored
      When Debian (and Ubuntu) builds its binaries, it (still) doesn't use
      dwz's "--relative" option.  This causes their debuginfo files to
      carry a .gnu_debugaltlink section containing a full pathname to the
      DWZ alt debug file, like this:
        $ readelf -wk /usr/bin/cat
        Contents of the .gnu_debugaltlink section:
          Separate debug info file: /usr/lib/debug/.dwz/x86_64-linux-gnu/coreutils.debug
          Build-ID (0x14 bytes):
         ee 76 5d 71 97 37 ce 46 99 44 32 bb e8 a9 1a ef 99 96 88 db
        Contents of the .gnu_debuglink section:
          Separate debug info file: 06d3bee37b8c7e67b31cb2689cb351102ae73b.debug
          CRC value: 0x53267655
      This usually works OK, because most of the debuginfo files installed
      via apt will be present in /usr/lib/debug anyway.  However, imagine
      the following scenario:
      - You are using /usr/bin/cat, it crashes on you and generates a
      - You don't want/need to "apt install" the debuginfo file for
        coreutils from the repositories.  Instead, you already have the
        debuginfo files in a separate directory (e.g., $HOME/dbgsym).
      - You start GDB and "set debug-file-directory $HOME/dbgsym/usr/lib/debug".
        You then get the following message:
        $ gdb -ex 'set debug-file-directory ./dbgsym/usr/lib/debug' -ex 'file /bin/cat' -ex 'core-file ./cat.core'
        GNU gdb (Ubuntu 10.1-0ubuntu1) 10.1
        Reading symbols from /bin/cat...
        Reading symbols from /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug...
        could not find '.gnu_debugaltlink' file for /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id/bc/06d3bee37b8c7e67b31cb2689cb351102ae73b.debug
      This error happens because GDB is trying to locate the build-id
      link (inside /home/sergio/gdb/dbgsym/usr/lib/debug/.build-id) for the
      DWZ alt debug file, which doesn't exist.  Arguably, this is a problem
      with how dh_dwz works in Debian, and it's something I'm also planning
      to tackle.  But, back at the problem at hand.
      Besides not being able to find the build-id link in the directory
      mentioned above, GDB also tried to open the DWZ alt file using its
      filename.  The problem here is that, since we don't have the distro's
      debuginfo installed, it can't find anything under /usr/lib/debug that
      satisfies it.
      It occurred to me that a good way to workaround this problem is to
      actually try to locate the DWZ alt debug file inside the
      debug-file-directories (that were likely provided by the user).  So
      this is what the proposed patch does.
      The idea here is simple: get the filename extracted from the
      .gnu_debugaltlink section, and manipulate it in order to replace the
      initial part of the path (everything before "/.dwz/") by whatever
      debug-file-directories the user might have provided.
      I talked with Mark Wielaard and he agrees this is a sensible approach.
      In fact, apparently this is something that eu-readelf also does.
      I regtested this code, and no regressions were found.
      2020-12-01  Sergio Durigan Junior  <sergiodj@sergiodj.net>
      	* dwarf2/read.c (dwz_search_other_debugdirs): New function.
      	(dwarf2_get_dwz_file): Convert 'filename' to a
      	std::string.  Use dwz_search_other_debugdirs to search for DWZ
      	files in the debug-file-directories provided by the user as well.