Commit Graph

106857 Commits

Author SHA1 Message Date
Mike Frysinger
bdedb2d21b sim: callback: extend syscall interface to handle 7 args
The Linux syscall interface, depending on architecture, handles up to
7 arguments.  Extend the callback API to handle those.
2021-06-24 23:51:16 -04:00
GDB Administrator
22c6cfe9c8 Automatic date update in version.in 2021-06-25 00:00:11 +00:00
Tom de Vries
013270a16a [gdb/testsuite] Fix duplicate in gdb.base/info-macros.exp
When running test-case gdb.base/info-macros.exp, I run into:
...
PASS: gdb.base/info-macros.exp: info macro --
PASS: gdb.base/info-macros.exp: info macro --
DUPLICATE: gdb.base/info-macros.exp: info macro --
PASS: gdb.base/info-macros.exp: info macro  --
...

These messages come from gdb_test calls using the following commands:
- "info macro --"
- "info macro -- "
- "info macro  -- ".

Apparantly the test names get stripped of trailing whitespace, and the first
two end up identical.

Fix this by explicitly specifying an <EOL> after the trailing whitespace in
the test name, such that we have:
...
PASS: gdb.base/info-macros.exp: info macro --
PASS: gdb.base/info-macros.exp: info macro -- <EOL>
PASS: gdb.base/info-macros.exp: info macro  -- <EOL>
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-06-24  Tom de Vries  <tdevries@suse.de>

	* gdb.base/info-macros.exp: Add <EOL> after trailing whitespace in
	test names.
2021-06-24 12:55:08 +02:00
Tom de Vries
657dcee4cf [gdb/testsuite] Fix duplicate in gdb.base/argv0-symlink.exp
I found the following duplicates in gdb.base/argv0-symlink.exp:
...
DUPLICATE: gdb.base/argv0-symlink.exp: set print repeats 10000
DUPLICATE: gdb.base/argv0-symlink.exp: set print elements 10000
...

Fix these by using with_test_prefix "file symlink" / "dir symlink".

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-06-24  Tom de Vries  <tdevries@suse.de>

	* gdb.base/argv0-symlink.exp: Use with_test_prefix.
2021-06-24 12:08:54 +02:00
Clément Chigot
1daf786ba3 gas: update csect alignment for PPC prefixed instructions on XCOFF
Power10 prefixed instructions must not cross 64-byte boundaries.
This is already handled.
However, on XCOFF, the csect must be updated to match the new
alignment.

	* config/tc-ppc.c (md_assemble): Update ppc_current_csect
	alignment when finding prefixed instructions.
2021-06-24 10:51:27 +09:30
Mike Frysinger
2f631626f1 sim: syscall: handle killing the sim itself
If code tries to send a signal to itself, the callback layer ignores
it and forces the caller to handle it.  This allows the sim to turn
that into an engine halt rather than actually killing the sim.
2021-06-23 20:11:45 -04:00
Mike Frysinger
e91488f739 sim: cris: override getpid callback
The cris linux syscall layers assume getpid returns a constant,
so add a custom function to provide that.
2021-06-23 20:10:08 -04:00
Mike Frysinger
d394a6efed sim: callback: add a kill interface
This will make it easier to emulate the syscall.  If the kill target
is the sim itself, don't do anything.  This forces the higher layers
to make a decision as to how to handle this event: like halting the
overall engine process.
2021-06-23 20:05:14 -04:00
GDB Administrator
02ddf7223d Automatic date update in version.in 2021-06-24 00:00:09 +00:00
Mike Frysinger
b34084121a sim: switch common srcdir to abs_srcdir
We rewrite srcdir in subdir Makefiles that we generate from the common
parent dir since it points to the parent dir.  Since @srcdir@ can be a
variety of formats (relative & absolute), switch to @abs_srcdir@ which
is a lot easier to adjust.  Our use of srcdir in here should handle it.
2021-06-23 18:12:43 -04:00
Tom de Vries
2dd865d7c1 [gdb/testsuite] Rewrite gdb_test_lines
On Ubuntu 20.04, when the debug info package for libc is not installed,
I get:

    FAIL: gdb.base/info-types-c++.exp: info types
    FAIL: gdb.base/info-types-c.exp: info types

