Commit Graph

552 Commits

Author SHA1 Message Date
Tom Tromey e11fb955fb Remove long_long_align_bit gdbarch attribute
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-30 11:25:32 -06:00
Tom Tromey 2b4424c35b Add initial type alignment support
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-30 11:25:30 -06:00
Markus Metzger 1d509aa625 infrun: step through indirect branch thunks
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-04-13 10:44:47 +02:00
Tom Tromey 281d762b1a Remove cleanups from check_fast_tracepoint_sals
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*.
2018-02-24 10:01:11 -07:00
Yao Qi c113ed0ca2 Pass readable_regcache to gdbarch method read_pc
We can pass readable_regcache to gdbarch method read_pc where it is
allowed to do read from regcache.

gdb:

2018-02-21  Yao Qi  <yao.qi@linaro.org>

	* avr-tdep.c (avr_read_pc): Change parameter type to
	readable_regcache.
	* gdbarch.sh (read_pc): Likewise.
	* gdbarch.c: Re-generated.
	* gdbarch.h: Re-generated.
	* hppa-tdep.c (hppa_read_pc): Change parameter type to
	readable_regcache.
	* ia64-tdep.c (ia64_read_pc): Likewise.
	* mips-tdep.c (mips_read_pc): Likewise.
	* spu-tdep.c (spu_read_pc): Likewise.
2018-02-21 11:20:03 +00:00
Yao Qi 849d0ba802 class readable_regcache and pass readable_regcache to gdbarch pseudo_register_read and pseudo_register_read_value
pseudo registers are either from raw registers or memory, so
gdbarch methods pseudo_register_read and pseudo_register_read_value
should have regcache object which only have read methods.  In other
words, we should disallow writing to regcache in these two gdbarch
methods.  In order to apply this restriction, this patch adds a new
class readable_regcache, derived from reg_buffer, and it only has
raw_read and cooked_read methods.  regcache is derived from
readable_regcache.  This patch also passes readable_regcache instead of
regcache to gdbarch methods pseudo_register_read and
pseudo_register_read_value.

This patch moves raw_read* and cooked_read* methods to readable_regcache,
which is straightforward.  One thing not straightforward is that I split
regcache::xfer_part to readable_regcache::read_part and regcache::write_part,
because readable_regcache can only have methods to read.

readable_regcache is an abstract base class, and it has a pure virtual
function raw_update, because I don't want readable_regcache know where
these raw registers are from.  They can be from either the target
(readwrite regcache) or the regcache itself (readonly regcache).

gdb:

2018-02-21  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c (aarch64_pseudo_register_read_value): Change
	parameter type to 'readable_regcache *'.
	* amd64-tdep.c (amd64_pseudo_register_read_value): Likewise.
	* arm-tdep.c (arm_neon_quad_read): Likewise.
	(arm_pseudo_read): Likewise.
	* avr-tdep.c (avr_pseudo_register_read): Likewise.
	* bfin-tdep.c (bfin_pseudo_register_read): Likewise.
	* frv-tdep.c (frv_pseudo_register_read): Likewise.
	* gdbarch.c: Re-generated.
	* gdbarch.h: Re-generated.
	* gdbarch.sh (pseudo_register_read): Change parameter type to
	'readable_regcache *'.
	(pseudo_register_read_value): Likewise.
	* h8300-tdep.c (pseudo_from_raw_register): Likewise.
	(h8300_pseudo_register_read): Likewise.
	* hppa-tdep.c (hppa_pseudo_register_read): Likewise.
	* i386-tdep.c (i386_mmx_regnum_to_fp_regnum): Likewise.
	(i386_pseudo_register_read_into_value): Likewise.
	(i386_pseudo_register_read_value): Likewise.
	* i386-tdep.h (i386_pseudo_register_read_into_value): Update
	declaration.
	* ia64-tdep.c (ia64_pseudo_register_read): Likewise.
	* m32c-tdep.c (m32c_raw_read): Likewise.
	(m32c_read_flg): Likewise.
	(m32c_banked_register): Likewise.
	(m32c_banked_read): Likewise.
	(m32c_sb_read): Likewise.
	(m32c_part_read): Likewise.
	(m32c_cat_read): Likewise.
	(m32c_r3r2r1r0_read): Likewise.
	(m32c_pseudo_register_read): Likewise.
	* m68hc11-tdep.c (m68hc11_pseudo_register_read): Likewise.
	* mep-tdep.c (mep_pseudo_cr32_read): Likewise.
	(mep_pseudo_cr64_read): Likewise.
	(mep_pseudo_register_read): Likewise.
	* mips-tdep.c (mips_pseudo_register_read): Likewise.
	* msp430-tdep.c (msp430_pseudo_register_read): Likewise.
	* nds32-tdep.c (nds32_pseudo_register_read): Likewise.
	* regcache.c (regcache::raw_read): Move it to readable_regcache.
	(regcache::cooked_read): Likewise.
	(regcache::cooked_read_value): Likewise.
	(regcache_cooked_read_signed):
	(regcache::cooked_read): Likewise.
	* regcache.h (readable_regcache): New class.
	(regcache): Inherit readable_regcache.  Move some methods to
	readable_regcache.
	* rl78-tdep.c (rl78_pseudo_register_read): Change
	parameter type to 'readable_regcache *'.
	* rs6000-tdep.c (do_regcache_raw_read): Remove.
	(e500_pseudo_register_read): Change parameter type to
	'readable_regcache *'.
	(dfp_pseudo_register_read): Likewise.
	(vsx_pseudo_register_read): Likewise.
	(efpr_pseudo_register_read): Likewise.
	* s390-tdep.c (s390_pseudo_register_read): Likewise.
	* sh-tdep.c (sh_pseudo_register_read): Likewise.
	* sh64-tdep.c (pseudo_register_read_portions): Likewise.
	(sh64_pseudo_register_read): Likewise.
	* sparc-tdep.c (sparc32_pseudo_register_read): Likewise.
	* sparc64-tdep.c (sparc64_pseudo_register_read): Likewise.
	* spu-tdep.c (spu_pseudo_register_read_spu): Likewise.
	(spu_pseudo_register_read): Likewise.
	* xtensa-tdep.c	(xtensa_register_read_masked): Likewise.
	(xtensa_pseudo_register_read): Likewise.
2018-02-21 11:20:03 +00:00
Joel Brobecker e2882c8578 Update copyright year range in all GDB files
gdb/ChangeLog:

        Update copyright year range in all GDB files
2018-01-02 07:38:06 +04:00
Yao Qi a738ea1d41 Clear non-significant bits of address on memory access
ARMv8 supports tagged address, that is, the top one byte in address
is ignored.  It is always enabled on aarch64-linux.  See
https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt

The tag in the tagged address is modeled as non-significant bits in
address, so this patch adds a new gdbarch method significant_addr_bit and
clear the non-significant bits (the top byte in ARMv8) of the virtual
address at the point before passing address to target cache layer.  IOW,
the address used in the target cache layer is already cleared.

Before this patch,
(gdb) x/x 0x0000000000411030
0x411030 <global>:	0x00000000
(gdb) x/x 0xf000000000411030
0xf000000000411030:	Cannot access memory at address 0xf000000000411030

After this patch,

(gdb) x/x 0x0000000000411030
0x411030 <global>:	0x00000000
(gdb) x/x 0xf000000000411030
0xf000000000411030:	0x00000000

Note that I used address_significant in paddress, but it causes a
regression gdb.base/long_long.exp, because gdb clears the non-significant
bits in address, but test still expects them.

p/a val.oct^M
$24 = 0x2ee53977053977^M
(gdb) FAIL: gdb.base/long_long.exp: p/a val.oct

so I defer the change there.

gdb:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c (aarch64_gdbarch_init): Install gdbarch
	significant_addr_bit.
	* gdbarch.sh (significant_addr_bit): New.
	* gdbarch.c, gdbarch.h: Re-generated.
	* target.c (memory_xfer_partial): Call address_significant.
	* utils.c (address_significant): New function.
	* utils.h (address_significant): Declare.

2017-12-08  Yao Qi  <yao.qi@linaro.org>

gdb/testsuite:

	* gdb.arch/aarch64-tagged-pointer.c: New file.
	* gdb.arch/aarch64-tagged-pointer.exp: New file.
2017-12-08 17:27:03 +00:00
Simon Marchi c2508e905f Remove simple_displaced_step_copy_insn
Nothing uses this function.  Remove it, and adjust comments referring to
it.

gdb/ChangeLog:

	* arch-utils.h (simple_displaced_step_copy_insn): Remove.
	* arch-utils.c (simple_displaced_step_copy_insn): Remove.
	* gdbarch.sh (displaced_step_copy_insn): Adjust comment.
	* gdbarch.h: Regenerate.
	* i386-linux-tdep.c (i386_linux_displaced_step_copy_insn):
	Adjust comment.
	* i386-tdep.c (i386_displaced_step_copy_insn): Adjust comment.
	(i386_displaced_step_fixup): Adjust comment.
	* rs6000-tdep.c (ppc_displaced_step_copy_insn): Adjust comment.
