After implementing the new linux-kernel target and preparing s390-tdep.
It is now time to get everything to work. Thus implement the hooks
required by the linux-kernel target and enable s390's privileged
registers.
gdb/ChangeLog:
* s390-lk-tdep.h: New file.
* s390-lk-tdep.c: New file.
* Makefile.in (ALL_TARGET_OBS): Add s390-lk-tdep.o.
(HFILES_NO_SRCDIR): Add s390-lk-tdep.h.
(ALLDEPFILES): Add s390-lk-tdep.c.
* configure.tgt (s390*-*-linux*): Add s390-lk-tdep.o.
* s390-tdep.h: Define macros for address translation.
* s390-tdep.c (s390-lk-tdep.h): New include.
(s390_iterate_over_regset_sections): Enable privileged registers.
(s390_core_read_description): Enable privileged registers.
(s390_gdbarch_init): : Enable privileged registers and adjust.
The Linux kernel and thus the linux-kernel target needs access to S390x's
privileged registers. Define new features and prepare s390-tdep.* to use
them in new Linux kernel code.
gdb/ChangeLog:
* features/s390-cr.xml: New file.
* features/s390x-cr-linux64.xml: New file
* features/s390x-vxcr-linux64.xml: New file
* features/Makefile: Add s390x-cr-linux64-expedite and
s390x-vxcr-linux64-expedite
(WICH): Add s390x-cr-linux64.xml and s390x-vxcr-linux64.xml
(XMLTOC): Add s390x-cr-linux64.xml and s390x-vxcr-linux64.xml
* features/s390x-cr-linux64.c: Generated.
* features/s390x-vxcr-linux64.c: Generated.
* regformats/s390x-cr-linux64.dat: Generated.
* regformats/s390x-vxcr-linux64.dat: Generated.
* s390-tdep.h: Define regnums for control registers.
(S390_NUM_REGS): Adjust.
* s390-tdep.c: (s390_dwarf_regmat): Add control registers.
The new linux-kernel target need some architecture dependant code. To
prepare for this split up the existing s390 code into a general s390-tedep
and a GDNU/Linux (user space) specific s390-linux-tdep. This keeps the
files manageable and allows for kernel specific code e.g. unwinder.
gdb/ChangeLog:
* s390-tdep.h: New file.
* s390-tdep.c: New file.
* Makefile.in (ALL_TARGET_OBS): Add s390-tdep.o.
(HFILES_NO_SRCDIR): Add s390-tdep.h.
(ALLDEPFILES): Add s390-tdep.c.
* configure.tgt (s390*-*-linux*): Add s390-tdep.o.
* s390-linux-tdep.h: Move defines for hardware capabilities and
register informations to s390-tdep.h.
(s390_gdbarch_linux_init): New export.
(s390_upper_registers): New export.
* s390-linux-tdep.c: Remove unneeded includes and sort alphabetically.
(s390-tdep.h): New include.
(s390_upper_regset): Remove static.
(s390_gdbarch_init): Rename to...
(s390_gdbarch_linux_init): ...this and adjust.
(_initialize_s390_tdep): Rename to...
(_initialize_s390_linux_tdep): ...this and adjust.
(s390_abi_kind, s390_vector_abi_kind): Move to s390-tdep.h
(gdbarch_tdep, enum named opcodes): Move to s390-tdep.h
(s390_readinstruction, is_ri, is_ril): Move to s390-tdep.c
(is_rr, is_rre, is_rs, is_rsy, is_rsi, is_rie): Move to s390-tdep.c
(is_rx, is_rxy, s390_break_insn): Move to s390-tdep.c
(s390_breakpoint, s390_is_partial_instruction): Move to s390-tdep.c
(s390_software_single_step, s390_prologue_data): Move to s390-tdep.c
(s390_addr, s390_store, s390_load): Move to s390-tdep.c
(s390_check_for_saved, s390_analyze_prologue): Move to s390-tdep.c
(s390_skip_prologue, s390_register_call_saved): Move to s390-tdep.c
(s390_register_name, s390_cannot_store_register): Move to s390-tdep.c
(s390_write_pc, s390_dwarf_regmap): Move to s390-tdep.c
(s390_dwarf_reg_to_regnum, regnum_is_gpr_full): Move to s390-tdep.c
(regnum_is_vxr_full, s390_value_from_register): Move to s390-tdep.c
(s390_core_read_description): Move to s390-tdep.c
(s390_iterate_over_regset_sections): Move to s390-tdep.c
(s390_pseudo_register_name): Move to s390-tdep.c
(s390_pseudo_register_read): Move to s390-tdep.c
(s390_pseudo_register_write): Move to s390-tdep.c
(s390_pseudo_register_type): Move to s390-tdep.c
(s390_pseudo_register_reggroup_p): Move to s390-tdep.c
(s390_ax_pseudo_register_collect): Move to s390-tdep.c
(s390_ax_pseudo_register_push_stack): Move to s390-tdep.c
(s390_gen_return_address): Move to s390-tdep.c
(s390_unwind_pseudo_register): Move to s390-tdep.c
(s390_effective_inner_type): Move to s390-tdep.c
(s390_function_arg_float): Move to s390-tdep.c
(s390_function_arg_vector, is_power_of_two): Move to s390-tdep.c
(s390_function_arg_integer, s390_arg_state): Move to s390-tdep.c
(s390_handle_arg, s390_push_dummy_call): Move to s390-tdep.c
(s390_dummy_id, s390_register_return_value): Move to s390-tdep.c
(s390_return_value, s390_stack_frame_destroyed_p): Move to s390-tdep.c
(s390_dwarf2_prev_register): Move to s390-tdep.c
(s390_dwarf2_frame_init_reg): Move to s390-tdep.c
(s390_adjust_frame_regnum, s390_unwind_cache): Move to s390-tdep.c
(s390_prologue_frame_unwind_cache): Move to s390-tdep.c
(s390_stub_unwind_cache): Move to s390-tdep.c
(s390_stub_frame_unwind_cache): Move to s390-tdep.c
(s390_stub_frame_this_id): Move to s390-tdep.c
(s390_trad_frame_prev_register): Move to s390-tdep.c
(s390_stub_frame_prev_register): Move to s390-tdep.c
(s390_stub_frame_sniffer, s390_stub_frame_unwind): Move to s390-tdep.c
(s390_sigtramp_unwind_cache): Move to s390-tdep.c
(s390_sigtramp_frame_unwind_cache): Move to s390-tdep.c
(s390_sigtramp_frame_this_id): Move to s390-tdep.c
(s390_sigtramp_frame_prev_register): Move to s390-tdep.c
(s390_sigtramp_frame_sniffer): Move to s390-tdep.c
(s390_sigtramp_frame_unwind): Move to s390-tdep.c
(s390_backchain_frame_unwind_cache): Move to s390-tdep.c
(s390_frame_unwind_cache, s390_frame_this_id): Move to s390-tdep.c
(s390_frame_prev_register, s390_frame_unwind): Move to s390-tdep.c
(s390_frame_base_address): Move to s390-tdep.c
(s390_local_base_address, s390_frame_base): Move to s390-tdep.c
(s390_unwind_pc, s390_unwind_sp): Move to s390-tdep.c
(is_non_branch_ril): Move to s390-tdep.c
(s390_displaced_step_copy_insn): Move to s390-tdep.c
(s390_displaced_step_fixup): Move to s390-tdep.c
(s390_displaced_step_hw_singlestep): Move to s390-tdep.c
(s390_addr_bits_remove): Move to s390-tdep.c
(s390_address_class_type_flags): Move to s390-tdep.c
(s390_address_class_type_flags_to_name): Move to s390-tdep.c
(s390_address_class_name_to_type_flags): Move to s390-tdep.c
This patch implements a "lsmod", "struct" and, "offset" command to work with
the new linux-kernel target. The commands are a handy byproduct from
development and crude hacks. I don't expect them to be accepted in the
current state. Nevertheless there needs to be an discussion on how and
where (see gdb/python scrips in kernel sources) to implement them. So here
is the start for it.
gdb/Changelog:
* lk-cmds.h: New file.
* lk-cmds.c: New file.
* lk-low.c: Include lk-cmds.h.
(lk_try_push_target): Init commands.
* typeprint.c: Remove unnecessary forward declarations.
(whatis_exp): Remove static.
* typeprint.h (whatis_exp): New export.
* Makefile.in (SFILES, ALLDEPFILES): Add lk-cmds.c.
(HFILES_NO_SRCDIR): Add lk-cmds.h.
(ALL_TARGET_OBS): Add lk-cmds.o.
* configure.tgt (lk_target_obs): Add lk-cmds.o.
This patch implements module support for the new linux-kernel target by
adding a target_so_ops. In addition this patch adds handling for kernel
virtual addresses. This is necessary because kernel modules, unlike
task_structs, live in kernel virtual address space. Thus addresses need
to be translated before they can be read from. We achieve this by adding
an implementation for the targets to_xfer_partial hook, which translates
the addresses before passing them down to the target beneath.
gdb/ChangeLog:
* lk-modules.h: New file.
* lk-modules.c: New file.
* lk-low.h (lk_hook_is_kvaddr, lk_hook_vtop)
(lk_hook_get_module_text_offset): New arch dependent hooks.
(sturct lk_private_hooks): Add new hooks.
(LK_MODULES_NAME_LEN, LK_UTS_NAME_LEN): New define.
* lk-low.c (lk-modules.h): New include.
(lk_kvtop, restore_current_target, lk_xfer_partial): New functions.
(lk_init_private_data): Declare needed debug symbols.
(lk_try_push_target): Assert for new hooks and set solib_ops.
(init_linux_kernel_ops): Add implementation for to_xfer_partial.
* solib.c (get_solib_search_path): New function.
* solib.h (get_solib_search_path): New export.
* Makefile.in (SFILES, ALLDEPFILES): Add lk-modules.c.
(HFILES_NO_SRCDIR): Add lk-modules.h.
(ALL_TARGET_OBS): Add lk-modules.o.
* configure.tgt (lk_target_obs): Add lk-modules.o.
This patch implements a basic target_ops for Linux kernel support. In
particular it models Linux tasks as GDB threads such that you are able to
change to a given thread, get backtraces, disassemble the current frame
etc..
Currently the target_ops is designed only to work with static targets, i.e.
dumps. Thus it lacks implementation for hooks like to_wait, to_resume or
to_store_registers. Furthermore the mapping between a CPU and the
task_struct of the running task is only be done once at initialization. See
cover letter for a detailed discussion.
Nevertheless i made some design decisions different to Peter [1] which are
worth discussing. Especially storing the private data in a htab (or
std::unordered_map if i had the time...) instead of global variables makes
the code much nicer and less memory consuming.
[1] https://sourceware.org/ml/gdb-patches/2016-12/msg00382.html
gdb/ChangeLog:
* gdbarch.sh (lk_init_private): New hook.
* gdbarch.h: Regenerated.
* gdbarch.c: Regenerated.
* lk-low.h: New file.
* lk-low.c: New file.
* lk-lists.h: New file.
* lk-lists.c: New file.
* Makefile.in (SFILES, ALLDEPFILES): Add lk-low.c and lk-lists.c.
(HFILES_NO_SRCDIR): Add lk-low.h and lk-lists.h.
(ALL_TARGET_OBS): Add lk-low.o and lk-lists.o.
* configure.tgt (lk_target_obs): New variable with object files for Linux
kernel support.
(s390*-*-linux*): Add lk_target_obs.
This commit adds concat_path function to concatenate an arbitrary number of
path elements. The function automatically adds an directory separator between
two elements as needed.
gdb/ChangeLog:
* common/common-utils.h (endswith): New function.
* utils.c (_concat_path, approx_path_length): New function.
* utils.h (_concat_path): New export.
(concat_path): New define.
Simplify the code of utils.c:substiute_path_component by converting it to C++.
gdb/ChangeLog:
* utils.c (substitute_path_component): Convert to C++.
* utils.h (substitute_path_componetn): Adjust declatation.
* auto-load.c (auto_load_expand_dir_vars): Adjust.
The expectation in gdb.cp/m-static.exp for the ptype of
single_constructor is to get in the result of destructor with the
following prototype: ~single_constructor(int).
Yet, m-static.cc declares the destructor as ~single_constructor(). This
commit fixes the expectation.
2017-03-16 Thomas Preud'homme <thomas.preudhomme@arm.com>
gdb/testsuite/
* gdb.cp/m-static.exp: Fix expectation for prototype of
test5.single_constructor and single_constructor::single_constructor.
In a later commit I'll be adding a new version of the ".nt" flag for an
ARC700 extension (NPS400) which does not require this same special
handling.
In this commit I have restricted the special flag handling to only apply
if we are assembling for ARCv2. This is a restructuring commit, and
there should be no user visible changes after this commit.
gas/ChangeLog:
* config/tc-arc.c (assemble_insn): Only handle ".t" and ".nt"
specially for ARCv2.
gold/
* mips.cc (Mips_got_entry::hash()): Shift addend to reduce
possibility of collisions.
(Mips_got_entry::equals): Fix case for GOT_TLS_LDM
entries.
gold/
* mips.cc (Mips_relobj::merge_processor_specific_data_): New data
member.
(Mips_relobj::merge_processor_specific_data): New method.
(Mips_relobj::do_read_symbols): Set merge_processor_specific_data_
to false, only if the input file is a binary or if object has no
contents except the section name string table and an empty symbol
table with the undefined symbol.
(Target_mips::do_finalize_sections): Refactor. Skip empty object files
for merging processor-specific data.
gold/
* mips.cc (Target_mips::Relocate::calculated_value_): New data
member.
(Target_mips::Relocate::calculate_only_): Likewise.
(Target_mips::Relocate::relocate): Handle multiple consecutive
relocations with the same offset.
gold/
* mips.cc (symbol_refs_local): Return false if a symbol
is from a dynamic object.
(Target_mips::got_section): Make _GLOBAL_OFFSET_TABLE_ STV_HIDDEN.
(Target_mips::set_gp): Refactor. Make _gp STT_NOTYPE and
STB_LOCAL.
(Target_mips::do_finalize_sections): Set _gp after all the checks
for creating .got are done.
(Target_mips::Scan::global): Remove unused code.
- They can accept 0 in imm field
2017-03-14 Kito Cheng <kito.cheng@gmail.com>
* riscv-opc.c (riscv_opcodes> <c.li>: Use the 'o' immediate encoding.
<c.andi>: Likewise.
<c.addiw> Likewise.
When inf_ptrace_xfer_partial performs a memory transfer via ptrace with
PT_READ_I, PT_WRITE_I (aka PTRACE_PEEKTEXT, PTRACE_POKETEXT), etc., then
it currently transfers at most one word. This behavior yields degraded
performance, particularly if the caller has significant preparation work
for each invocation. And indeed it has for writing, in
memory_xfer_partial in target.c, where all of the remaining data to be
transferred is copied to a temporary buffer each time, for breakpoint
shadow handling. Thus large writes have quadratic runtime and can take
hours.
Note: On GNU/Linux targets GDB usually does not use
inf_ptrace_xfer_partial for large memory transfers, but attempts a single
read/write from/to /proc/<pid>/mem instead. However, the kernel may
reject writes to /proc/<pid>/mem (such as kernels prior to 2.6.39), or
/proc may not be mounted. In both cases GDB falls back to the ptrace
mechanism.
This patch fixes the performance issue by attempting to fulfill the whole
transfer request in inf_ptrace_xfer_partial, using a loop around the
ptrace call.
gdb/ChangeLog:
PR gdb/21220
* inf-ptrace.c (inf_ptrace_xfer_partial): In "case
TARGET_OBJECT_MEMORY", extract the logic for ptrace peek/poke...
(inf_ptrace_peek_poke): ...here. New function. Now also loop
over ptrace peek/poke until end of buffer or error.
gas/ChangeLog:
2017-03-02 Kuan-Lin Chen <rufus@andestech.com>
* config/tc-riscv.c (md_apply_fix): Set fx_frag and
fx_next->fx_frag for CFA_advance_loc relocations.
Since BFD64 may be used on 32-bit address, we need to apply addr_mask
to check VMA and LMA.
* ldlang.c (lang_check_section_addresses): Use addr_mask to
check VMA and LMA.
It isn't used anywhere else than the file it's defined in.
gdb/ChangeLog:
* parse.c (length_of_subexp): Make static.
* parser-defs.h (length_of_subexp): Remove.
* readelf.c (print_gnu_build_attribute_description): Move symbol
printing code to...
(print_symbol_for_build_attribute): New function. ...here.
Add to find the best symbol to associate with an OPEN note.
Add code to cache the symbol table and string table, so that they
are not loaded every time a note is displayed.
* testsuite/binutils-all/note-2-32.s: Add a function symbol.
* testsuite/binutils-all/note-2-64.s: Likewise.
* testsuite/binutils-all/note-2-32.d: Update expected note output.
* testsuite/binutils-all/note-2-64.d: Likewise.
An optional parameter TEST has been added to get_hexadecimal_valueof in commit:
https://sourceware.org/ml/gdb-patches/2016-06/msg00469.html
This patch adds a similar optional parameter to other related methods that
retrieve expression values: get_valueof, get_integer_valueof and get_sizeof.
Thus tests that evaluate same expression multiple times can provide custom
test names, ensuring that test names will be unique.
gdb/testsuite/ChangeLog:
2017-03-14 Anton Kolesov <anton.kolesov@synopsys.com>
* lib/gdb.exp (get_valueof, get_integer_valueof, get_sizeof):
Add optional 'test' parameter.
So far linux_proc_xfer_partial refused to handle write requests. This is
still based on the assumption that the Linux kernel does not support
writes to /proc/<pid>/mem. That used to be true, but has changed with
Linux 2.6.39 released in May 2011.
This patch lifts this restriction and now exploits /proc/<pid>/mem for
writing to inferior memory as well, if possible.
gdb/ChangeLog:
* linux-nat.c (linux_proc_xfer_partial): Handle write operations
as well.
Commit c8b23b3f89 ("Add constructor and destructor to
demangle_parse_info") a while ago broke the "test-cp-name-parser"
build:
$ make test-cp-name-parser
[...]
src/gdb/cp-name-parser.y: In function ‘int main(int, char**)’:
src/gdb/cp-name-parser.y:2190:9: error: cannot convert ‘std::unique_ptr<demangle_parse_info>’ to ‘demangle_parse_info*’ in assignment
result = cp_demangled_name_to_comp (str2, &errmsg);
^
src/gdb/cp-name-parser.y:2199:38: error: ‘cp_demangled_name_parse_free’ was not declared in this scope
cp_demangled_name_parse_free (result);
^
src/gdb/cp-name-parser.y:2211:14: error: cannot convert ‘std::unique_ptr<demangle_parse_info>’ to ‘demangle_parse_info*’ in assignment
result = cp_demangled_name_to_comp (argv[arg], &errmsg);
^
src/gdb/cp-name-parser.y:2219:43: error: ‘cp_demangled_name_parse_free’ was not declared in this scope
cp_demangled_name_parse_free (result);
^
Makefile:2107: recipe for target 'test-cp-name-parser.o' failed
make: *** [test-cp-name-parser.o] Error 1
This commit restores it.
gdb/ChangeLog:
2017-03-14 Pedro Alves <palves@redhat.com>
* cp-name-parser.y (cp_demangled_name_to_comp): Update comment.
(main): Use std::unique_ptr. Remove calls to
cp_demangled_name_parse_free.
gdb/ChangeLog:
* amd64-linux-nat.c (amd64_linux_fetch_inferior_registers,
amd64_linux_fetch_inferior_registers): Use regcache->ptid
instead of inferior_ptid.
We are currently assuming that regcache->ptid is equal to inferior_ptid
when we call target_fetch/store_registers. These asserts just validate
that assumption. Also, since the following patches will change target
code to use regcache->ptid instead of inferior_ptid, asserting that they
are the same should ensure that our changes don't have any unintended
consequences.
gdb/ChangeLog:
* target.c (target_fetch_registers, target_store_registers): Add
assert.
This patch introduces the regcache_get_ptid function, which can be used
to retrieve the ptid a regcache is connected to. It is used in
subsequent patches.
gdb/ChangeLog:
* regcache.h (regcache_get_ptid): New function.
* regcache.c (regcache_get_ptid): New function.