The reason is that the output of info types is exactly:

    (gdb) info types
    All defined types:

    File /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/info-types.c:
    52:     typedef enum {...} anon_enum_t;
    45:     typedef struct {...} anon_struct_t;
    68:     typedef union {...} anon_union_t;
    28:     typedef struct baz_t baz;
    31:     typedef struct baz_t * baz_ptr;
    21:     struct baz_t;
            double
    33:     enum enum_t;
            float
            int
    38:     typedef enum enum_t my_enum_t;
    17:     typedef float my_float_t;
    16:     typedef int my_int_t;
    54:     typedef enum {...} nested_anon_enum_t;
    47:     typedef struct {...} nested_anon_struct_t;
    70:     typedef union {...} nested_anon_union_t;
    30:     typedef struct baz_t nested_baz;
    29:     typedef struct baz_t nested_baz_t;
    39:     typedef enum enum_t nested_enum_t;
    19:     typedef float nested_float_t;
    18:     typedef int nested_int_t;
    62:     typedef union union_t nested_union_t;
    56:     union union_t;
            unsigned int
    (gdb)

The lines we expect in the test contain an empty line at the end:

    ...
    "62:\[\t \]+typedef union union_t nested_union_t;" \
    "56:\[\t \]+union union_t;" \
    "--optional" "\[\t \]+unsigned int" \
    ""]

This is written with the supposition that other files will be listed, so
an empty line will be included to separate the symbols from this file
from the next one.  This empty line is not included when info-types.c is
the only file listed.

Fix this by rewriting gdb_test_lines to accept a single, plain tcl multiline
regexp, such that we can write:
...
    "62:\[\t \]+typedef union union_t nested_union_t;" \
    "56:\[\t \]+union union_t;(" \
    "\[\t \]+unsigned int)?" \
    "($|\r\n.*)"]
...

Tested affected test-cases:
- gdb.base/info-types-c.exp
- gdb.base/info-types-c++.exp
- gdb.base/info-macros.exp
- gdb.cp/cplusfuncs.exp
on x86_64-linux (openSUSE Leap 15.2), both with check and check-read1.

Also tested the first two with gcc-4.8.

Also tested on ubuntu 18.04.

gdb/testsuite/ChangeLog:

2021-06-23  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_test_lines): Rewrite to accept single
	multiline tcl regexp.
	* gdb.base/info-types.exp.tcl: Update.  Make empty line at end of
	regexp optional.
	* gdb.base/info-macros.exp: Update.
	* gdb.cp/cplusfuncs.exp: Update.
2021-06-23 23:46:04 +02:00
GDB Administrator
0b98ef1642 Automatic date update in version.in 2021-06-23 00:00:11 +00:00
Mike Frysinger
072d63a871 sim: cris: fix a few warnings
Include header for hw funcs called, adjust prototype to match the
args given to it, and adjust cast to match the function.
2021-06-22 19:41:00 -04:00
Mike Frysinger
13b0d6e5a2 sim: callback: add missing cb_target_to_host_signal
There's been a prototype for this forever, but the implementation was
missing.  Probably because there weren't any callers, but we'll start
using it to implement the kill function.
2021-06-22 19:38:48 -04:00
Mike Frysinger
cc40b4f2a3 sim: callback: generate signal map
We've been generating the syscall/errno/open maps, but not the signal
map, even though we've been including them in the source constants.
2021-06-22 19:38:09 -04:00
Mike Frysinger
c45cffdbe1 sim: callback: add a getpid interface
Rather than hit the OS interface directly, use the existing callback
layer so the instantiator can decide behavior.
2021-06-22 19:36:28 -04:00
Mike Frysinger
e173c80fbb sim: rx: merge with common configure script
Move the unique configure flag to acinclude.m4 so the common code
can include it, then delete the rx configure logic entirely.
2021-06-22 19:29:28 -04:00
Mike Frysinger
36bb57e40c sim: drop configure scripts for simple ports
These ports only use the pieces that have been unified, so we can
merge them into the common configure script and get rid of their
unique one entirely.

We still compile & link separate run programs, and have dedicated
subdir Makefiles, but the configure script portion is merged.
2021-06-22 19:26:13 -04:00
Simon Marchi
224506e95d gdb: fix python/lib/gdb/__init__.py formatting
Run black to fix this formatting.

gdb/ChangeLog:

	* python/lib/gdb/__init__.py: Format.