2017-10-12 21:42:23 -04:00
Maciej W. Rozycki fe22022617 GDB: Remove Linux core PRPSINFO note writer override
Revert parts of commit b3ac9c7756 ("Put more info in NT_PRPSINFO Linux
notes"), <https://sourceware.org/ml/binutils/2013-02/msg00024.html>, and
remove support for a Linux core PRPSINFO note writer override, now that
all variants are handled automatically within BFD itself.

	gdb/
	* linux-tdep.c (linux_make_corefile_notes): Remove call to
	`gdbarch_elfcore_write_linux_prpsinfo'.
	* gdbarch.sh (elfcore_write_linux_prpsinfo): Remove architecture
	method.
	(elf_internal_linux_prpsinfo): Remove declaration.
	* gdbarch.h: Regenerate.
	* gdbarch.c: Regenerate.
2017-10-11 15:01:41 +01:00
Maciej W. Rozycki db8dd1601e gdbarch: Remove duplicate `struct objfile' declaration
Remove a duplicate `struct objfile' declaration mistakenly added with
commit 3e29f34a4e ("MIPS: Keep the ISA bit in compressed code
addresses").

	gdb/
	* gdbarch.sh (objfile): Remove duplicate declaration.
	* gdbarch.h: Regenerate.
2017-10-03 23:46:28 +01:00
Maciej W. Rozycki 0dba2a6c09 gdbarch: Use an anonymous union for target data in `gdbarch_info'
As an update to commit ede5f15146 ("gdbarch.h: Change
gdbarch_info::tdep_info's type to void *") replace the definition of the
`tdep_info' member in `struct gdbarch_info' with an anonymous union,
comprising the original member, with its type reverted to `struct
gdbarch_tdep_info *', a `tdesc_data' member of a `struct tdesc_arch_data
*' type and an `id' member of an `int *' type.  Remove now unnecessary
casts throughout use places then, making code easier to read an less
prone to errors, which may happen with casting.

	gdb/
	* gdbarch.sh (gdbarch_info): Replace the `tdep_info' member with
	a union of `tdep_info', `tdesc_data' and `id'.
	* aarch64-tdep.c (aarch64_gdbarch_init): Use `info.tdesc_data'
	rather than `info.tdep_info'.
	* amd64-linux-tdep.c (amd64_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* i386-tdep.c (i386_gdbarch_init): Likewise.
	* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): Use `info.id' rather than
	`info.tdep_info'.
	(ppc_linux_init_abi): Use `info.tdesc_data' rather than
	`info.tdep_info'.
	* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
	* spu-multiarch.c (spu_gdbarch): Use `info.id' rather than
	`info.tdep_info'.
	* spu-tdep.c (spu_gdbarch_init): Likewise.
	* gdbarch.h: Regenerate.
2017-08-07 15:53:54 +01:00
John Baldwin 382b69bbb7 Add a new gdbarch method to fetch signal information from core files.
Previously the core_xfer_partial method used core_get_siginfo to handle
TARGET_OBJECT_SIGNAL_INFO requests.  However, core_get_siginfo looked for
Linux-specific sections in the core file.  To support fetching siginfo
from cores on other systems, add a new gdbarch method (`core_xfer_siginfo`)
and move the body of the existing core_get_siginfo into a
linux_core_xfer_siginfo implementation of this method in linux-tdep.c.

gdb/ChangeLog:

	* corelow.c (get_core_siginfo): Remove.
	(core_xfer_partial): Use the gdbarch "core_xfer_siginfo" method
	instead of get_core_siginfo.
	* gdbarch.sh (core_xfer_siginfo): New gdbarch callback.
	* gdbarch.h: Re-generate.
	* gdbarch.c: Re-generate.
	* linux-tdep.c (linux_core_xfer_siginfo): New.
	(linux_init_abi): Install gdbarch "core_xfer_siginfo" method.
2017-07-07 16:08:33 -07:00
Simon Marchi 6d45d4b42b gdbarch: Remove displaced_step_free_closure
The displaced_step_free_closure gdbarch hook allows architectures to
free data they might have allocated to complete a displaced step.
However, all architectures using that hook use the
simple_displaced_step_free_closure provided in arch-utils.{c,h}, which
does a simple xfree.  We can remove it and do an xfree directly instead
of calling the hook.

gdb/ChangeLog:

	* gdbarch.sh (displaced_step_free_closure): Remove.
	* gdbarch.h, gdbarch.c: Re-generate.
	* aarch64-linux-tdep.c (aarch64_linux_init_abi): Don't set
	displaced_step_free_closure.
	* amd64-linux-tdep.c (amd64_linux_init_abi_common): Likewise.
	* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
	* arch-utils.h (simple_displaced_step_free_closure): Remove.
	* arch-utils.c (simple_displaced_step_free_closure): Remove.
	* infrun.c (displaced_step_clear): Call xfree instead of
	gdbarch_displaced_step_free_closure.
2017-06-10 00:24:50 +02:00
Simon Marchi 35837774a7 gdbarch.sh: Remove commented out TARGET_CHAR_BIT definition
As Pedro commented on the patch "Change field separator in gdbarch.sh",
this commented out definition is probably not useful and should be
removed.  It has been commented out for basically forever, and it
probably serves the same intent as addressable_memory_unit_size.

gdb/ChangeLog:

	* gdbarch.sh: Remove commented out definition of
	TARGET_CHAR_BIT.
	* gdbarch.h: Re-generate.
2017-05-03 09:21:27 -04:00
Simon Marchi a0ff9e1ad2 Change return type of gdbarch_software_single_step to vector<CORE_ADDR>
This is a relatively straightforward patch that changes
gdbarch_software_single_step so it returns an std::vector<CORE_ADDR>
instead of a VEC (CORE_ADDR).

gdb/ChangeLog:

	* gdbarch.sh (software_single_step): Change return type to
	std::vector<CORE_ADDR>.
	* gdbarch.c, gdbarch.h: Re-generate.
	* arch/arm-get-next-pcs.c (thumb_deal_with_atomic_sequence_raw):
	Adjust.
	(arm_deal_with_atomic_sequence_raw): Adjust.
	(thumb_get_next_pcs_raw): Adjust.
	(arm_get_next_pcs_raw): Adjust.
	(arm_get_next_pcs): Adjust.
	* arch/arm-get-next-pcs.h (arm_get_next_pcs): Adjust.
	* aarch64-tdep.c (aarch64_software_single_step): Adjust.
	* alpha-tdep.c (alpha_deal_with_atomic_sequence): Adjust.
	(alpha_software_single_step): Adjust.
	* alpha-tdep.h (alpha_software_single_step): Adjust.
	* arm-linux-tdep.c (arm_linux_software_single_step): Adjust.
	* arm-tdep.c (arm_software_single_step): Adjust.
	(arm_breakpoint_kind_from_current_state): Adjust.
	* arm-tdep.h (arm_software_single_step): Adjust.
	* breakpoint.c (insert_single_step_breakpoint): Adjust.
	* cris-tdep.c (cris_software_single_step): Adjust.
	* mips-tdep.c (mips_deal_with_atomic_sequence): Adjust.
	(micromips_deal_with_atomic_sequence): Adjust.
	(deal_with_atomic_sequence): Adjust.
	(mips_software_single_step): Adjust.
	* mips-tdep.h (mips_software_single_step): Adjust.
	* moxie-tdep.c (moxie_software_single_step): Adjust.
	* nios2-tdep.c (nios2_software_single_step): Adjust.
	* ppc-tdep.h (ppc_deal_with_atomic_sequence): Adjust.
	* rs6000-aix-tdep.c (rs6000_software_single_step): Adjust.
	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust.
	* s390-linux-tdep.c (s390_software_single_step): Adjust.
	* sparc-tdep.c (sparc_software_single_step): Adjust.
	* spu-tdep.c (spu_software_single_step): Adjust.
	* tic6x-tdep.c (tic6x_software_single_step): Adjust.

gdb/gdbserver/ChangeLog:

	* linux-arm-low.c (arm_gdbserver_get_next_pcs): Adjust to
	software_single_step change of return type to
	std::vector<CORE_ADDR>.
	* linux-low.c (install_software_single_step_breakpoints):
	Likewise.
	* linux-low.h (install_software_single_step_breakpoints):
	Likewise.
2017-05-02 13:30:07 -04:00
Simon Marchi ea480a306d Change field separator in gdbarch.sh
The fields in the description of the gdbarch interface are separated
using colons.  That becomes a problem if we want to use things like
std::vector in it. This patch changes the field separator to use
semicolons instead.

I think there's very little chance we'll ever want to use a semicolon in
one of the fields, but if you think another character would be more
appropriate, let me know.

gdb/ChangeLog:

	* gdbarch.sh: Use semi-colon as field separator instead of colon.
	* gdbarch.h: Re-generate.
2017-05-02 13:30:07 -04:00
Jiong Wang b41c5a85a7 [gdbarch] New method "execute_dwarf_cfa_vendor_op" and migrate SPARC to it
Recently a feature called "return address signing" has been added to GCC to
prevent stack smash stack on AArch64.  For details please refer:

  https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00376.html

GDB needs to be aware of this feature so it can restore the original return
address which is critical for unwinding.

On compiler side, whenever return address, i.e. LR register, is mangled or
restored by hardware instruction, compiler is expected to generate a
DW_CFA_AARCH64_negate_ra_state to toggle return address signing status.

DW_CFA_AARCH64_negate_ra_state is using the same CFI number and
therefore need to be multiplexed with DW_CFA_GNU_window_save which was designed
for SPARC.

A new gdbarch method "execute_dwarf_cfa_vendor_op" is introduced by this patch.
It's parameters has been restricted to those only needed by SPARC and AArch64
for multiplexing DW_CFA_GNU_window_save which is a CFI operation takes none
operand.  Should any further DWARF CFI operation want to be multiplexed in the
future,  the parameter list can be extended.  Below is the current function
prototype.

   typedef int (gdbarch_execute_dwarf_cfa_vendor_op_ftype)
     (struct gdbarch *gdbarch, gdb_byte op, struct dwarf2_frame_state *fs);

DW_CFA_GNU_window_save support for SPARC is migrated to this new gdbarch
method by this patch.

gdb/
	* gdbarch.sh: New gdbarch method execute_dwarf_cfa_vendor_op.
	* gdbarch.c: Regenerated.
	* gdbarch.h: Regenerated.
	* dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Made the
	visibility external.
	(execute_cfa_program): Call execute_dwarf_cfa_vendor_op for CFI
	between DW_CFA_lo_user and DW_CFA_high_user inclusive.
	(enum cfa_how_kind): Move to ...
	(struct dwarf2_frame_state_reg_info): Likewise.
	(struct dwarf2_frame_state): Likewise.
	* dwarf2-frame.h: ... here.
	(dwarf2_frame_state_alloc_regs): New declaration.
	* sparc-tdep.c (sparc_execute_dwarf_cfa_vendor_op): New function.
	(sparc32_gdbarch_init): Register execute_dwarf_cfa_vendor_op hook.
2017-04-26 14:05:03 +01:00
Pedro Alves 53375380e9 Teach GDB that wchar_t is a built-in type in C++ mode
GDB is currently not aware that wchar_t is a built-in type in C++
mode.  This is usually not a problem because the debug info describes
the type, so when you have a program loaded, you don't notice this.
However, if you try expressions involving wchar_t before a program is
loaded, gdb errors out:

 (gdb) p (wchar_t)-1
 No symbol table is loaded.  Use the "file" command.
 (gdb) p L"hello"
 No type named wchar_t.
 (gdb) ptype L"hello"
 No type named wchar_t.

This commit teaches gdb about the type.  After:

 (gdb) p (wchar_t)-1
 $1 = -1 L'\xffffffff'
 (gdb) p L"hello"
 $2 = L"hello"
 (gdb) ptype L"hello"
 type = wchar_t [6]

Unlike char16_t/char32_t, unfortunately, the underlying type of
wchar_t is implementation dependent, both size and signness.  So this
requires adding a couple new gdbarch hooks.

I grepped the GCC code base for WCHAR_TYPE and WCHAR_TYPE_SIZE, and it
seems to me that the majority of the ABIs have a 4-byte signed
wchar_t, so that's what I made the default for GDB too.  And then I
looked for which ports have a 16-bit and/or unsigned wchar_t, and made
GDB follow suit.

gdb/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

	PR gdb/21323
	* c-lang.c (cplus_primitive_types) <cplus_primitive_type_wchar_t>:
	New enum value.
	(cplus_language_arch_info): Register cplus_primitive_type_wchar_t.
	* gdbtypes.h (struct builtin_type) <builtin_wchar>: New field.
	* gdbtypes.c (gdbtypes_post_init): Create the "wchar_t" type.
	* gdbarch.sh (wchar_bit, wchar_signed): New per-arch values.
	* gdbarch.h, gdbarch.c: Regenerate.
	* aarch64-tdep.c (aarch64_gdbarch_init): Override
	gdbarch_wchar_bit and gdbarch_wchar_signed.
	* alpha-tdep.c (alpha_gdbarch_init): Likewise.
	* arm-tdep.c (arm_gdbarch_init): Likewise.
	* avr-tdep.c (avr_gdbarch_init): Likewise.
	* h8300-tdep.c (h8300_gdbarch_init): Likewise.
	* i386-nto-tdep.c (i386nto_init_abi): Likewise.
	* i386-tdep.c (i386_go32_init_abi): Likewise.
	* m32r-tdep.c (m32r_gdbarch_init): Likewise.
	* moxie-tdep.c (moxie_gdbarch_init): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* rs6000-aix-tdep.c (rs6000_aix_init_osabi): Likewise.
	* sh-tdep.c (sh_gdbarch_init): Likewise.
	* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
	* sparc64-tdep.c (sparc64_init_abi): Likewise.
	* windows-tdep.c (windows_init_abi): Likewise.
	* xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise.

gdb/testsuite/ChangeLog:
2017-04-12  Pedro Alves  <palves@redhat.com>

	PR gdb/21323
	* gdb.cp/wide_char_types.c: Include <wchar.h>.
	(wchar): New global.
	* gdb.cp/wide_char_types.exp (wide_char_types_program)
	(do_test_wide_char, wide_char_types_no_program, top level): Add
	wchar_t testing.
2017-04-12 14:06:40 +01:00
Pedro Alves 7a1149643d -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info
-Wwrite-strings flagged a missing cast for example here:

   static char *
   ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp)
   {
     return "Ravenscar task";

Since callers are not supposed to free the string returned by these
methods, change the methods' signature to return const strings.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

	* aix-thread.c (aix_thread_pid_to_str)
	(aix_thread_extra_thread_info): Constify.
	* bsd-kvm.c (bsd_kvm_pid_to_str): Constify.
	* bsd-uthread.c (bsd_uthread_extra_thread_info)
	(bsd_uthread_pid_to_str): Constify.
	* corelow.c (core_pid_to_str): Constify.
	* darwin-nat.c (darwin_pid_to_str): Constify.
	* fbsd-nat.c (fbsd_pid_to_str): Constify.
	* fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str):
	Constify.
	* gnu-nat.c (gnu_pid_to_str): Constify.
	* go32-nat.c (go32_pid_to_str): Constify.
	* i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify.
	* inf-ptrace.c (inf_ptrace_pid_to_str): Constify.
	* inferior.c (inferior_pid_to_str): Constify.
	* linux-nat.c (linux_nat_pid_to_str): Constify.
	* linux-tdep.c (linux_core_pid_to_str): Constify.
	* linux-thread-db.c (thread_db_pid_to_str)
	(thread_db_extra_thread_info): Constify.
	* nto-tdep.c (nto_extra_thread_info): Constify.
	* nto-tdep.h (nto_extra_thread_info): Constify.
	* obsd-nat.c (obsd_pid_to_str): Constify.
	* procfs.c (procfs_pid_to_str): Constify.
	* ravenscar-thread.c (ravenscar_extra_thread_info)
	(ravenscar_pid_to_str): Constify.
	* remote-sim.c (gdbsim_pid_to_str): Constify.
	* remote.c (remote_threads_extra_info, remote_pid_to_str):
	Constify.
	* sol-thread.c (solaris_pid_to_str): Constify.
	* sol2-tdep.c (sol2_core_pid_to_str): Constify.
	* sol2-tdep.h (sol2_core_pid_to_str): Constify.
	* target.c (default_pid_to_str, target_pid_to_str)
	(normal_pid_to_str, default_pid_to_str): Constify.
	* target.h (target_ops::to_pid_to_str)
	(target_ops::to_extra_thread_info): Constify.
	(target_pid_to_str, normal_pid_to_str): Constify.
	* windows-nat.c (windows_pid_to_str): Constify.
	* gdbarch.sh (core_pid_to_str): Constify.
	* target-delegates.c: Regenerate.
	* gdbarch.h, gdbarch.c: Regenerate.
2017-04-05 19:21:34 +01:00
Peter Bergner 65b48a8140 GDB: Add support for the new set/show disassembler-options commands.
This commit adds support to GDB so that it can modify the disassembler-options
value that is passed to the disassembler, similar to objdump's -M option.
Currently, the only supported targets are ARM, PowerPC and S/390, but
adding support for a new target(s) is not difficult.

include/
	* dis-asm.h (disasm_options_t): New typedef.
	(parse_arm_disassembler_option): Remove prototype.
	(set_arm_regname_option): Likewise.
	(get_arm_regnames): Likewise.
	(get_arm_regname_num_options): Likewise.
	(disassemble_init_s390): New prototype.
	(disassembler_options_powerpc): Likewise.
	(disassembler_options_arm): Likewise.
	(disassembler_options_s390): Likewise.
	(remove_whitespace_and_extra_commas): Likewise.
	(disassembler_options_cmp): Likewise.
	(next_disassembler_option): New inline function.
	(FOR_EACH_DISASSEMBLER_OPTION): New macro.

opcodes/
	* disassemble.c Include "safe-ctype.h".
	(disassemble_init_for_target): Handle s390 init.
	(remove_whitespace_and_extra_commas): New function.
	(disassembler_options_cmp): Likewise.
	* arm-dis.c: Include "libiberty.h".
	(NUM_ELEM): Delete.
	(regnames): Use long disassembler style names.
	Add force-thumb and no-force-thumb options.
	(NUM_ARM_REGNAMES): Rename from this...
	(NUM_ARM_OPTIONS): ...to this.  Use ARRAY_SIZE.
	(get_arm_regname_num_options): Delete.
	(set_arm_regname_option): Likewise.
	(get_arm_regnames): Likewise.
	(parse_disassembler_options): Likewise.
	(parse_arm_disassembler_option): Rename from this...
	(parse_arm_disassembler_options): ...to this.  Make static.
	Use new FOR_EACH_DISASSEMBLER_OPTION macro to scan over options.
	(print_insn): Use parse_arm_disassembler_options.
	(disassembler_options_arm): New function.
	(print_arm_disassembler_options): Handle updated regnames.
	* ppc-dis.c: Include "libiberty.h".
	(ppc_opts): Add "32" and "64" entries.
	(ppc_parse_cpu): Use ARRAY_SIZE and disassembler_options_cmp.
	(powerpc_init_dialect): Add break to switch statement.
	Use new FOR_EACH_DISASSEMBLER_OPTION macro.
	(disassembler_options_powerpc): New function.
	(print_ppc_disassembler_options): Use ARRAY_SIZE.
	Remove printing of "32" and "64".
	* s390-dis.c: Include "libiberty.h".
	(init_flag): Remove unneeded variable.
	(struct s390_options_t): New structure type.
	(options): New structure.
	(init_disasm): Rename from this...
	(disassemble_init_s390): ...to this.  Add initializations for
	current_arch_mask and option_use_insn_len_bits_p.  Remove init_flag.
	(print_insn_s390): Delete call to init_disasm.
	(disassembler_options_s390): New function.
	(print_s390_disassembler_options): Print using information from
	struct 'options'.
	* po/opcodes.pot: Regenerate.

binutils/
	* objdump.c (main): Use remove_whitespace_and_extra_commas.

gdb/
	* NEWS: Mention new set/show disassembler-options commands.
	* doc/gdb.texinfo: Document new set/show disassembler-options commands.
	* disasm.c: Include "arch-utils.h", "gdbcmd.h" and "safe-ctype.h".
	(prospective_options): New static variable.
	(gdb_disassembler::gdb_disassembler): Initialize
	m_di.disassembler_options.
	(gdb_buffered_insn_length_init_dis): Initilize di->disassembler_options.
	(get_disassembler_options): New function.
	(set_disassembler_options): Likewise.
	(set_disassembler_options_sfunc): Likewise.
	(show_disassembler_options_sfunc): Likewise.
	(disassembler_options_completer): Likewise.
	(_initialize_disasm): Likewise.
	* disasm.h (get_disassembler_options): New prototype.
	(set_disassembler_options): Likewise.
	* gdbarch.sh (gdbarch_disassembler_options): New variable.
	(gdbarch_verify_disassembler_options): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Likewise.
	* arm-tdep.c (num_disassembly_options): Delete.
	(set_disassembly_style): Likewise.
	(arm_disassembler_options): New static variable.
	(set_disassembly_style_sfunc): Convert short style name into long
	option name.  Call set_disassembler_options.
	(show_disassembly_style_sfunc): New function.
	(arm_gdbarch_init): Call set_gdbarch_disassembler_options and
	set_gdbarch_verify_disassembler_options.
	(_initialize_arm_tdep): Delete regnames variable and update callers.
	(arm_disassembler_options): Initialize.
	(disasm_options): New variable.
	(num_disassembly_options): Rename from this...
	(num_disassembly_styles): ...to this.  Compute by scanning through
	disasm_options.
	(valid_disassembly_styles): Initialize using disasm_options.
	Remove calls to parse_arm_disassembler_option, get_arm_regnames and
	set_arm_regname_option.
	Pass show_disassembly_style_sfunc to the "disassembler" setshow command.
	* rs6000-tdep.c (powerpc_disassembler_options): New static variable.
	(rs6000_gdbarch_init): Call set_gdbarch_disassembler_options and
	set_gdbarch_verify_disassembler_options.
	* s390-tdep.c (s390_disassembler_options): New static variable.
	(s390_gdbarch_init):all set_gdbarch_disassembler_options and
	set_gdbarch_verify_disassembler_options.

gdb/testsuite/
	* gdb.arch/powerpc-power.exp: Delete test.
	* gdb.arch/powerpc-power.s: Likewise.
	* gdb.disasm/disassembler-options.exp: New test.
	* gdb.arch/powerpc-altivec.exp: Likewise.
	* gdb.arch/powerpc-altivec.s: Likewise.
	* gdb.arch/powerpc-altivec2.exp: Likewise.
	* gdb.arch/powerpc-altivec2.s: Likewise.
	* gdb.arch/powerpc-altivec3.exp: Likewise.
	* gdb.arch/powerpc-altivec3.s: Likewise.
	* gdb.arch/powerpc-power7.exp: Likewise.
	* gdb.arch/powerpc-power7.s: Likewise.
	* gdb.arch/powerpc-power8.exp: Likewise.
	* gdb.arch/powerpc-power8.s: Likewise.
	* gdb.arch/powerpc-power9.exp: Likewise.
	* gdb.arch/powerpc-power9.s: Likewise.
	* gdb.arch/powerpc-vsx.exp: Likewise.
	* gdb.arch/powerpc-vsx.s: Likewise.
	* gdb.arch/powerpc-vsx2.exp: Likewise.
	* gdb.arch/powerpc-vsx2.s: Likewise.
	* gdb.arch/powerpc-vsx3.exp: Likewise.
	* gdb.arch/powerpc-vsx3.s: Likewise.
	* gdb.arch/arm-disassembler-options.exp: Likewise.
	* gdb.arch/powerpc-disassembler-options.exp: Likewise.
	* gdb.arch/s390-disassembler-options.exp: Likewise.
2017-02-28 12:32:07 -06:00
Joel Brobecker 61baf725ec update copyright year range in GDB files
This applies the second part of GDB's End of Year Procedure, which
updates the copyright year range in all of GDB's files.

gdb/ChangeLog:

        Update copyright year range in all GDB files.
2017-01-01 10:52:34 +04:00
Yao Qi f5ea389ac7 Change gdbarch software_single_step frame_info to regcache
This patch changes gdbarch method software_single_step's parameter from
"struct frame_info *" to "struct regcache *, IOW, software_single_step
starts to use current regcache rather than current frame for software
single.

gdb:

2016-11-22  Yao Qi  <yao.qi@linaro.org>

	* gdbarch.sh (software_single_step): Change parameter from frame_info
	to regcache.
	* gdbarch.c, gdbarch.h: Regenerated.
	* aarch64-tdep.c (aarch64_software_single_step): Change parameter
	from frame_info to regcache.  Don't call get_current_regcache.
	* alpha-tdep.c (alpha_deal_with_atomic_sequence): Likewise.
	(alpha_software_single_step): Likewise.
	* alpha-tdep.h (alpha_software_single_step): Update declaration.
	* arm-linux-tdep.c (arm_linux_software_single_step): Likewise.
	* arm-tdep.c (arm_software_single_step): Likewise.
	* arm-tdep.h (arm_software_single_step): Likewise.
	* breakpoint.c (insert_single_step_breakpoint): Pass regcache to
	gdbarch_software_single_step.
	* cris-tdep.c (cris_software_single_step): Change parameter from
	frame_info to regcache.  Don't call get_current_regcache.
	* mips-tdep.c (mips_software_single_step): Likewise.
	* mips-tdep.h (mips_software_single_step): Update declaration.
	* moxie-tdep.c (moxie_software_single_step): Likewise.
	* nios2-tdep.c (nios2_software_single_step): Likewise.
	* ppc-tdep.h (ppc_deal_with_atomic_sequence): Update declaration.
	* rs6000-aix-tdep.c (rs6000_software_single_step): Likewise.
	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Likewise.
	* s390-linux-tdep.c (s390_software_single_step): Likewise.
	* sparc-tdep.c (sparc_software_single_step): Likewise.
	* spu-tdep.c (spu_software_single_step): Likewise.
	* tic6x-tdep.c (tic6x_software_single_step): Likewise.
2016-11-22 14:30:50 +00:00
Yao Qi 93f9a11fbd gdbarch software_single_step returns VEC (CORE_ADDR) *
This patch changes gdbarch method software_single_step to return a
vector of addresses on which GDB should insert breakpoints, and don't
insert breakpoints.  Instead, the caller of
gdbarch_software_single_step inserts breakpoints if the returned
vector is not NULL.

gdb:

2016-11-08  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c (aarch64_software_single_step): Return
	VEC (CORE_ADDR) *.  Return NULL instead of 0.  Don't call
	insert_single_step_breakpoint.
	* alpha-tdep.c (alpha_deal_with_atomic_sequence): Likewise.
	(alpha_software_single_step): Likewise.
	* alpha-tdep.h (alpha_software_single_step): Update declaration.
	* arm-linux-tdep.c (arm_linux_software_single_step): Return
	VEC (CORE_ADDR) *.  Return NULL instead of 0.
	* arm-tdep.c (arm_software_single_step): Return NULL instead of	0.
	* arm-tdep.h (arm_software_single_step): Update declaration.
	* breakpoint.c (insert_single_step_breakpoints): New function.
	* breakpoint.h (insert_single_step_breakpoints): Declare.
	* cris-tdep.c (cris_software_single_step): Return
	VEC (CORE_ADDR) *.  Don't call insert_single_step_breakpoint.
	* gdbarch.sh (software_single_step): Change it to return
	VEC (CORE_ADDR) *.
	* gdbarch.c, gdbarch.h: Regenerated.
	* infrun.c (maybe_software_singlestep): Adjust.
	* mips-tdep.c (mips_deal_with_atomic_sequence): Return
	VEC (CORE_ADDR) *.  Don't call insert_single_step_breakpoint.
	(micromips_deal_with_atomic_sequence): Likewise.
	(deal_with_atomic_sequence): Likewise.
	(mips_software_single_step): Likewise.
	* mips-tdep.h (mips_software_single_step): Update declaration.
	* moxie-tdep.c (moxie_software_single_step): Likewise.
	* nios2-tdep.c (nios2_software_single_step): Likewise.
	* ppc-tdep.h (ppc_deal_with_atomic_sequence): Update
	declaration.
	* record-full.c (record_full_resume): Adjust.
	(record_full_wait_1): Likewise.
	* rs6000-aix-tdep.c (rs6000_software_single_step): Return
	VEC (CORE_ADDR) *.  Don't call insert_single_step_breakpoint.
	* rs6000-tdep.c	(ppc_deal_with_atomic_sequence): Return
	VEC (CORE_ADDR) *.  Don't call insert_single_step_breakpoint.
	* s390-linux-tdep.c (s390_software_single_step): Likewise.
	* sparc-tdep.c (sparc_software_single_step): Likewise.
	* spu-tdep.c (spu_software_single_step): Likewise.
	* tic6x-tdep.c (tic6x_software_single_step): Likewise.
2016-11-08 14:28:32 +00:00
Yao Qi 833b7ab500 Determine the kind of single step breakpoint
This patch adds a new gdbarch method breakpoint_kind_from_current_state
for single step breakpoint, and uses it in breakpoint_kind.

gdb:

2016-11-03  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.c (default_breakpoint_kind_from_current_state):
	New function.
	* arch-utils.h (default_breakpoint_kind_from_current_state):
	Declare.
	* arm-tdep.c (arm_breakpoint_kind_from_current_state): New
	function.
	(arm_gdbarch_init): Call
	set_gdbarch_breakpoint_kind_from_current_state.
	* breakpoint.c (breakpoint_kind): Call
	gdbarch_breakpoint_kind_from_current_state for single step
	breakpoint.  Update comments.
	* gdbarch.sh (breakpoint_kind_from_current_state): New.
	* gdbarch.c, gdbarch.h: Regenerate.
2016-11-03 14:35:14 +00:00
Yao Qi c0f4a997c2 Remove gdbarch_remote_breakpoint_from_pc
This patch removes gdbarch method remote_breakpoint_from_pc, as it
is no longer used.

gdb:

2016-11-03  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.c (default_remote_breakpoint_from_pc): Remove.
	* arch-utils.h (default_remote_breakpoint_from_pc): Remove.
	* arm-tdep.c (arm_remote_breakpoint_from_pc): Remove.
	(arm_gdbarch_init): Don't call
	set_gdbarch_remote_breakpoint_from_pc.
	* gdbarch.sh (remote_breakpoint_from_pc): Remove.
	* gdbarch.c, gdbarch.h: Regenerate.
	* mips-tdep.c (mips_remote_breakpoint_from_pc): Remove.
	(mips_gdbarch_init): Don't call
	set_gdbarch_remote_breakpoint_from_pc.
2016-11-03 14:35:14 +00:00
Yao Qi cd6c3b4ffc New gdbarch methods breakpoint_kind_from_pc and sw_breakpoint_from_kind
This patch adds two gdbarch methods breakpoint_kind_from_pc and
sw_breakpoint_from_kind, and uses target_info.placed_size as "kind"
of the breakpoint.  This patch updates the usages of
target_info.placed_size.

The "kind" of a breakpoint is determined by gdbarch rather than
target, so we have gdbarch method breakpoint_kind_from_pc, and we
should set target_info.placed_size out of each implementation of
target to_insert_breakpoint.  In this way, each target doesn't have
to set target_info.placed_size any more.

This patch also sets target_info.placed_address before
target_insert_breakpoint too, so that target to_insert_breakpoint
can use it, see record_full_insert_breakpoint.

Before we call target_insert_breakpoint, we set
target_info.placed_address and target_info.placed_size like this,

      CORE_ADDR addr = bl->target_info.reqstd_address;

      bl->target_info.placed_size = gdbarch_breakpoint_kind_from_pc (bl->gdbarch, &addr);
      bl->target_info.placed_address = addr;

      return target_insert_breakpoint (bl->gdbarch, &bl->target_info);

target_insert_breakpoint may fail, but it doesn't matter to the "kind"
and "placed_address" of a breakpoint.  They should be determined by
gdbarch.

gdb:

2016-11-03  Yao Qi  <yao.qi@linaro.org>

	* arch-utils.h (GDBARCH_BREAKPOINT_MANIPULATION): Define
	breakpoint_kind_from_pc and sw_breakpoint_from_kind.
	(GDBARCH_BREAKPOINT_MANIPULATION_ENDIAN): Likewise.
	(SET_GDBARCH_BREAKPOINT_MANIPULATION): Call
	set_gdbarch_breakpoint_kind_from_pc and
	set_gdbarch_sw_breakpoint_from_kind.
	* arm-tdep.c: Add comments.
	* bfin-tdep.c: Likewise.
	* breakpoint.c (breakpoint_kind): New function.
	(insert_bp_location): Set target_info.placed_size and
	target_info.placed_address.
	(bkpt_insert_location): Likewise.
	* cris-tdep.c: Add comments.
	* gdbarch.sh (breakpoint_kind_from_pc): New.
	(sw_breakpoint_from_kind): New.
	* gdbarch.c, gdbarch.h: Regenerated.
	* ia64-tdep.c (ia64_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	(ia64_memory_remove_breakpoint): Don't assert
	bp_tgt->placed_size.
	(ia64_breakpoint_kind_from_pc): New function.
	(ia64_gdbarch_init): Install ia64_breakpoint_kind_from_pc.
	* m32r-tdep.c (m32r_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.
	* mem-break.c (default_memory_insert_breakpoint): Don't set
	bp_tgt->placed_size.  Call gdbarch_sw_breakpoint_from_kind.
	(default_memory_remove_breakpoint): Call
	gdbarch_sw_breakpoint_from_kind.
	(memory_validate_breakpoint): Don't check bp_tgt->placed_size.
	* mips-tdep.c: Add comments.
	* mt-tdep.c: Likewise.
	* nios2-tdep.c: Likewise.
	* record-full.c (record_full_insert_breakpoint): Don't call
	gdbarch_breakpoint_from_pc.  Don't set bp_tgt->placed_address
	and bp_tgt->placed_size.
	* remote.c (remote_insert_breakpoint): Don't call
	gdbarch_remote_breakpoint_from_pc.  Use bp_tgt->placed_size.
	Don't set bp_tgt->placed_address and bp_tgt->placed_size.
	(remote_insert_hw_breakpoint): Likewise.
	* score-tdep.c: Likewise.
	* sh-tdep.c: Likewise.
	* tic6x-tdep.c: Likewise.
	* v850-tdep.c: Likewise.
	* xtensa-tdep.c: Likewise.
2016-11-03 14:35:13 +00:00
Ulrich Weigand 9b790ce722 Add gdbarch callback to provide formats for debug info float types
At this point, all TYPE_CODE_FLT types carry their floating-point format,
except for those creating from reading DWARF or stabs debug info.  Those
will be addressed by this commit.

The main issue here is that we actually have to determine which floating-
point format to use.  Currently, we only have the type length as input
to this decision.  In the future, we may hopefully get --at least in
DWARF-- additional information to help disambiguate multiple different
formats of the same length.  For now, we can still look at the type name
as a hint.

This decision logic is encapsulated in a gdbarch callback to allow
platform-specific overrides.  The default implementation use the same
logic (compare type length against the various gdbarch_..._bit sizes)
that is currently implemented in floatformat_from_length.

With this commit, all platforms still use the default logic, so there
should be no actual change in behavior.  A follow-on commit will add
support for __float128 on Intel and Power.

Once dwarf2read.c and stabsread.c make use of the new callback to
determine floating-point formats, we're now sure every TYPE_CODE_FLT
type will always carry its format.  The commit therefore adds asserts
to verify_floatformat to ensure new code will continue to always
provide formats, and removes the code in floatformat_from_type that
used to handle types with a NULL TYPE_FLOATFORMAT.

gdb/ChangeLog:

	* gdbarch.sh (floatformat_for_type): New gdbarch callback.
	* gdbarch.h, gdbarch.c: Re-generate.
	* arch-utils.h (default_floatformat_for_type): New prototype.
	* arch-utils.c (default_floatformat_for_type): New function.

	* doublest.c (floatformat_from_length): Remove.
	(floatformat_from_type): Assume TYPE_FLOATFORMAT is non-NULL.
	* gdbtypes.c (verify_floatformat): Require non-NULL format.

	* dwarf2read.c (dwarf2_init_float_type): New function.
	(read_base_type): Use it.
	* stabsread.c (dbx_init_float_type): New function.
	(read_sun_floating_type): Use it.
	(read_range_type): Likewise.

Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
2016-09-06 17:31:53 +02:00
John Baldwin 2faa34476d Add a new gdbarch method to print a single AUXV entry.
Different platforms have different meanings for auxiliary vector
entries.  The 'print_auxv_entry' gdbarch method allows an architecture
to output a suitable description for platform-specific entries.

A fprint_auxv_entry function is split out of fprint_target_auxv.
This function outputs the description of a single auxiliary vector
entry to the specified file using caller-supplied formatting and
strings to describe the vector type.

The existing switch on auxiliary vector types is moved out of
fprint_target_auxv into a new default_print_auxv_entry function.
default_print_auxv_entry chooses an appropriate format and description
and calls fprint_single_auxv to describe a single vector entry.
This function is used as the default 'print_auxv_entry' gdbarch method.

fprint_target_auxv now invokes the gdbarch 'print_auxv_entry' method
on each vector entry.

gdb/ChangeLog:

	* auxv.c (fprint_auxv_entry): New function.
	(default_print_auxv_entry): New function.
	(fprint_target_auxv): Use gdbarch_print_auxv_entry.
	* auxv.h (enum auxv_format): New enum.
	(fprint_auxv_entry): Declare.
	(default_print_auxv_entry): Declare.
	* gdbarch.sh (print_auxv_entry): New.
	* gdbarch.c, gdbarch.h: Re-generated.
2016-06-24 10:34:29 -07:00
Yao Qi 7eb895307f Skip unwritable frames in command "finish"
Nowadays, GDB can't insert breakpoint on the return address of the
exception handler on ARM M-profile, because the address is a magic
one 0xfffffff9,

 (gdb) bt
 #0  CT32B1_IRQHandler () at ../src/timer.c:67
 #1  <signal handler called>
 #2  main () at ../src/timer.c:127

(gdb) info frame
Stack level 0, frame at 0x200ffa8:
 pc = 0x4ec in CT32B1_IRQHandler (../src/timer.c:67); saved pc = 0xfffffff9
 called by frame at 0x200ffc8
 source language c.
 Arglist at 0x200ffa0, args:
 Locals at 0x200ffa0, Previous frame's sp is 0x200ffa8
 Saved registers:
  r7 at 0x200ffa0, lr at 0x200ffa4

(gdb) x/x 0xfffffff9
0xfffffff9:     Cannot access memory at address 0xfffffff9

(gdb) finish
Run till exit from #0  CT32B1_IRQHandler () at ../src/timer.c:67
Ed:15: Target error from Set break/watch: Et:96: Pseudo-address (0xFFFFFFxx) for EXC_RETURN is invalid (GDB error?)

Warning:
Cannot insert hardware breakpoint 0.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.

even some debug probe can't set hardware breakpoint on the magic
address too,

(gdb) hbreak *0xfffffff9
Hardware assisted breakpoint 2 at 0xfffffff9
(gdb) c
Continuing.
Ed:15: Target error from Set break/watch: Et:96: Pseudo-address (0xFFFFFFxx) for EXC_RETURN is invalid (GDB error?)

Warning:
Cannot insert hardware breakpoint 2.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.

The problem described above is quite similar to PR 8841, in which GDB
can't set breakpoint on signal trampoline, which is mapped to a read-only
page by kernel.  The rationale of this patch is to skip "unwritable"
frames when looking for caller frames in command "finish", and a new
gdbarch method code_of_frame_writable is added.  This patch fixes
the problem on ARM cortex-m target, but it can be used to fix
PR 8841 too.

gdb:

2016-05-10  Yao Qi  <yao.qi@arm.com>

	* arch-utils.c (default_code_of_frame_writable): New function.
	* arch-utils.h (default_code_of_frame_writable): Declare.
	* arm-tdep.c (arm_code_of_frame_writable): New function.
	(arm_gdbarch_init): Install gdbarch method
	code_of_frame_writable if the target is M-profile.
	* frame.c (skip_unwritable_frames): New function.
	* frame.h (skip_unwritable_frames): Declare.
	* gdbarch.sh (code_of_frame_writable): New.
	* gdbarch.c, gdbarch.h: Re-generated.
	* infcmd.c (finish_command): Call skip_unwritable_frames.
2016-05-23 17:32:56 +01:00
Yao Qi 21edc42f4e Force to insert software single step breakpoint
GDB doesn't insert software single step breakpoint if the instruction
branches to itself, so that the program can't stop after command "si".

(gdb) b 32
Breakpoint 2 at 0x8680: file git/gdb/testsuite/gdb.base/branch-to-self.c, line 32.
(gdb) c
Continuing.

Breakpoint 2, main () at gdb/git/gdb/testsuite/gdb.base/branch-to-self.c:32
32	  asm (".Lhere: " BRANCH_INSN " .Lhere"); /* loop-line */
(gdb) si
infrun: clear_proceed_status_thread (Thread 3991.3991)
infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: step-over queue now empty
infrun: resuming [Thread 3991.3991] for step-over
infrun: skipping breakpoint: stepping past insn at: 0x8680
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sending packet: $Z0,8678,4#f3...Packet received: OK
infrun: skipping breakpoint: stepping past insn at: 0x8680
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sending packet: $Z0,b6fe86c8,4#82...Packet received: OK
infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [Thread 3991.3991] at 0x868

breakpoint.c:should_be_inserted thinks the breakpoint shouldn't be
inserted, which is wrong.  This patch restrict the condition that
only skip the non-single-step breakpoints if they are inserted at
the place we are stepping over, however we don't want to skip
single-step breakpoint if its thread is the thread we are stepping
over, so in this patch, I add a thread num in 'struct step_over_info'
to record the thread we're stepping over.

gdb:

2016-04-25  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (should_be_inserted): Return 0 if the location's
	owner is not single step breakpoint or single step breakpoint's
	thread isn't the thread which is stepping past a breakpoint.
	* gdbarch.sh (software_single_step): Update comments.
	* gdbarch.h: Regenerated.
	* infrun.c (struct step_over_info) <thread>: New field.
	(set_step_over_info): New argument 'thread'.  Callers updated.
	(clear_step_over_info): Set field thread to -1.
	(thread_is_stepping_over_breakpoint): New function.
	* infrun.h (thread_is_stepping_over_breakpoint): Declaration.
2016-04-25 09:16:21 +01:00
Yao Qi cc651c1cdd Remove comments on software_single_step in gdbarch.sh
This comment is out of date.  We've already done that.  Patch is to remove
it.

gdb:

2016-03-23  Yao Qi  <yao.qi@linaro.org>

	* gdbarch.sh (software_single_step): Remove comments.
	* gdbarch.h: Regenerated.
2016-03-23 11:21:20 +00:00
Walfred Tedeschi 012b3a217a Intel MPX bound violation handling
With Intel Memory Protection Extensions it was introduced the concept of
boundary violation.  A boundary violations is presented to the inferior as
a segmentation fault having SIGCODE 3.  This patch adds a
handler for a boundary violation extending the information displayed
when a bound violation is presented to the inferior.  In the stop mode
case the debugger will also display the kind of violation: "upper" or
"lower", bounds and the address accessed.
On no stop mode the information will still remain unchanged.  Additional
information about bound violations are not meaningful in that case user
does not know the line in which violation occurred as well.

When the segmentation fault handler is stop mode the out puts will be
changed as exemplified below.

The usual output of a segfault is:
Program received signal SIGSEGV, Segmentation fault
0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050,
c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68
68        value = *(p + len);

In case it is a bound violation it will be presented as:
Program received signal SIGSEGV, Segmentation fault
Upper bound violation while accessing address 0x7fffffffc3b3
Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050,
c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68
68        value = *(p + len);

In mi mode the output of a segfault is:
*stopped,reason="signal-received",signal-name="SIGSEGV",
signal-meaning="Segmentation fault", frame={addr="0x0000000000400d7c",
func="upper",args=[{name="p", value="0x603010"},{name="a",value="0x603030"}
,{name="b",value="0x603050"}, {name="c",value="0x603070"},
{name="d",value="0x603090"},{name="len",value="7"}],
file="i386-mpx-sigsegv.c",fullname="i386-mpx-sigsegv.c",line="68"},
thread-id="1",stopped-threads="all",core="6"

in the case of a bound violation:
*stopped,reason="signal-received",signal-name="SIGSEGV",
signal-meaning="Segmentation fault",
sigcode-meaning="Upper bound violation",
lower-bound="0x603010",upper-bound="0x603023",bound-access="0x60302f",
frame={addr="0x0000000000400d7c",func="upper",args=[{name="p",
value="0x603010"},{name="a",value="0x603030"},{name="b",value="0x603050"},
{name="c",value="0x603070"},{name="d",value="0x603090"},
{name="len",value="7"}],file="i386-mpx-sigsegv.c",
fullname="i386-mpx-sigsegv.c",line="68"},thread-id="1",
stopped-threads="all",core="6"

2016-02-18  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/ChangeLog:

	* NEWS: Add entry for bound violation.
	* amd64-linux-tdep.c (amd64_linux_init_abi_common):
	Add handler for segmentation fault.
	* gdbarch.sh (handle_segmentation_fault): New.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* i386-linux-tdep.c (i386_linux_handle_segmentation_fault): New.
	(SIG_CODE_BONDARY_FAULT): New define.
	(i386_linux_init_abi): Use i386_mpx_bound_violation_handler.
	* i386-linux-tdep.h (i386_linux_handle_segmentation_fault) New.
	* i386-tdep.c (i386_mpx_enabled): Add as external.
	* i386-tdep.c (i386_mpx_enabled): Add as external.
	* infrun.c (handle_segmentation_fault): New function.
	(print_signal_received_reason): Use handle_segmentation_fault.

gdb/testsuite/ChangeLog:

	* gdb.arch/i386-mpx-sigsegv.c: New file.
	* gdb.arch/i386-mpx-sigsegv.exp: New file.
	* gdb.arch/i386-mpx-simple_segv.c: New file.
	* gdb.arch/i386-mpx-simple_segv.exp: New file.

gdb/doc/ChangeLog:

	* gdb.texinfo (Signals): Add bound violation display hints for
	a SIGSEGV.
2016-02-18 17:25:49 +01:00
Marcin Kościelnicki 5f034a78b9 gdb: Add guess_tracepoint_registers hook to gdbarch.
When we're looking at a tracefile trace frame where registers are not
available, and the tracepoint has only one location, we supply
the location's address as the PC register.  However, this only works
if PC is not a pseudo register, and individual architectures may want
to guess more registers.  Add a gdbarch hook that will handle that.

gdb/ChangeLog:

	* arch-utils.c (default_guess_tracepoint_registers): New function.
	* arch-utils.h (default_guess_tracepoint_registers): New prototype.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh: Add guess_tracepoint_registers hook.
	* tracefile.c (tracefile_fetch_registers): Use the new gdbarch hook.
2016-02-18 17:21:22 +01:00
John Baldwin 4dfc5dbc4e Add support for extracting thread names from cores.
Add a new gdbarch method to extract a thread name from a core for a
given thread.  Use this new method in core_thread_name to implement the
to_thread_name target op.

gdb/ChangeLog:

	* corelow.c (core_thread_name): New function.
	(init_core_ops): Use "core_thread_name" for the "to_thread_name"
	target op.
	* gdbarch.sh (core_thread_name): New gdbarch callback.
	* gdbarch.h: Re-generate.
	* gdbarch.c: Re-generate.
2016-01-19 08:18:20 -08:00
Joel Brobecker 618f726fcb GDB copyright headers update after running GDB's copyright.py script.
gdb/ChangeLog:

        Update year range in copyright notice of all files.
2016-01-01 08:43:22 +04:00
Doug Evans 0fde2c536b PR symtab/17391 gdb internal error: assertion fails in regcache.c:178
gdb/ChangeLog:

	* dwarf2-frame.c (dwarf2_restore_rule): Call dwarf_reg_to_regnum
	instead of gdbarch_dwarf2_reg_to_regnum.
	(dwarf2_frame_cache): Ditto.
	(read_addr_from_reg): Call dwarf_reg_to_regnum_or_error instead of
	gdbarch_dwarf2_reg_to_regnum.
	(get_reg_value): Ditto.
	(dwarf2_fetch_cfa_info): Ditto.
	(dwarf2_frame_prev_register): Ditto.
	* dwarf2loc.c: #include "complaints.h".
	(dwarf_expr_read_addr_from_reg): Call dwarf_reg_to_regnum_or_error
	instead of gdbarch_dwarf2_reg_to_regnum.
	(dwarf_expr_get_reg_value): Ditto.
	(read_pieced_value): Ditto.
	(write_pieced_value): Ditto.
	(dwarf2_evaluate_loc_desc_full): Ditto.
	(dwarf_reg_to_regnum): New function.
	(throw_bad_regnum_error): New function.
	(dwarf_reg_to_regnum_or_error): Renamed from
	dwarf2_reg_to_regnum_or_errorChange to take a ULONGEST regnum.
	All callers updated.  Call throw_bad_regnum_error.
	(locexpr_regname): Improve text of bad register number.
	* dwarf2loc.h (dwarf_reg_to_regnum): Declare.
	(dwarf_reg_to_regnum_or_error): Update prototype.
	* dwarf2expr.c: #include "dwarf2loc.h".
	(dwarf_block_to_sp_offset): Call dwarf_reg_to_regnum instead of
	gdbarch_dwarf2_reg_to_regnum.
	* gdbarch.sh (dwarf2_reg_to_regnum): Add comment.
	* gdbarch.h: Regenerate.
	* amd64-tdep.c (amd64_dwarf_reg_to_regnum): Remove warning for bad
	register.
	* avr-tdep.c (avr_dwarf_reg_to_regnum): Ditto.
	* cris-tdep.c (cris_dwarf2_reg_to_regnum): Ditto.
	* bfin-tdep.c (bfin_reg_to_regnum): Fix error checking.
	* hppa-linux-tdep.c (hppa_dwarf_reg_to_regnum): Improve error checking.
	Remove warning for bad register.
	* hppa-tdep.c (hppa64_dwarf_reg_to_regnum): Ditto.
	* i386-tdep.c (i386_svr4_dwarf_reg_to_regnum): Renamed from
	i386_svr4_reg_to_regnum.  Return -1 for bad registers.
	(i386_svr4_reg_to_regnum): New function.
	(i386_gdbarch_init): Update call to set_gdbarch_dwarf2_reg_to_regnum.
	* microblaze-tdep.c (microblaze_dwarf2_reg_to_regnum): Don't assert
	on bad registers, return -1.
	* msp430-tdep.c (msp430_dwarf2_reg_to_regnum): Improve error checking.
	Remove warning for bad register.
	* nios2-tdep.c: Add static assert for NIOS2_NUM_REGS.
	(nios2_dwarf_reg_to_regnum): Fix off-by-one error.
	Remove warning for bad register.  Return -1 for bad register.
	* rl78-tdep.c (rl78_dwarf_reg_to_regnum): Don't flag an internal error
	for bad register, return -1.
	* rx-tdep.c (rx_dwarf_reg_to_regnum): Ditto.
	* m68k-tdep.c (m68k_dwarf_reg_to_regnum): Fix error result.
	* mep-tdep.c (mep_debug_reg_to_regnum): Ditto.
	* mips-tdep.c (mips_stab_reg_to_regnum): Ditto.
	(mips_dwarf_dwarf2_ecoff_reg_to_regnum): Ditto.
	* mn10300-tdep.c (mn10300_dwarf2_reg_to_regnum): Remove warning
	for bad regs.
	* xtensa-tdep.c (xtensa_reg_to_regnum): Remove internal error for
	bad regs.  Fix error result.
	* stabsread.c (stab_reg_to_regnum): Watch for negative regno.
	(reg_value_complaint): Update complaint text.
	* mdebugread.c (reg_value_complaint): New function.
	(mdebug_reg_to_regnum): Rewrite to watch for bad reg numbers.

gdb/testsuite/ChangeLog:

	* lib/dwarf.exp (_location): Add support for DW_OP_regx.
	* gdb.dwarf2/bad-regnum.c: New file.
	* gdb.dwarf2/bad-regnum.exp: New file.
2015-10-26 16:05:21 -07:00
Aleksandar Ristovski 89fdc87fdb Remove core_regset_section
gdb/ChangeLog:

	* gdbarch.sh (core_regset_section): Remove.
	* gdbarch.h: Regenerate.
2015-10-15 08:56:23 -04:00
Simon Marchi ede5f15146 gdbarch.h: Change gdbarch_info::tdep_info's type to void *
As reported by Ulrich here:

  https://sourceware.org/ml/gdb-patches/2015-09/msg00604.html

The system compiler (gcc 4.1) in Centos 5 doesn't like that we cast to a
pointer to a type that doesn't exist.  I see no real value in using this
kind iof construct over just using void *.  So this patch changes the
tdep_info field to void * and removes the casts.  Even in C++, we
should not need an explicit cast when assigning to a void *.

gdb/ChangeLog:

	* gdbarch.sh (struct gdbarch_info): Change tdep_info's type to void *.
	* gdbarch.h: Regenerate.
	* i386-tdep.c (i386_gdbarch_init): Remove cast to
	struct gdbarch_tdep_info *.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* ppc-linux-tdep (ppu2spu_sniffer): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* spu-multiarch.c (spu_gdbarch): Likewise.
2015-09-30 11:21:52 -04:00
Patrick Palka 6c214e7cb3 Use gdbarch obstack to allocate the TYPE_NAME string in arch_type
Since the type whose name is being set is now being allocated on the
gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
This reduces the number of individual valgrind warnings for the command
"gdb gdb" from ~300 to ~150.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* gdb_obstack.h (obstack_strdup): Declare.
	* gdb_obstack.c (obstack_strdup): Define.
	* gdbarch.sh (gdbarch_obstack_strdup): Declare and define.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbtypes.c (arch_type): Use gdbarch_obstack_strdup.
2015-09-02 20:53:33 -04:00
Patrick Palka 2fee770894 Revert "Use gdbarch obstack to allocate the TYPE_NAME string in arch_type"
This patch manually modified the autogenerated files gdbarch.[ch] instead of
going through gdbarch.sh.

This reverts commit aa78b3b28a.
2015-08-29 18:24:29 -04:00
Patrick Palka aa78b3b28a Use gdbarch obstack to allocate the TYPE_NAME string in arch_type
Since the type whose name is being set is now being allocated on the
gdbarch obstack, we should allocate its TYPE_NAME on the obstack too.
This reduces the number of individual valgrind warnings for the command
"gdb gdb" from ~300 to ~150.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* gdbarch.h (gdbarch_obstack_strdup): Declare.
	* gdbarch.c (gdbarch_obstack_strdup): Define.
	* gdbtypes.c (arch_type): Use it.
2015-08-29 08:53:08 -04:00
Simon Marchi 8d7493201c Replace some xmalloc-family functions with XNEW-family ones
This patch is part of the make-gdb-buildable-in-C++ effort.  The idea is
to change some calls to the xmalloc family of functions to calls to the
equivalents in the XNEW family.  This avoids adding an explicit cast, so
it keeps the code a bit more readable.  Some of them also map relatively
well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be
possible to do scripted replacements if needed.

I only changed calls that were obviously allocating memory for one or
multiple "objects".  Allocation of variable sizes (such as strings or
buffer handling) will be for later (and won't use XNEW).

  - xmalloc (sizeof (struct foo)) -> XNEW (struct foo)
  - xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num)
  - xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo)
  - xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num)
  - xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num)
  - obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo)
  - obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num)
  - alloca (sizeof (struct foo)) -> XALLOCA (struct foo)
  - alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num)

Some instances of xmalloc followed by memset to zero the buffer were
replaced by XCNEW or XCNEWVEC.

I regtested on x86-64, Ubuntu 14.04, but the patch touches many
architecture-specific files.  For those I'll have to rely on the
buildbot or people complaining that I broke their gdb.

gdb/ChangeLog:

	* aarch64-linux-nat.c (aarch64_add_process): Likewise.
	* aarch64-tdep.c (aarch64_gdbarch_init): Likewise.
	* ada-exp.y (write_ambiguous_var): Likewise.
	* ada-lang.c (resolve_subexp): Likewise.
	(user_select_syms): Likewise.
	(assign_aggregate): Likewise.
	(ada_evaluate_subexp): Likewise.
	(cache_symbol): Likewise.
	* addrmap.c (allocate_key): Likewise.
	(addrmap_create_mutable): Likewise.
	* aix-thread.c (sync_threadlists): Likewise.
	* alpha-tdep.c (alpha_push_dummy_call): Likewise.
	(alpha_gdbarch_init): Likewise.
	* amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise.
	* arm-linux-nat.c (arm_linux_add_process): Likewise.
	* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
	* arm-tdep.c (push_stack_item): Likewise.
	(arm_displaced_step_copy_insn): Likewise.
	(arm_gdbarch_init): Likewise.
	(_initialize_arm_tdep): Likewise.
	* avr-tdep.c (push_stack_item): Likewise.
	* ax-general.c (new_agent_expr): Likewise.
	* block.c (block_initialize_namespace): Likewise.
	* breakpoint.c (alloc_counted_command_line): Likewise.
	(update_dprintf_command_list): Likewise.
	(parse_breakpoint_sals): Likewise.
	(decode_static_tracepoint_spec): Likewise.
	(until_break_command): Likewise.
	(clear_command): Likewise.
	(update_global_location_list): Likewise.
	(get_breakpoint_objfile_data) Likewise.
	* btrace.c (ftrace_new_function): Likewise.
	(btrace_set_insn_history): Likewise.
	(btrace_set_call_history): Likewise.
	* buildsym.c (add_symbol_to_list): Likewise.
	(record_pending_block): Likewise.
	(start_subfile): Likewise.
	(start_buildsym_compunit): Likewise.
	(push_subfile): Likewise.
	(end_symtab_get_static_block): Likewise.
	(buildsym_init): Likewise.
	* cli/cli-cmds.c (source_command): Likewise.
	* cli/cli-decode.c (add_cmd): Likewise.
	* cli/cli-script.c (build_command_line): Likewise.
	(setup_user_args): Likewise.
	(realloc_body_list): Likewise.
	(process_next_line): Likewise.
	(copy_command_lines): Likewise.
	* cli/cli-setshow.c (do_set_command): Likewise.
	* coff-pe-read.c (read_pe_exported_syms): Likewise.
	* coffread.c (coff_locate_sections): Likewise.
	(coff_symtab_read): Likewise.
	(coff_read_struct_type): Likewise.
	* common/cleanups.c (make_my_cleanup2): Likewise.
	* common/common-exceptions.c (throw_it): Likewise.
	* common/filestuff.c (make_cleanup_close): Likewise.
	* common/format.c (parse_format_string): Likewise.
	* common/queue.h (DEFINE_QUEUE_P): Likewise.
	* compile/compile-object-load.c (munmap_list_add): Likewise.
	(compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (append_args): Likewise.
	* corefile.c (specify_exec_file_hook): Likewise.
	* cp-support.c (make_symbol_overload_list): Likewise.
	* cris-tdep.c (push_stack_item): Likewise.
	(cris_gdbarch_init): Likewise.
	* ctf.c (ctf_trace_file_writer_new): Likewise.
	* dbxread.c (init_header_files): Likewise.
	(add_new_header_file): Likewise.
	(init_bincl_list): Likewise.
	(dbx_end_psymtab): Likewise.
	(start_psymtab): Likewise.
	(dbx_end_psymtab): Likewise.
	* dcache.c (dcache_init): Likewise.
	* dictionary.c (dict_create_hashed): Likewise.
	(dict_create_hashed_expandable): Likewise.
	(dict_create_linear): Likewise.
	(dict_create_linear_expandable): Likewise.
	* dtrace-probe.c (dtrace_process_dof_probe): Likewise.
	* dummy-frame.c (register_dummy_frame_dtor): Likewise.
	* dwarf2-frame-tailcall.c (cache_new_ref1): Likewise.
	* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
	(decode_frame_entry_1): Likewise.
	* dwarf2expr.c (new_dwarf_expr_context): Likewise.
	* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
	* dwarf2read.c (dwarf2_has_info): Likewise.
	(create_signatured_type_table_from_index): Likewise.
	(dwarf2_read_index): Likewise.
	(dw2_get_file_names_reader): Likewise.
	(create_all_type_units): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(init_tu_and_read_dwo_dies): Likewise.
	(init_cutu_and_read_dies): Likewise.
	(create_all_comp_units): Likewise.
	(queue_comp_unit): Likewise.
	(inherit_abstract_dies): Likewise.
	(read_call_site_scope): Likewise.
	(dwarf2_add_field): Likewise.
	(dwarf2_add_typedef): Likewise.
	(dwarf2_add_member_fn): Likewise.
	(attr_to_dynamic_prop): Likewise.
	(abbrev_table_alloc_abbrev): Likewise.
	(abbrev_table_read_table): Likewise.
	(add_include_dir): Likewise.
	(add_file_name): Likewise.
	(dwarf_decode_line_header): Likewise.
	(dwarf2_const_value_attr): Likewise.
	(dwarf_alloc_block): Likewise.
	(parse_macro_definition): Likewise.
	(set_die_type): Likewise.
	(write_psymtabs_to_index): Likewise.
	(create_cus_from_index): Likewise.
	(dwarf2_create_include_psymtab): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(build_type_psymtab_dependencies): Likewise.
	(read_comp_units_from_section): Likewise.
	(compute_compunit_symtab_includes): Likewise.
	(create_dwo_unit_in_dwp_v1): Likewise.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(read_func_scope): Likewise.
	(process_structure_scope): Likewise.
	(mark_common_block_symbol_computed): Likewise.
	(load_partial_dies): Likewise.
	(dwarf2_symbol_mark_computed): Likewise.
	* elfread.c (elf_symfile_segments): Likewise.
	(elf_read_minimal_symbols): Likewise.
	* environ.c (make_environ): Likewise.
	* eval.c (evaluate_subexp_standard): Likewise.
	* event-loop.c (create_file_handler): Likewise.
	(create_async_signal_handler): Likewise.
	(create_async_event_handler): Likewise.
	(create_timer): Likewise.
	* exec.c (build_section_table): Likewise.
	* fbsd-nat.c (fbsd_remember_child): Likewise.
	* fork-child.c (fork_inferior): Likewise.
	* frv-tdep.c (new_variant): Likewise.
	* gdbarch.sh (gdbarch_alloc): Likewise.
	(append_name): Likewise.
	* gdbtypes.c (rank_function): Likewise.
	(copy_type_recursive): Likewise.
	(add_dyn_prop): Likewise.
	* gnu-nat.c (make_proc): Likewise.
	(make_inf): Likewise.
	(gnu_write_inferior): Likewise.
	* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
	(build_std_type_info_type): Likewise.
	* guile/scm-param.c (compute_enum_list): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* guile/scm-value.c (gdbscm_value_call): Likewise.
	* h8300-tdep.c (h8300_gdbarch_init): Likewise.
	* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
	(read_unwind_info): Likewise.
	* ia64-tdep.c (ia64_gdbarch_init): Likewise.
	* infcall.c (dummy_frame_context_saver_setup): Likewise.
	(call_function_by_hand_dummy): Likewise.
	* infcmd.c (step_once): Likewise.
	(finish_forward): Likewise.
	(attach_command): Likewise.
	(notice_new_inferior): Likewise.
	* inferior.c (add_inferior_silent): Likewise.
	* infrun.c (add_displaced_stepping_state): Likewise.
	(save_infcall_control_state): Likewise.
	(save_inferior_ptid): Likewise.
	(_initialize_infrun): Likewise.
	* jit.c (bfd_open_from_target_memory): Likewise.
	(jit_gdbarch_data_init): Likewise.
	* language.c (add_language): Likewise.
	* linespec.c (decode_line_2): Likewise.
	* linux-nat.c (add_to_pid_list): Likewise.
	(add_initial_lwp): Likewise.
	* linux-thread-db.c (add_thread_db_info): Likewise.
	(record_thread): Likewise.
	(info_auto_load_libthread_db): Likewise.
	* m32c-tdep.c (m32c_gdbarch_init): Likewise.
	* m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise.
	* m68k-tdep.c (m68k_gdbarch_init): Likewise.
	* m88k-tdep.c (m88k_analyze_prologue): Likewise.
	* macrocmd.c (macro_define_command): Likewise.
	* macroexp.c (gather_arguments): Likewise.
	* macroscope.c (sal_macro_scope): Likewise.
	* macrotab.c (new_macro_table): Likewise.
	* mdebugread.c (push_parse_stack): Likewise.
	(parse_partial_symbols): Likewise.
	(parse_symbol): Likewise.
	(psymtab_to_symtab_1): Likewise.
	(new_block): Likewise.
	(new_psymtab): Likewise.
	(mdebug_build_psymtabs): Likewise.
	(add_pending): Likewise.
	(elfmdebug_build_psymtabs): Likewise.
	* mep-tdep.c (mep_gdbarch_init): Likewise.
	* mi/mi-main.c (mi_execute_command): Likewise.
	* mi/mi-parse.c (mi_parse_argv): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (terminate_minimal_symbol_table): Likewise.
	* mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* mn10300-tdep.c (mn10300_gdbarch_init): Likewise.
	* msp430-tdep.c (msp430_gdbarch_init): Likewise.
	* mt-tdep.c (mt_registers_info): Likewise.
	* nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise.
	* nat/linux-btrace.c (linux_enable_bts): Likewise.
	(linux_enable_pt): Likewise.
	* nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise.
	(linux_xfer_osdata_processgroups): Likewise.
	* nios2-tdep.c (nios2_gdbarch_init): Likewise.
	* nto-procfs.c (procfs_meminfo): Likewise.
	* objc-lang.c (start_msglist): Likewise.
	(selectors_info): Likewise.
	(classes_info): Likewise.
	(find_methods): Likewise.
	* objfiles.c (allocate_objfile): Likewise.
	(update_section_map): Likewise.
	* osabi.c (gdbarch_register_osabi): Likewise.
	(gdbarch_register_osabi_sniffer): Likewise.
	* parse.c (start_arglist): Likewise.
	* ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise.
	(hwdebug_insert_point): Likewise.
	* printcmd.c (display_command): Likewise.
	(ui_printf): Likewise.
	* procfs.c (create_procinfo): Likewise.
	(load_syscalls): Likewise.
	(proc_get_LDT_entry): Likewise.
	(proc_update_threads): Likewise.
	* prologue-value.c (make_pv_area): Likewise.
	(pv_area_store): Likewise.
	* psymtab.c (extend_psymbol_list): Likewise.
	(init_psymbol_list): Likewise.
	(allocate_psymtab): Likewise.
	* python/py-inferior.c (add_thread_object): Likewise.
	* python/py-param.c (compute_enum_values): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/py-varobj.c (py_varobj_iter_next): Likewise.
	* python/python.c (ensure_python_env): Likewise.
	* record-btrace.c (record_btrace_start_replaying): Likewise.
	* record-full.c (record_full_reg_alloc): Likewise.
	(record_full_mem_alloc): Likewise.
	(record_full_end_alloc): Likewise.
	(record_full_core_xfer_partial): Likewise.
	* regcache.c (get_thread_arch_aspace_regcache): Likewise.
	* remote-fileio.c (remote_fileio_init_fd_map): Likewise.
	* remote-notif.c (remote_notif_state_allocate): Likewise.
	* remote.c (demand_private_info): Likewise.
	(remote_notif_stop_alloc_reply): Likewise.
	(remote_enable_btrace): Likewise.
	* reverse.c (save_bookmark_command): Likewise.
	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
	* rx-tdep.c (rx_gdbarch_init): Likewise.
	* s390-linux-nat.c (s390_insert_watchpoint): Likewise.
	* ser-go32.c (dos_get_tty_state): Likewise.
	(dos_copy_tty_state): Likewise.
	* ser-mingw.c (ser_windows_open): Likewise.
	(ser_console_wait_handle): Likewise.
	(ser_console_get_tty_state): Likewise.
	(make_pipe_state): Likewise.
	(net_windows_open): Likewise.
	* ser-unix.c (hardwire_get_tty_state): Likewise.
	(hardwire_copy_tty_state): Likewise.
	* solib-aix.c (solib_aix_new_lm_info): Likewise.
	* solib-dsbt.c (dsbt_current_sos): Likewise.
	(dsbt_relocate_main_executable): Likewise.
	* solib-frv.c (frv_current_sos): Likewise.
	(frv_relocate_main_executable): Likewise.
	* solib-spu.c (spu_bfd_fopen): Likewise.
	* solib-svr4.c (lm_info_read): Likewise.
	(svr4_copy_library_list): Likewise.
	(svr4_default_sos): Likewise.
	* source.c (find_source_lines): Likewise.
	(line_info): Likewise.
	(add_substitute_path_rule): Likewise.
	* spu-linux-nat.c (spu_bfd_open): Likewise.
	* spu-tdep.c (info_spu_dma_cmdlist): Likewise.
	* stabsread.c (dbx_lookup_type): Likewise.
	(read_type): Likewise.
	(read_member_functions): Likewise.
	(read_struct_fields): Likewise.
	(read_baseclasses): Likewise.
	(read_args): Likewise.
	(_initialize_stabsread): Likewise.
	* stack.c (func_command): Likewise.
	* stap-probe.c (handle_stap_probe): Likewise.
	* symfile.c (addrs_section_sort): Likewise.
	(addr_info_make_relative): Likewise.
	(load_section_callback): Likewise.
	(add_symbol_file_command): Likewise.
	(init_filename_language_table): Likewise.
	* symtab.c (create_filename_seen_cache): Likewise.
	(sort_search_symbols_remove_dups): Likewise.
	(search_symbols): Likewise.
	* target.c (make_cleanup_restore_target_terminal): Likewise.
	* thread.c (new_thread): Likewise.
	(enable_thread_stack_temporaries): Likewise.
	(make_cleanup_restore_current_thread): Likewise.
	(thread_apply_all_command): Likewise.
	* tic6x-tdep.c (tic6x_gdbarch_init): Likewise.
	* top.c (gdb_readline_wrapper): Likewise.
	* tracefile-tfile.c (tfile_trace_file_writer_new): Likewise.
	* tracepoint.c (trace_find_line_command): Likewise.
	(all_tracepoint_actions_and_cleanup): Likewise.
	(make_cleanup_restore_current_traceframe): Likewise.
	(get_uploaded_tp): Likewise.
	(get_uploaded_tsv): Likewise.
	* tui/tui-data.c (tui_alloc_generic_win_info): Likewise.
	(tui_alloc_win_info): Likewise.
	(tui_alloc_content): Likewise.
	(tui_add_content_elements): Likewise.
	* tui/tui-disasm.c (tui_find_disassembly_address): Likewise.
	(tui_set_disassem_content): Likewise.
	* ui-file.c (ui_file_new): Likewise.
	(stdio_file_new): Likewise.
	(tee_file_new): Likewise.
	* utils.c (make_cleanup_restore_integer): Likewise.
	(add_internal_problem_command): Likewise.
	* v850-tdep.c (v850_gdbarch_init): Likewise.
	* valops.c (find_oload_champ): Likewise.
	* value.c (allocate_value_lazy): Likewise.
	(record_latest_value): Likewise.
	(create_internalvar): Likewise.
	* varobj.c (install_variable): Likewise.
	(new_variable): Likewise.
	(new_root_variable): Likewise.
	(cppush): Likewise.
	(_initialize_varobj): Likewise.
	* windows-nat.c (windows_make_so): Likewise.
	* x86-nat.c (x86_add_process): Likewise.
	* xcoffread.c (arrange_linetable): Likewise.
	(allocate_include_entry): Likewise.
	(process_linenos): Likewise.
	(SYMBOL_DUP): Likewise.
	(xcoff_start_psymtab): Likewise.
	(xcoff_end_psymtab): Likewise.
	* xml-support.c (gdb_xml_parse_attr_ulongest): Likewise.
	* xtensa-tdep.c (xtensa_register_type): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.

gdb/gdbserver/ChangeLog:

	* ax.c (gdb_parse_agent_expr): Likewise.
	(compile_bytecodes): Likewise.
	* dll.c (loaded_dll): Likewise.
	* event-loop.c (append_callback_event): Likewise.
	(create_file_handler): Likewise.
	(create_file_event): Likewise.
	* hostio.c (handle_open): Likewise.
	* inferiors.c (add_thread): Likewise.
	(add_process): Likewise.
	* linux-aarch64-low.c (aarch64_linux_new_process): Likewise.
	* linux-arm-low.c (arm_new_process): Likewise.
	(arm_new_thread): Likewise.
	* linux-low.c (add_to_pid_list): Likewise.
	(linux_add_process): Likewise.
	(handle_extended_wait): Likewise.
	(add_lwp): Likewise.
	(enqueue_one_deferred_signal): Likewise.
	(enqueue_pending_signal): Likewise.
	(linux_resume_one_lwp_throw): Likewise.
	(linux_resume_one_thread): Likewise.
	(linux_read_memory): Likewise.
	(linux_write_memory): Likewise.
	* linux-mips-low.c (mips_linux_new_process): Likewise.
	(mips_linux_new_thread): Likewise.
	(mips_add_watchpoint): Likewise.
	* linux-x86-low.c (initialize_low_arch): Likewise.
	* lynx-low.c (lynx_add_process): Likewise.
	* mem-break.c (set_raw_breakpoint_at): Likewise.
	(set_breakpoint): Likewise.
	(add_condition_to_breakpoint): Likewise.
	(add_commands_to_breakpoint): Likewise.
	(clone_agent_expr): Likewise.
	(clone_one_breakpoint): Likewise.
	* regcache.c (new_register_cache): Likewise.
	* remote-utils.c (look_up_one_symbol): Likewise.
	* server.c (queue_stop_reply): Likewise.
	(start_inferior): Likewise.
	(queue_stop_reply_callback): Likewise.
	(handle_target_event): Likewise.
	* spu-low.c (fetch_ppc_memory): Likewise.
	(store_ppc_memory): Likewise.
	* target.c (set_target_ops): Likewise.
	* thread-db.c (thread_db_load_search): Likewise.
	(try_thread_db_load_1): Likewise.
	* tracepoint.c (add_tracepoint): Likewise.
	(add_tracepoint_action): Likewise.
	(create_trace_state_variable): Likewise.
	(cmd_qtdpsrc): Likewise.
	(cmd_qtro): Likewise.
	(add_while_stepping_state): Likewise.
	* win32-low.c (child_add_thread): Likewise.
	(get_image_name): Likewise.
2015-08-26 17:18:12 -04:00
Pedro Alves 7f03bd92e3 PPC64: Fix gdb.arch/ppc64-atomic-inst.exp with displaced stepping
The ppc64 displaced step code can't handle atomic sequences.  Fallback
to stepping over the breakpoint in-line if we detect one.

gdb/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* infrun.c (displaced_step_prepare_throw): Return -1 if
	gdbarch_displaced_step_copy_insn returns NULL.  Update intro
	comment.
	* rs6000-tdep.c (LWARX_MASK, LWARX_INSTRUCTION, LDARX_INSTRUCTION)
	(STWCX_MASK, STWCX_INSTRUCTION, STDCX_INSTRUCTION): Move higher up
	in file.
	(ppc_displaced_step_copy_insn): New function.
	(ppc_displaced_step_fixup): Update comment.
	(rs6000_gdbarch_init): Install ppc_displaced_step_copy_insn as
	gdbarch_displaced_step_copy_insn hook.
	* gdbarch.sh (displaced_step_copy_insn): Document what happens on
	NULL return.
	* gdbarch.h: Regenerate.

gdb/testsuite/ChangeLog:
2015-08-07  Pedro Alves  <palves@redhat.com>

	* gdb.arch/ppc64-atomic-inst.exp (do_test): New procedure, move
	tests here.
	(top level): Run do_test with and without displaced stepping.
2015-08-07 17:26:21 +01:00
Pierre Langlois 6b940e6a06 Remove isize output argument from fast_tracepoint_valid_at
This patch removes the isize output argument from the
fast_tracepoint_valid_at gdbarch hook.  It was used to return the size
of the instruction that needs to be replaced when installing a fast
tracepoint.  Instead of getting this value from the
fast_tracepoint_valid_at hook, we can call the gdb_insn_length function.

If we do not do this, then architectures which do not have a restriction
on where to install the fast tracepoint will send uninitialized memory
off to GDBserver.  See remote_download_tracepoint:

~~~
int isize;

if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
				      tpaddr, &isize, NULL))
  xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
	     isize);