Change-Id: I68ea306d1991bf7243b2c8aeeb11719d668851e5
2021-06-22 15:07:50 -04:00
Simon Marchi
ac0d67ed1d gdb: remove unnecessary parameter wait_ptid from do_target_wait
do_target_wait has a wait_ptid parameter, to filter what ptid we wait
on.  The sole caller of do_target_wait passes minus_one_ptid, meaning
"all ptids".  So in practice, this parameter is not needed, remove it.

gdb/ChangeLog:

	* infrun.c (do_target_wait): Remove wait_ptid parameter.
	(fetch_inferior_event): Adjust.

Change-Id: I54119beb43db678e4b2081dc490f89e7ff878e74
2021-06-22 14:57:29 -04:00
Simon Marchi
4e317a765b gdb/python: print name of unwinder that claimed frame in debug message
If we have multiple registered unwinders, this will helps identify which
unwinder was chosen and make it easier to track down potential problems.
Unwinders have a mandatory name argument, which we can use in the
message.

First, make gdb._execute_unwinders return a tuple containing the name,
in addition to the UnwindInfo.  Then, make pyuw_sniffer include the name
in the debug message.

I moved the debug message earlier.  I think it's good to print it as
early as possible, so that we see it in case an assert is hit in the
loop below, for example.

gdb/ChangeLog:

	* python/lib/gdb/__init__.py (_execute_unwinders): Return tuple
	with name of chosen unwinder.
	* python/py-unwind.c (pyuw_sniffer): Print name of chosen
	unwinder in debug message.

Change-Id: Id603545b44a97df2a39dd1872fe1f38ad5059f03
2021-06-22 14:47:10 -04:00
Andreas Schwab
80d1206d7f gdb: Support DW_LLE_start_end
Without that it is impossible to debug on riscv64.

gdb/
	PR symtab/27999
	* dwarf2/loc.c (decode_debug_loclists_addresses): Support
	DW_LLE_start_end.

gdb/testsuite/
	PR symtab/27999
	* lib/dwarf.exp (start_end): New proc inside loclists.
	* gdb.dwarf2/loclists-start-end.exp: New file.
	* gdb.dwarf2/loclists-start-end.c: New file.
2021-06-22 16:39:01 +02:00
Tom de Vries
e5b771060e [gdb/testsuite] Add gdb.dwarf2/imported-unit-c.exp
This test-case is intended to excercise this code in process_imported_unit_die:
...
      /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
	 into another compilation unit, at root level.  Regard this as a hint,
	 and ignore it.  */
      if (die->parent && die->parent->parent == NULL
	  && per_cu->unit_type == DW_UT_compile
	  && per_cu->lang == language_cplus)
	return;
...
in the sense that the test-case should fail if the
"per_cu->lang == language_cplus" clause is removed.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2021-06-22  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/imported-unit-c.exp: New file.
2021-06-22 15:58:09 +02:00
Nelson Chu
50331d64f1 RISC-V: Clarify the addends of pc-relative access.
The original discussion was here,
https://github.com/riscv/riscv-elf-psabi-doc/issues/184

After discussing with Kito Cheng, I think the addends of %pcrel_hi
and %pcrel_lo are both allowed in GNU toolchain.  However, both of
the them mean the offset of symbols, rather than the pc address.
But the addends of %got_pcrel_hi and it's %pcrel_lo do not look
reasonable.  I believe gcc won't generate the got patterns with
addends, so linker should report dangerous relocation errors,
in case the assembly code use them.

Another issue was here,
https://sourceware.org/pipermail/binutils/2021-June/116983.html

At the beginnig, I suppose %pcrel_hi and %pcrel_lo are valid only
when they are in the same input section.  But Jim Wilson points out
that gcc may generate %hi and %lo in the different input sections,
when -freorder-blocks-and-partition option is used.  So that a memory
references for a loop may have the %hi outside the loop, but the %lo
remain in the loop.  However, it is hard to create the testcases,
to see if %pcrel_hi and %pcrel_lo have the same behavior.

Unfortunately, I notice that the current pcrel resolver cannot
work for the above case.  For now we build a hash table for pcrel
at the start of riscv_elf_relocate_section, and then free the hash
at the end.  But riscv_elf_relocate_section only handles an input
section at a time, so that means we can only resolve the %pcrel_hi
and %pcrel_lo which are in the same input section.  Otherwise, like
the above case, we will report "%pcrel_lo missing matching %pcrel_hi"
for them.  I have no plan to improve this in the short-term, so maybe
we can wait until someone meets the problem before we deal with it.