~~~

The default implementation of fast_tracepoint_valid_at will not set
isize resulting in uninitialized memory being sent.  Later on, GDBserver
could use this information to compute a jump offset.

gdb/ChangeLog:

	* arch-utils.c (default_fast_tracepoint_valid_at): Remove unused
	isize argument.
	* arch-utils.h (default_fast_tracepoint_valid_at): Likewise.
	* breakpoint.c (check_fast_tracepoint_sals): Adjust call to
	gdbarch_fast_tracepoint_valid_at.
	* gdbarch.sh (fast_tracepoint_valid_at): Remove isize argument.
	* gdbarch.h: Regenerate.
	* gdbarch.c: Regenerate.
	* i386-tdep.c (i386_fast_tracepoint_valid_at): Remove isize
	argument.  Do not set it.
	* remote.c (remote_download_tracepoint): Adjust call to
	gdbarch_fast_tracepoint_valid_at.  Call gdb_insn_length to get
	the instruction length.
2015-07-30 18:05:00 +01:00
Simon Marchi 3374165f51 gdbarch: add addressable_memory_unit_size method
Add a new gdbarch method to get the length of an addressable memory unit
for a given architecture. The default implementation returns 1.

gdb/ChangeLog:

	* arch-utils.h (default_addressable_memory_unit_size): New.
	* arch-utils.c (default_addressable_memory_unit_size): New.
	* gdbarch.sh (addressable_memory_unit_size): New.
	* gdbarch.h: Re-generate.
	* gdbarch.c: Re-generate.