bfd/
    * elfnn-riscv.c (riscv_pcrel_hi_reloc): Added field to store
    the original relocation type, in case the type is converted to
    R_RISCV_HI20.
    (riscv_pcrel_lo_reloc): Removed unused name field.
    (riscv_pcrel_relocs): Added comments.
    (riscv_zero_pcrel_hi_reloc): Removed unused input_bfd.
    (riscv_record_pcrel_hi_reloc): Updated.
    (riscv_record_pcrel_lo_reloc): Likewise.
    (riscv_resolve_pcrel_lo_relocs): Likewise.  Check the original
    type of auipc, to make sure the %pcrel_lo without any addends.
    Otherwise, report dangerous relocation error.
    (riscv_elf_relocate_section): Updated above functions are changed.
    For R_RISCV_GOT_HI20, report dangerous relocation error when addend
    isn't zero.
ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.d: New testcase.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.d: New testcase.
    Should report error since the %pcrel_lo with addend refers to
    %got_pcrel_hi.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.d: New testcase.
    Should report error since the %got_pcrel_hi with addend.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.s: Likewise.
    * testsuite/ld-riscv-elf/pcrel-lo-addend-3.ld: Likewise.
2021-06-22 17:14:55 +08:00
Andrew Burgess
80dc83fd0e gdb/remote: handle target dying just before a stepi
I randomly hit a situation where gdbserver crashed immediately before
I issued a 'stepi' to GDB, it turns out that this causes GDB itself to
crash.

What happens is that as part of the stepi we try to insert some
breakpoints into the inferior, so from insert_breakpoints we figure
out what we want to insert, then, eventually, try to send some packets
to the remote to get the breakpoints inserted.

It is only at this point that GDB realises that the target has gone
away.  This causes GDB to then enter this call stack:

  unpush_and_perror
    remote_unpush_target
      generic_mourn_inferior
        breakpoint_init_inferior
          delete_breakpoint
            update_global_location_list

So, we realise the target is gone and so delete the breakpoints
associated with that target.

GDB then throws a TARGET_CLOSE_ERROR from unpush_and_error.

This error is caught in insert_breakpoints where we then try to print
a nice error saying something like:

  Cannot insert breakpoint %d: some error text here...

To fill in the '%d' we try to read properties of the breakpoint
object.

Which was deleted due to the delete_breakpoint call above.

And so GDB dies...

My proposal in this commit is that, should we catch a
TARGET_CLOSE_ERROR in insert_breakpoints, then we just rethrow the
error.

This will cause the main event loop to print something like:

  Remote connection closed

Which I think is fine, I don't think the user will care much which
particular breakpoint GDB was operating on when the connection closed,
just knowing that the connection closed should be enough I think.

I initially added a test to 'gdb.server/server-kill.exp' for this
issue, however, my first attempt was not good enough, the test was
passing even without my fix.

Turns out that the server-kill.exp test actually kills the PID of the
inferior, not the PID of the server.  This means that gdbserver is
actually able to send a packet to GDB saying that the inferior has
exited prior to gdbserver itself shutting down.  This extra
information was enough to prevent the bug I was seeing manifest.

So, I have extended server-kill.exp to run all of the tests twice, the
first time we still kill the inferior.  On the second run we hard kill
the gdbserver itself, this prevents the server from sending anything
to GDB before it exits.

My new test is only expected to fail in this second mode of
operation (killing gdbserver itself), and without my fix, that is what
I see.

gdb/ChangeLog:

	* breakpoint.c (insert_bp_location): If we catch a
	TARGET_CLOSE_ERROR just rethrow it, the breakpoints might have
	been deleted.

gdb/testsuite/ChangeLog:

	* gdb.server/server-kill.exp: Introduce global kill_pid_of, and
	make use of this in prepare to select which pid we should kill.
	Run all the tests twice with a different kill_pid_of value.
	(prepare): Make use of kill_pid_of.
	(test_stepi): New proc.
2021-06-22 10:03:02 +01:00
Andrew Burgess
46b8b3d6f8 opcodes: make use of __builtin_popcount when available
This commit provides a small performance improvement when starting up
CGEN based disassemblers by making use of __builtin_popcount.

The #if check used in this commit was copied from bfd/elf32-arm.c
where __builtin_popcount is also used.