2015-06-12 16:51:51 -04:00
Jan Kratochvil 7f36105668 compile: Use also inferior munmap
Currently inferior memory is allocated by inferior mmap() but it is never
deallocated; despite the injected objfile incl. its symbols is freed.  This was
intentional so that one can do for example:
inferior:
	char *str = "foo";
GDB:
	(gdb) compile code str = "bar";

I believe later patches will be needed to introduce full control over keeping
vs. discarding the injected module as being discussed in:
	compile: objfiles lifetime UI
	https://sourceware.org/ml/gdb/2015-04/msg00051.html
	Message-ID: <20150429135735.GA16974@host1.jankratochvil.net>
	https://sourceware.org/ml/gdb/2015-05/msg00007.html

As decided by Phil it is better not to leak inferior pages as users can
workaround the issue above for example by:
	(gdb) compile code str = strdup ("bar");

I have checked that in fact gdb/doc/ (written by Phil) already expects the
injected code will be unmapped so that does not need to be changed:
	compile code int ff = 5; p = &ff;
	In this example, @code{p} would point to @code{ff} when the
	@code{compile} command is executing the source code provided to it.
	However, as variables in the (example) program persist with their
	assigned values, the variable @code{p} would point to an invalid
	location when the command exists.

gdb/ChangeLog
2015-04-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* arch-utils.c (default_infcall_munmap): New.
	* arch-utils.h (default_infcall_munmap): New declaration.
	* compile/compile-object-load.c (struct munmap_list, munmap_list_add)
	(munmap_list_free, munmap_listp_free_cleanup): New.
	(struct setup_sections_data): Add field munmap_list_headp.
	(setup_sections): Call munmap_list_add.
	(compile_object_load): New variable munmap_list_head, initialize
	setup_sections_data.munmap_list_headp, return munmap_list_head.
	* compile/compile-object-load.h (struct munmap_list): New declaration.
	(struct compile_module): Add field munmap_list_head.
	(munmap_list_free): New declaration.
	* compile/compile-object-run.c (struct do_module_cleanup): Add field
	munmap_list_head.
	(do_module_cleanup): Call munmap_list_free.
	(compile_object_run): Pass munmap_list_head to do_module_cleanup.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
	* gdbarch.sh (infcall_munmap): New.
	* linux-tdep.c (linux_infcall_munmap): New.
	(linux_init_abi): Install it.