I ran into this code while investigating some GDB tests that would
occasionally timeout.  One of the reason these tests were having
problems is that the m16c and m32c disassemblers take so long to
initialise themselves.  Speeding up count_decodable_bits helps, but is
not a total solution.  Still, this felt like an easy win which added
minimal extra complexity, so I figure its worth doing.

opcodes/ChangeLog:

	* cgen-dis.c (count_decodable_bits): Use __builtin_popcount when
	available.
2021-06-22 09:53:13 +01:00
Alan Modra
ded5cb9444 picojava assembler and disassembler fixes
Commit 54758c3e39 made changes to the picojava support based on
https://sourceware.org/pipermail/binutils/2005-November/045136.html
An update from picojava to picojava II, I think.  Unfortunately the
patch neglected any changes to the gas testsuite, resulting in
"FAIL: pj" since that date.  This patch makes a few relatively simple
changes to cure the regression.

gas/
	* config/tc-pj.c (md_apply_fix): Apply PJ_CODE_REL32 relocs.
	* testsuite/gas/pj/ops.s: Update jsr, ret, getstatic,
	putstatic, getfield, putfield, invokevirtual, invokespecial,
	invokestatic, invokeinterface, goto_w, jsr_w assembly.  Delete
	version 1 picojava opcodes.
	* testsuite/gas/pj/ops.d: Match expected output.
opcodes/
	* pj-dis.c (print_insn_pj): Don't print trailing tab.  Do
	print separator for pcrel insns.
2021-06-22 17:44:45 +09:30
Mike Frysinger
456ef1c1d4 sim: unify hardware settings
Move these options up to the common dir so we only test & export
them once across all ports.
2021-06-21 22:20:18 -04:00
Mike Frysinger
be0387eed0 sim: hw: rework configure option & device selection
The sim-hardware configure option allows builders to select a set of
device models to enable.  But this seems like unnecessary overkill:
the existence of individual device models doesn't affect performance
at all as they are only enabled at runtime if the config uses them,
and individually these are all <5KB a piece.  Stripping off a total
of ~50KB from a ~1MB binary doesn't seem useful, and it's extremely
unlikely anyone will ever bother.

So let's simplify the configure/make logic by turning sim-hardware
into a boolean option like many of the other sim options.  Any ports
that have unique device models will declare them in their Makefile
instead of at configure time.  This will allow us to (eventually)
unify the setting into the common dir.
2021-06-21 21:36:51 -04:00
GDB Administrator
b4ee29a445 Automatic date update in version.in 2021-06-22 00:00:08 +00:00
Andrew Burgess
96f842cbdb gdb/riscv: add support for vector registers in target descriptions
This commit adds support to RISC-V GDB for vector registers in the
incoming target description.

The vector registers should be described in a feature called
"org.gnu.gdb.riscv.vector", and should contain the register v0 to
v31.  There's no restriction on the size or type of these registers,
so the target description can set these up as it requires.

However, if the target feature is present then all of the registers
must be present, and they must all be the same size, these
requirements are, I believe, inline with the RISC-V vector extension.

The DWARF register numbers for the vector registers have been added,
and the code to map between GDB's internal numbering and the DWARF
numbering has been updated.

I have not yet added a feature/riscv/*.xml file for the vector
extension, the consequence of this is that we can't, right now, detect
vector registers on a native target, this patch is all about
supporting vectors on a remote target.

It is worth noting that I don't actually have access to a RISC-V
target with vectors, so the only testing that this patch has had has
been done using 'set tdesc filename ....' to load a target description
to which I have manually added the vector feature.  This has shown
that the vector register feature can be successfully parsed, and that
the registers show up in the expected register groups.

Additionally, the RISC-V vector extension is currently at v0.10, which
is also the v1.0 draft release.  However, this extension is not yet
finalised.  It is possible (but unlikely I think) that the register
set could change between now and the final release of the vector
extension.  If this were to happen then we would potentially end up
changing the requirements for the new org.gnu.gdb.riscv.vector
feature.  I really don't think it is likely that the register set will
change this late in the process, and even if it did, changing the
feature requirements will not be a problem as far as I am
concerned (when the alternative is GDB just continues without this
feature for now).

gdb/ChangeLog:

	* NEWS: Mention new target feature name.
	* arch/riscv.c (riscv_create_target_description): GDB doesn't
	currently create target descriptions containing vector registers.
	* arch/riscv.h (struct riscv_gdbarch_features) <vlen>: New member
	variable.
	<operator==>: Also compare vlen.
	<hash>: Also include vlen.
	* riscv-tdep.c (riscv_feature_name_vector): New static global.
	(struct riscv_vector_feature): New struct.
	(riscv_vector_feature): New static global.
	(riscv_register_reggroup_p): Ensure vector registers are part of
	the 'all' group, and part of the 'vector' group.
	(riscv_dwarf_reg_to_regnum): Handle vector registers.
	(riscv_gdbarch_init): Check vector register feature.
	* riscv-tdep.h: Add vector registers to GDB's internal register
	numbers, and to the DWARF register numbers.

gdb/doc/ChangeLog:

	* gdb.texinfo (RISC-V Features): Mention vector register feature.
2021-06-21 20:47:13 +01:00
Andrew Burgess
d52b800721 gdb/python: add PendingFrame.level and Frame.level methods
Add new methods to the PendingFrame and Frame classes to obtain the
stack frame level for each object.

The use of 'level' as the method name is consistent with the existing
attribute RecordFunctionSegment.level (though this is an attribute
rather than a method).

For Frame/PendingFrame I went with methods as these classes currently
only use methods, including for simple data like architecture, so I
want to be consistent with this interface.

gdb/ChangeLog:

	* NEWS: Mention the two new methods.
	* python/py-frame.c (frapy_level): New function.
	(frame_object_methods): Register 'level' method.
	* python/py-unwind.c (pending_framepy_level): New function.
	(pending_frame_object_methods): Register 'level' method.

gdb/doc/ChangeLog:

	* python.texi (Unwinding Frames in Python): Mention
	PendingFrame.level.
	(Frames In Python): Mention Frame.level.

gdb/testsuite/ChangeLog:

	* gdb.python/py-frame.exp: Add Frame.level tests.
	* gdb.python/py-pending-frame-level.c: New file.
	* gdb.python/py-pending-frame-level.exp: New file.
	* gdb.python/py-pending-frame-level.py: New file.
2021-06-21 16:20:08 +01:00
Andrew Burgess
8b9c48b287 gdb/python: move PyLong_From* calls into py-utils.c
We already have two helper functions in py-utils.c:

  gdb_py_object_from_longest (LONGEST l)
  gdb_py_object_from_ulongest (ULONGEST l)

these wrap around calls to either PyLong_FromLongLong,
PyLong_FromLong, or PyInt_From_Long (if Python 2 is being used).

There is one place in gdb/python/* where a call to PyLong_FromLong was
added outside of the above utility functions, this was done in the
recent commit:

  commit 55789354fc
  Date:   Fri May 14 11:56:31 2021 +0200

      gdb/python: add a 'connection_num' attribute to Inferior objects

In this commit I replace the direct use of PyLong_FromLong with a call
to gdb_py_object_from_longest.  The only real change with this commit,
is that, for Python 2, we will now end up calling PyInt_FromLong
instead of PyLong_FromLong, but this should be invisible to the user.
For Python 3 there should be absolutely no change.

gdb/ChangeLog:

	* python/py-inferior.c (infpy_get_connection_num): Call
	gdb_py_object_from_longest instead of PyLong_FromLong directly.
2021-06-21 16:09:06 +01:00
Andrew Burgess
61e2dde2db gdb/python: handle saving user registers in a frame unwinder
This patch came about because I wanted to write a frame unwinder that
would corrupt the backtrace in a particular way.  In order to achieve
what I wanted I ended up trying to write an unwinder like this:

  class FrameId(object):
      .... snip class definition ....

  class TestUnwinder(Unwinder):
      def __init__(self):
          Unwinder.__init__(self, "some name")

      def __call__(self, pending_frame):
          pc_desc = pending_frame.architecture().registers().find("pc")
          pc = pending_frame.read_register(pc_desc)

          sp_desc = pending_frame.architecture().registers().find("sp")
          sp = pending_frame.read_register(sp_desc)

          # ... snip code to decide if this unwinder applies or not.

          fid = FrameId(pc, sp)
          unwinder = pending_frame.create_unwind_info(fid)
          unwinder.add_saved_register(pc_desc, pc)
          unwinder.add_saved_register(sp_desc, sp)
          return unwinder

The important things here are the two calls:

          unwinder.add_saved_register(pc_desc, pc)
          unwinder.add_saved_register(sp_desc, sp)

On x86-64 these would fail with an assertion error:

  gdb/regcache.c:168: internal-error: int register_size(gdbarch*, int): Assertion `regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch)' failed.

What happens is that in unwind_infopy_add_saved_register (py-unwind.c)
we call register_size, as register_size should only be called on
cooked (real or pseudo) registers, and 'pc' and 'sp' are implemented
as user registers (at least on x86-64), we trigger the assertion.

A simple fix would be to check in unwind_infopy_add_saved_register if
the register number we are handling is a cooked register or not, if
not we can throw a 'Bad register' error back to the Python code.

However, I think we can do better.

Consider that at the CLI we can do this:

  (gdb) set $pc=0x1234

This works because GDB first evaluates '$pc' to get a register value,
then evaluates '0x1234' to create a value encapsulating the
immediate.  The contents of the immediate value are then copied back
to the location of the register value representing '$pc'.

The value location for a user-register will (usually) be the location
of the real register that was accessed, so on x86-64 we'd expect this
to be $rip.

So, in this patch I propose that in the unwinder code, when
add_saved_register is called, if it is passed a
user-register (i.e. non-cooked) then we first fetch the register,
extract the real register number from the value's location, and use
that new register number when handling the add_saved_register call.

If either the value location that we get for the user-register is not
a cooked register then we can throw a 'Bad register' error back to the
Python code, but in most cases this will not happen.

gdb/ChangeLog:

	* python/py-unwind.c (unwind_infopy_add_saved_register): Handle
	saving user registers.

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind-user-regs.c: New file.
	* gdb.python/py-unwind-user-regs.exp: New file.
	* gdb.python/py-unwind-user-regs.py: New file.
2021-06-21 16:09:05 +01:00
Mike Frysinger
1b40d569a8 sim: cris: clean up printf & abort usage a bit
Inline the stats printf calls to avoid compiler warnings about
non-literal format strings.  This in turn highlights bad type
sizes being passed in, so fix the strings to use the right size
type.  This in turn highlights the rest of the func using casts
rather than the right type directly, so adjust all of those.

Finally, replace a few abort+sim_engine_halt calls with the
common sim_engine_abort.  This provides good output while still
aborting as we want.
2021-06-20 23:45:24 -04:00
GDB Administrator
e27c0d7ae3 Automatic date update in version.in 2021-06-21 00:00:08 +00:00
Mike Frysinger
4488e43c49 sim: rx: scope the unique configure flag
This will make it possible to merge into the common configure by
making sure we never collide with other arches.
2021-06-20 01:13:14 -04:00
Mike Frysinger
3eda63f2e4 sim: delete SIM_AC_COMMON macro
Now that we've moved all content out to the common file, this is
empty and can be deleted it entirely.
2021-06-20 00:39:38 -04:00
Mike Frysinger
3a829bc50c sim: unify general maintainer settings
Move these options up to the common dir so we only test & export
them once across all ports.  This takes a page from the cgen maint
logic to make $(MAINT) work for non-automake Makefiles which will
allow us to merge it together.
2021-06-20 00:31:27 -04:00
Mike Frysinger
1bf5c34239 sim: unify cgen maintainer settings
Move these options up to the common dir so we only test & export
them once across all ports.  It makes it available to targets that
aren't cgen-based, but those will just ignore the settings, so it
shouldn't be an issue.
2021-06-20 00:25:13 -04:00
Mike Frysinger
4ca8baee00 sim: m68hc11: fix unused function warnings with -O0
Mark these functions as unused in case they don't get inlined when
building with -O0.
2021-06-20 00:17:08 -04:00
Mike Frysinger
d73f39ee43 sim: move sim-inline to the common code
This will allow us to build the common code with the same inline
settings as the arch subdirs, and only do the test once.
2021-06-20 00:12:11 -04:00
H.J. Lu
406b4ada55 x86: Count PLT for GOTOFF relocation against IFUNC symbol
Since GOTOFF relocations against IFUNC symbols must go through PLT,
set PLT reference count to 1 for GOTOFF relocation.

bfd/

	PR ld/27998
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Count PLT for GOTOFF
	relocation against IFUNC symbols.
	(_bfd_x86_elf_adjust_dynamic_symbol): Likewise.

ld/

	PR ld/27998
	* testsuite/ld-i386/i386.exp: Run PR ld/27998 tests.
	* testsuite/ld-i386/pr27998a.d: New file.
	* testsuite/ld-i386/pr27998a.s: Likewise.
	* testsuite/ld-i386/pr27998b.d: Likewise.
	* testsuite/ld-i386/pr27998b.s: Likewise.
2021-06-19 20:21:04 -07:00
Mike Frysinger
7e3941ac06 gdb/gdbserver: switch to AC_CONFIG_MACRO_DIRS
These dirs don't use automake, so use AC_CONFIG_MACRO_DIRS to specify
../config as a search dir for m4 macros.  This allows removal of a lot
of hand-written m4_include's from acinclude.m4 files, and simplifies
use of `aclocal` or `autoreconf` as manual -I is not needed.
2021-06-19 23:06:01 -04:00
Simon Marchi
57a922a598 sim: move UNUSED before TYPE in SIM_ENDIAN_INLINE's definition
I get this when building with gcc 11:

      CC       common/common_libcommon_a-sim-load.o
    In file included from /home/simark/src/binutils-gdb/sim/common/sim-n-bits.h:27,
                     from /home/simark/src/binutils-gdb/sim/common/sim-bits.c:259,
                     from /home/simark/src/binutils-gdb/sim/common/sim-bits.h:599,
                     from /home/simark/src/binutils-gdb/sim/common/sim-basics.h:122,
                     from /home/simark/src/binutils-gdb/sim/common/sim-load.c:30:
    /home/simark/src/binutils-gdb/sim/common/sim-n-endian.h:39:27: error: 'offset_16' defined but not used [-Werror=unused-function]
       39 | #define offset_N XCONCAT2(offset_,N)
          |                           ^~~~~~~
    /home/simark/src/binutils-gdb/sim/../include/symcat.h:23:26: note: in definition of macro 'CONCAT2'
       23 | #define CONCAT2(a,b)     a##b
          |                          ^
    /home/simark/src/binutils-gdb/sim/common/sim-n-endian.h:39:18: note: in expansion of macro 'XCONCAT2'
       39 | #define offset_N XCONCAT2(offset_,N)
          |                  ^~~~~~~~
    /home/simark/src/binutils-gdb/sim/common/sim-n-endian.h:138:1: note: in expansion of macro 'offset_N'
      138 | offset_N (unsigned_N *x,
          | ^~~~~~~~

offset_N uses INLINE_SIM_ENDIAN, which uses UNUSED to put the "unused"
attribute.  However, it appears after the function's return type, which
seems to make it not apply to the function.  Moving it to before the
return type fixes the error.

Change all instances found in that file.

sim/common/ChangeLog:

	* sim-inline.h: Move UNUSED before TYPE.

Change-Id: Ide20106683ed7a9ebf35d484dabf70b309cb1ba6
2021-06-19 22:49:52 -04:00
Mike Frysinger
a979f2a07a sim: unify dtc tool checks
Only one arch uses this currently, but others could too.  By moving
it up to the common checks, it'll also let us simplify the moxie code
significantly.
2021-06-19 22:43:56 -04:00
Mike Frysinger
54c47dfb68 sim: ppc: rename inline defines to match common code
Use the same basic names as the common sim inline logic so we can
merge the two.  We don't do that here, just prepare for it.

The common code seems to be based on the ppc version but with slightly
different names as it was cleaned up & generalized.  I *think* these
concepts are the same, so binding them together is OK, but maybe I'm
misreading them.  If so, can always tweak them later.
	REVEAL_MODULE  ->  H_REVEALS_MODULE
	INLINE_MODULE  ->  C_REVEALS_MODULE
2021-06-19 22:41:05 -04:00
Mike Frysinger
36842f65be sim: drop old BUILT_SRC_FROM_COMMON ref
The code that set & used this variable was deleted long ago,
but the clean target was missed.  Clean that up now.
2021-06-19 22:24:03 -04:00
GDB Administrator
89ee1c2f6e Automatic date update in version.in 2021-06-20 00:00:08 +00:00
H.J. Lu
83b1d8f4a6 elf: Correct DT_TEXTREL warning in PDE
Change

ld: warning: creating DT_TEXTREL in a PIE

to

ld: warning: creating DT_TEXTREL in a PDE

on PDE.

bfd/

	* elflink.c (bfd_elf_final_link): Correct DT_TEXTREL warning in
	PDE.

ld/

	* testsuite/ld-x86-64/textrel-1.err: New file.
	* testsuite/ld-x86-64/textrel-1a.s: Likewise.
	* testsuite/ld-x86-64/textrel-1b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run textrel-1 tests.
2021-06-19 16:33:35 -07:00