gdb/testsuite/ChangeLog
2015-04-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.compile/compile.exp (keep jit in memory): Rename to ...
	(do not keep jit in memory): ... this.
	(expect 5): Change it to ...
	(expect no 5): ... this.
2015-06-03 21:26:04 +02:00
Martin Galvan c9cf6e20c6 Rename in_function_epilogue_p to stack_frame_destroyed_p
We concluded that gdbarch_in_function_epilogue_p is misnamed, since it
returns true if the given PC is one instruction after the one that
destroyed the stack (which isn't necessarily inside an epilogue),
therefore it should be renamed to stack_frame_destroyed_p.

I also took the liberty of renaming the arch-specific implementations to
*_stack_frame_destroyed_p as well for consistency.

gdb:

2015-05-26  Martin Galvan  <martin.galvan@tallertechnologies.com>

	* amd64-tdep.c: Replace in_function_epilogue_p with
	stack_frame_destroyed_p throughout.
	* arch-utils.c: Ditto.
	* arch-utils.h: Ditto.
	* arm-tdep.c: Ditto.
	* breakpoint.c: Ditto.
	* gdbarch.sh: Ditto.
	* hppa-tdep.c: Ditto.
	* i386-tdep.c: Ditto.
	* mips-tdep.c: Ditto.
	* nios2-tdep.c: Ditto.
	* rs6000-tdep.c: Ditto.
	* s390-linux-tdep.c: Ditto.
	* score-tdep.c: Ditto.
	* sh-tdep.c: Ditto.
	* sparc-tdep.c: Ditto.
	* sparc-tdep.h: Ditto.
	* sparc64-tdep.c: Ditto.
	* spu-tdep.c: Ditto.
	* tic6x-tdep.c: Ditto.
	* tilegx-tdep.c: Ditto.
	* xstormy16-tdep.c: Ditto.
	* gdbarch.c, gdbarch.h: Re-generated.
2015-05-26 12:07:59 +01:00
Pedro Alves 8a526fa69a gdbarch.h: include regcache.h
Building GDB in C++ mode, I got:

  src/gdb/gdbarch.h:240:149: error: invalid type in declaration before ‘;’ token
  src/gdb/gdbarch.h:240:14: error: use of enum ‘register_status’ without previous declaration
  src/gdb/gdbarch.h:241:13: error: use of enum ‘register_status’ without previous declaration
  src/gdb/gdbarch.h:241:140: error: invalid type in declaration before ‘;’ token

That's because 'enum register_status' has not been declared (and we can't
forward declare enums in C++).

gdb/ChangeLog:
2015-02-27  Pedro Alves  <palves@redhat.com>

	* gdbarch.sh: Include regcache.h.
	* gdbarch.h: Regenerate.
2015-02-27 17:39:54 +00:00
Jose E. Marchesi 8b367e1771 New gdbarch functions: dtrace_parse_probe_argument, dtrace_probe_is_enabled, dtrace_enable_probe, dtrace_disable_probe.
This patch adds several gdbarch functions (along with the corresponding
predicates): `dtrace_parse_probe_argument', `dtrace_probe_is_enabled',
`dtrace_enable_probe' and `dtrace_disable_probe'.  These functions will
be implemented by target-specific code, and called from the DTrace
probes implementation in order to calculate the value of probe
arguments, and manipulate is-enabled probes.

gdb/ChangeLog:

2015-02-17  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* gdbarch.sh (dtrace_parse_probe_argument): New.
	(dtrace_probe_is_enabled): Likewise.
	(dtrace_enable_probe): Likewise.
	(dtrace_disable_probe): Likewise.
	* gdbarch.c: Regenerate.
	* gdbarch.h: Regenerate.
2015-02-17 15:54:44 +01:00