Commit Graph

107705 Commits

Author SHA1 Message Date
Luis Machado
ecbf5d4f9b [ARM] Refactor pseudo register numbering
The pseudo register handling for ARM uses some hardcoded constants to
determine types and names.  In preparation to the upcoming MVE support
patch (that will add another pseudo register), this patch refactors and
reorganizes things in order to simplify handling of future pseudo registers.

We keep track of the first pseudo register number in a group and the number of
pseudo registers in that group.

Right now we only have the S and Q pseudo registers.
2021-10-11 16:03:52 -03:00
Luis Machado
dc22c61a16 [ARM] Small refactoring of arm gdbarch initialization
This is in preparation to MVE support, where we will define another
pseudo register. We need to define the pseudo register numbers *after*
accounting for all the registers in the XML description, so move
the call to tdesc_use_registers up.

If we don't do it, GDB's register count won't consider registers contained
in the XML but ignored by GDB, throwing the register numbering off.
2021-10-11 16:03:48 -03:00
Luis Machado
4d224f4a58 [ARM] Refactor some constants
In preparation for the MVE extension patch, this one refactors some of
the register-related constants we have for ARM.

Basically I'm separating counting constants from numbering constants.

For example, ARM_A1_REGNUM is a numbering constant, whereas ARM_NUM_ARG_REGS
is a counting constant.
2021-10-11 16:03:44 -03:00
Tom de Vries
c8ed8c8ac3 [gdb/testsuite] Fix FAIL in gdb.mi/mi-var-child-f.exp
When running test-case gdb.mi/mi-var-child-f.exp on openSUSE Tumbleweed
(with glibc 2.34) I run into:
...
(gdb) ^M
PASS: gdb.mi/mi-var-child-f.exp: mi runto prog_array
Expecting: ^(-var-create array \* array[^M
]+)?(\^done,name="array",numchild="[0-9]+",value=".*",type=.*,has_more="0"[^M
]+[(]gdb[)] ^M
[ ]*)
-var-create array * array^M
&"Attempt to use a type name as an expression.\n"^M
^error,msg="-var-create: unable to create variable object"^M
(gdb) ^M
FAIL: gdb.mi/mi-var-child-f.exp: create local variable array (unexpected output)
...

The problem is that the name array is used both:
- as the name for a local variable
- as the name of a type in glibc, in file malloc/dynarray-skeleton.c, as included
  by nss/nss_files/files-hosts.c.

Fix this by ignoring the shared lib symbols.

Likewise in a couple of other fortran tests.

Tested on x86_64-linux.
2021-10-11 16:59:56 +02:00
Andrew Burgess
3a480f1e35 z80/disassembler: call memory_error_func when appropriate
If a call to the read_memory_func fails then we should call the
memory_error_func to notify the user of the disassembler of the
address that was a problem.

Without this GDB will report all memory errors as being at address
0x0.

opcodes/ChangeLog:

	* z80-dis.c (fetch_data): Call memory_error_func if the
	read_memory_func call fails.
2021-10-11 14:07:03 +01:00
Andrew Burgess
ba7c18a484 s12z/disassembler: call memory_error_func when appropriate
If a call to the read_memory_func fails then we should call the
memory_error_func to notify the user of the disassembler of the
address that was a problem.

Without this GDB will report all memory errors as being at address
0x0.

opcodes/ChangeLog:

	* s12z-disc.c (abstract_read_memory): Call memory_error_func if
	the read_memory_func call fails.
2021-10-11 14:07:03 +01:00
Tom de Vries
c2c8a42788 [gdb/testsuite] Fix double debug info in gdb.dwarf2/dw2-ref-missing-frame.exp
A mistake slipped in in commit a5ea23036d "[gdb/testsuite] Use function_range
in gdb.dwarf2/dw2-ref-missing-frame.exp".

Before the commit the main file was compiled with debug info, and the two
others not:
...
if {[prepare_for_testing_full "failed to prepare" \
        [list $testfile {} $srcfile {} $srcfuncfile {} \
             $srcmainfile debug]]} {
...

After the commit, all were compiled with debug info, and consequently, there
are two versions of debug info for $srcfuncfile.  This shows up as a FAIL when
running the test-case with target boards readnow and cc-with-debug-names.

Fix this by using prepare_for_testing_full, as before.

Tested on x86_64-linux.

Fixes: a5ea23036d ("[gdb/testsuite] Use function_range in
       gdb.dwarf2/dw2-ref-missing-frame.exp")
2021-10-11 13:31:54 +02:00
Tom de Vries
19abf6c542 [gdb/testsuite] Use require for ensure_gdb_index
Replace:
...
if { [ensure_gdb_index $binfile] == -1 } {
    return -1
}
...
with:
...
require {ensure_gdb_index $binfile} != -1
...
and consequently, add a missing UNTESTED message.

Tested on x86_64-linux, both with native and target board readnow.
2021-10-11 12:21:00 +02:00
Tom de Vries
dbfc69bef9 [gdb/testsuite] Handle readnow in ensure_gdb_index
When running test-case gdb.base/with-mf.exp with target board readnow, I run
into:
...
FAIL: gdb.base/with-mf.exp: check if index present
...
This is since commit 6010fb0c49 "[gdb/testsuite] Fix full buffer in
gdb.rust/dwindex.exp".

Before that commit, the proc ensure_gdb_index would treat the line:
...
.gdb_index: faked for "readnow"^M
...
as proof that an index is already present (which is incorrect).

Now, instead it generates aforementioned FAIL and continues to generate an
index.

Fix this by explicitly handling the readnow case in proc ensure_gdb_index,
such that we bail out instead.

Tested on x86_64-linux.
2021-10-11 12:21:00 +02:00
Tom de Vries
47265957ad [gdb/testsuite] Fix gdb.dwarf2/gdb-add-index-symlink.exp
The test-case gdb.dwarf2/gdb-add-index-symlink.exp interpretes a failure to
add an index as a failure to add an index for a symlink:
...
if { [ensure_gdb_index $symlink] == -1 } {
    fail "Unable to call gdb-add-index with a symlink to a symfile"
    return -1
}
...

However, it's possible that the gdb-add-index also fails with a regular
file.  Add a check for that situation.

Tested on x86_64-linux.
2021-10-11 12:21:00 +02:00
Tom de Vries
4f69f0a21e [gdb/testsuite] Add proc require in lib/gdb.exp
Add a new proc require in lib/gdb.exp, and use it to shorten:
...
if { [gdb_skip_xml_test] } {
    # Valgrind gdbserver requires gdb with xml support.
    untested "missing xml support"
    return 0
}
...
into:
...
require gdb_skip_xml_test 0
...

Tested on x86_64-linux, both with and without a trigger patch that forces
gdb_skip_xml_test to return 1.
2021-10-11 12:21:00 +02:00
Michael Forney
b6fca8a3d5 bfd: Remove use of void pointer arithmetic
This is not valid in ISO C. Instead, use a pointer to bfd_byte.

	* peicode.h (pe_bfd_object_p): Remove use of void pointer
	arithmetic.
2021-10-11 19:13:41 +10:30
GDB Administrator
88b3223704 Automatic date update in version.in 2021-10-11 00:00:13 +00:00
GDB Administrator
902ad3d703 Automatic date update in version.in 2021-10-10 00:00:09 +00:00
Tom de Vries
84a6adfd4c [gdb] Make execute_command_to_string return string on throw
The pattern for using execute_command_to_string is:
...
  std::string output;
  output = execute_fn_to_string (fn, term_out);
...

This results in a problem when using it in a try/catch:
...
  try
    {
      output = execute_fn_to_string (fn, term_out)
    }
  catch (const gdb_exception &e)
    {
      /* Use output.  */
    }
...

If an expection was thrown during execute_fn_to_string, then the output
remains unassigned, while it could be worthwhile to known what output was
generated by gdb before the expection was thrown.

Fix this by returning the string using a parameter instead:
...
  execute_fn_to_string (output, fn, term_out)
...

Also add a variant without string parameter, to support places where the
function is used while ignoring the result:
...
  execute_fn_to_string (fn, term_out)
...

Tested on x86_64-linux.
2021-10-09 18:58:30 +02:00
Tom de Vries
fa9ce2c143 [gdb/testsuite] Add check-readmore
Consider the gdb output:
...
27        return SYSCALL_CANCEL (nanosleep, requested_time, remaining);^M
(gdb) ^M
Thread 2 "run-attach-whil" stopped.^M
...

When trying to match the gdb prompt using gdb_test which uses '$gdb_prompt $',
it may pass or fail.

This sort of thing needs to be fixed (see commit b0e2f96b56), but there's
currently no way to reliably find this type of FAILs.

We have check-read1, but that one actually make the test pass reliably.

We need something like the opposite of check-read1: something that makes
expect read a bit slower, or more exhaustively.

Add a new test target check-readmore that implements this.

There are two methods of implementing this in read1.c:
- the first method waits a bit before doing a read
- the second method does a read and then decides whether to
  return or to wait a bit and do another read, and so on.

The second method is potentially faster, has less risc of timeout and could
potentially detect more problems.  The first method has a simpler
implementation.

The second method is enabled by default.  The default waiting period is 10
miliseconds.

The first method can be enabled using:
...
$ export READMORE_METHOD=1
...
and the waiting period can be specified in miliseconds using:
...
$ export READMORE_SLEEP=9
...

Also a log file can be specified using:
...
$ export READMORE_LOG=$(pwd -P)/LOG
...

Tested on x86_64-linux.

Testing with check-readmore showed these regressions:
...
FAIL: gdb.base/bp-cmds-continue-ctrl-c.exp: run: stop with control-c (continue)
FAIL: gdb.base/bp-cmds-continue-ctrl-c.exp: attach: stop with control-c (continue)
...

I have not been able to find a problem in the test-case, and I think it's the
nature of both the test-case and readmore that makes it run longer.  Make
these pass by increasing the alarm timeout from 60 to 120 seconds.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27957
2021-10-09 18:53:12 +02:00
Tom de Vries
f9edf60830 [gdb/testsuite] Fix fortran module tests with stressed cpu
When running these test-cases:
- gdb.fortran/info-modules.exp
- gdb.fortran/module.exp
- gdb.mi/mi-fortran-modules.exp
in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
I run into timeouts.

Fix this by using:
- "set auto-solib-add off" to avoid symbols of shared libs
  (which doesn't work for libc, now that libpthread_name_p has been
  updated to  match libc)
- "nosharedlibrary" to avoid symbols of libc

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28133
2021-10-09 11:35:43 +02:00
Guillermo E. Martinez
0161bdd47c PR28415, invalid read in xtensa_read_table_entries
PR 28415
	PR 28416
	* elf32-xtensa.c (xtensa_read_table_entries): Handle error
	return from retrieve_contents.
2021-10-09 14:02:07 +10:30
GDB Administrator
851a4f24d7 Automatic date update in version.in 2021-10-09 00:00:08 +00:00
Tom de Vries
b886031bd2 [gdb/testsuite] Fix gdb.base/info-types-c++.exp with stressed cpu
When running test-case gdb.base/info-types-c++.exp in conjunction with:
...
$ stress -c $(($(cat /proc/cpuinfo | grep -c "^processor") + 1))
...
we get:
...
FAIL: gdb.base/info-types-c++.exp: info types (timeout)
...

Fix this by setting auto-solib-add to off.

Tested on x86_64-linux.
2021-10-09 00:40:46 +02:00
Tom de Vries
048cb8b466 [gdb/testsuite] Fix gdb.base/info_sources_2.exp with check-read1
When running test-case gdb.base/info_sources_2.exp with check-read1, I run
into:
...
FAIL: gdb.base/info_sources_2.exp: args: : info sources  (timeout)
...

Fix this by consuming a "$src1, $src2, ..., $srcn: line bit by bit rather than
as one whole line.

Also add the missing handling of "Objfile has no debug information".

Tested on x86_64-linux.
2021-10-08 14:17:09 +02:00
Tom de Vries
2550e478ad [gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1
When running test-case gdb.mi/gdb2549.exp with check-read1, I run into:
...
FAIL: gdb.mi/gdb2549.exp: register values x (timeout)
...

Fix this by applying the same fix as for "register values t" in commit
478e490a4d "[gdb/testsuite] Fix gdb.mi/gdb2549.exp with check-read1".

Tested on x86_64-linux.
2021-10-08 13:07:52 +02:00
Tom de Vries
8320b04230 [gdb/testsuite] Fix gdb.base/bt-on-error-and-warning.exp with check-read1
When running test-case gdb.base/bt-on-error-and-warning.exp with check-read1,
I run into:
...
(gdb) maint internal-error foobar^M
src/gdb/maint.c:82: internal-error: foobar^M
A problem internal to GDB has been detectedFAIL: \
  gdb.base/bt-on-error-and-warning.exp: problem=internal-error, mode=on: \
  scan for backtrace (GDB internal error)
Resyncing due to internal error.
,^M
...

The corresponding gdb_test_multiple in the test-case contains:
...
           -early -re "^A problem internal to GDB has been detected,\r\n" {
               incr header_lines
               exp_continue
           }
...
but instead this one triggers in gdb_test_multiple:
...
        -re ".*A problem internal to GDB has been detected" {
            fail "$message (GDB internal error)"
            gdb_internal_error_resync
            set result -1
        }
...

Fix this by likewise shortening the regexp to before the comma.

Tested on x86_64-linux.
2021-10-08 12:30:35 +02:00
Tom de Vries
b80e6295f6 [gdb/testsuite] Add nopie in two test-cases
When running test-case gdb.dwarf2/dw2-restrict.exp on openSUSE Leap 15.2 with
gcc-PIE installed (switching compiler default to -fPIE/-pie), I get:
...
gdb compile failed, ld: outputs/gdb.dwarf2/dw2-restrict/dw2-restrict0.o: \
  warning: relocation in read-only section `.text'
ld: warning: creating DT_TEXTREL in a PIE
UNTESTED: gdb.dwarf2/dw2-restrict.exp: failed to prepare
...

This is due to using a hardcoded .S file that was generated with -fno-PIE.

Fix this by adding the missing nopie.

Likewise in gdb.arch/amd64-tailcall-noret.exp.

Tested on x86_64-linux.
2021-10-08 11:20:31 +02:00
GDB Administrator
fc6e66cd18 Automatic date update in version.in 2021-10-08 00:00:11 +00:00
Tom de Vries
d7a6aa74c8 [gdb/testsuite] Fix gdb.threads/check-libthread-db.exp with glibc 2.34
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed (with glibc 2.34) I get:
...
(gdb) continue^M
Continuing.^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
Stopped due to shared library event:^M
  Inferior loaded /lib64/libm.so.6^M
    /lib64/libc.so.6^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: continue
...

The check expect the inferior to load libpthread, but since glibc 2.34
libpthread has been integrated into glibc, and consequently it's no longer
a dependency:
...
$ ldd outputs/gdb.threads/check-libthread-db/check-libthread-db
        linux-vdso.so.1 (0x00007ffe4cae4000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f167c77c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f167c572000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f167c86e000)
...

Fix this by updating the regexp to expect libpthread or libc.

Tested on x86_64-linux.
2021-10-07 18:00:08 +02:00
Tom de Vries
22589c4996 [gdb/testsuite] Fix gdb.guile/scm-type.exp with gcc 4.8
With gcc 7.5.0, I get:
...
(gdb) guile (print (type-range (field-type (type-field (value-type \
  (value-dereference f)) "items"))))^M
= (0 0)^M
(gdb) PASS: gdb.guile/scm-type.exp: lang_cpp: test_range: \
  on flexible array member: $cmd
...
but with gcc 4.8.5, I get instead:
...
(gdb) guile (print (type-range (field-type (type-field (value-type \
  (value-dereference f)) "items"))))^M
= (0 -1)^M
(gdb) FAIL: gdb.guile/scm-type.exp: lang_cpp: test_range: \
  on flexible array member: $cmd
...

There's a difference in debug info.  With gcc 4.8.5, we have:
...
 <2><224>: Abbrev Number: 15 (DW_TAG_member)
    <225>   DW_AT_name        : items
    <22b>   DW_AT_type        : <0x231>
 <1><231>: Abbrev Number: 4 (DW_TAG_array_type)
    <232>   DW_AT_type        : <0x105>
 <2><23a>: Abbrev Number: 16 (DW_TAG_subrange_type)
    <23b>   DW_AT_type        : <0x11a>
    <23f>   DW_AT_upper_bound : 0xffffffffffffffff
...
and with gcc 7.5.0, we have instead:
...
 <2><89f>: Abbrev Number: 12 (DW_TAG_member)
    <8a0>   DW_AT_name        : items
    <8a6>   DW_AT_type        : <0x8ac>
 <1><8ac>: Abbrev Number: 17 (DW_TAG_array_type)
    <8ad>   DW_AT_type        : <0x29d>
 <2><8b5>: Abbrev Number: 41 (DW_TAG_subrange_type)
 <2><8b6>: Abbrev Number: 0
...

As mentioned in commit 858c8f2c1b "gdb/testsuite: adjust
gdb.python/flexible-array-member.exp expected pattern":
...
Ideally, GDB would present a consistent and documented value for an
array member declared with size 0, regardless of how the debug info
looks like.
...

As in gdb.python/flexible-array-member.exp, change the test to accept the two
values.

Tested on x86_64-linux.
2021-10-07 18:00:08 +02:00
Simon Marchi
cd3f655cc7 gdb: add accessors for field (and call site) location
Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8
2021-10-07 11:03:54 -04:00
Philipp Tomsich
8baf3d0756 RISC-V: Support aliases for Zbs instructions
Add aliases for the non-immediate mnemonics of b{set,clr,inv,ext} to
yencode the respective immediate insn b{set,clr,inv,ext}i when the
second source operand is an immediate.

2021-01-11  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    gas/
	* testsuite/gas/riscv/b-ext.d: Add tests.
	* testsuite/gas/riscv/b-ext.s: Likewise.
	* testsuite/gas/riscv/b-ext-64.d: Likewise.
	* testsuite/gas/riscv/b-ext-64.s: Likewise.
    opcodes/
        * riscv-opc.c (riscv_opcodes): Add aliases for Zbs.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2021-10-07 17:09:28 +08:00
Philipp Tomsich
9455c91957 RISC-V: Add support for Zbs instructions
This change adds the Zbs instructions from the Zbs 1.0.0 specification.
See
  https://github.com/riscv/riscv-bitmanip/releases/tag/1.0.0
for the frozen specification.

2021-01-09  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    bfd/
	* elfxx-riscv.c (riscv_supported_std_z_ext): Added zbs.
    gas/
	* config/tc-riscv.c (riscv_multi_subset_supports): Handle INSN_CLASS_ZBS.
	* testsuite/gas/riscv/b-ext.d: Test Zbs instructions.
	* testsuite/gas/riscv/b-ext.s: Likewise.
	* testsuite/gas/riscv/b-ext-64.d: Likewise.
	* testsuite/gas/riscv/b-ext-64.s: Likewise.
    include/
	* opcode/riscv-opc.h: Added MASK/MATCH/DECLARE_INSN for Zbs.
	* opcode/riscv.h (riscv_insn_class): Added INSN_CLASS_ZBS.
    opcodes/
	* riscv-opc.c (riscv_supported_std_z_ext): Add zbs.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2021-10-07 17:09:25 +08:00
Philipp Tomsich
586dcfc81e RISC-V: Update extension version for Zb[abc] to 1.0.0
2021-10-06  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    bfd/
	* elfxx-riscv.c (riscv_supported_std_z_ext): Update the version
	number for zba, zbb and zbc to 1.0.0

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>

Version-changes: 3
- Updated version numbers for zba, zbb and zbc to 1.0.0
2021-10-07 17:09:21 +08:00
Philipp Tomsich
cda0561f9e RISC-V: Split Zb[abc] into commented sections
The Zb[abc] opcodes are bundled just below the Privileged opcodes in
riscv_opcodes, possibly giving the appearance that they are part of
the Privileged spec for an uninitiated reader.  This separates them
out and adds comments above each section to clearly identify them as
Zba, Zbb or Zbc opcodes.

2021-10-04  Philipp Tomsich  <philipp.tomsich@vrull.eu>

    opcodes/
	* riscv-opc.c: Split of Zb[abc] instructions and add comments.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2021-10-07 17:09:18 +08:00
Alan Modra
6646834337 PR28423, use-after-free in objdump
XCOFF archives use a bi-directional linked list for file members.  So
one member points to both the previous member and the next member.
Members may not be sequentially ordered in the file.  This of course
is over-engineered nonsense and an attractive target for fuzzers.
(There is even a free list of members!)  The testcase in PR28423 is an
XCOFF archive with one member pointing to itself, which results in
lots of bad behaviour.  For example, "ar t" never terminates.

The use-after-free with "objdump -r" happens like this:  The first
archive element is opened, its symbols are read and "canonicalized"
for objdump, then relocations are read and printed.  Those relocations
use the canonicalized symbols, and also happen to be cached by the
coff bfd backend support.  objdump frees the symbols.  The next
archive element is then opened.  This must be done before the first
element is closed, because finding the next element uses data held in
the currect element.  Unfortunately the next element happens to be the
original, so we aren't opening, we're reopening a bfd which has cached
data.  When the relocations are printed they use the cached copy
containing references to the freed canonical symbols.

This patch adds a little sanity checking to the XCOFF "open next
archive file" support, so that it rejects archive members pointing at
themselves.  That is sufficient to cure this problem.  Anything more
is overkill.  If someone deliberately fuzzes an XCOFF archive with an
element loop then reports an "ar" bug when it runs forever, they will
find their bug report closed WONTFIX.

	PR 28423
	* coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Save size occupied
	by member name in areltdata.extra_size.
	(_bfd_xcoff_openr_next_archived_file): Sanity check nextoff.
	* coff64-rs6000.c (xcoff64_openr_next_archived_file): Call
	_bfd_xcoff_openr_next_archived_file.
2021-10-07 14:23:14 +10:30
Alan Modra
6d661cdc5b PR28422, build_id use-after-free
This fixes a bug in commit 5d9bbb73c1.  All fields preserved from a
bfd in struct bfd_preserve need to be cleared in bfd_reinit.

	PR 28422
	* format.c (bfd_reinit): Clear build_id.
2021-10-07 14:23:14 +10:30
Alan Modra
89e62f7454 Change ridiculous section size error
Rather than reporting "memory exhausted", report "file truncated".
You can hit this error on small fuzzed object files, or on files that
are actually truncated.  In either case sizes can be such that an out
of memory error is a little confusing.

	* compress.c (bfd_get_full_section_contents): Set
	bfd_error_file_truncated rather than bfd_error_no_memory when
	section size exceeds file size.
2021-10-07 14:23:14 +10:30
Tom de Vries
c0ae8ccdba [gdb/testsuite] Fix FAIL in gdb.base/annota1.exp
On openSUSE tumbleweed I run into:
...
FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
...
due to a message related to libthread_db:
...
^Z^Zstarting^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
^M
^Z^Zframes-invalid^M
...
which is not matched by the regexp.

Fix this by updating the regexp.

Tested on x86_64-linux.
2021-10-07 05:45:32 +02:00
Tom de Vries
cf4505a7ec [gdb/testsuite] Refactor regexp in gdb.base/annota1.exp
Refactor regexp in gdb.base/annota1.exp to reduce indentation and repetition.

Tested on x86_64-linux.
2021-10-07 05:45:32 +02:00
GDB Administrator
82f2f39d81 Automatic date update in version.in 2021-10-07 00:00:09 +00:00
Andrew Burgess
24616c1995 gdb/doc: improve 'show print elements' description
The documentation for 'show print elements' contains the line:

  If the number is 0, then the printing is unlimited.

However, this line is now out of date as can be seen by this GDB
session:

  (gdb) set print elements 0
  (gdb) show print elements
  Limit on string chars or array elements to print is unlimited.

The value 0 does indeed mean unlimited, and this is described in the
'set print elements' section, however, for 'show print elements' the
user will never see the value 0, so lets just remove that bit from the
docs.
2021-10-06 14:36:23 +01:00
Tom de Vries
cf2ad3e662 [gdb/testsuite] Fix FAIL in gdb.tui/corefile-run.exp
When running test-case gdb.tui/corefile-run.exp on openSUSE Tumbleweed,
I run into:
...
PASS: gdb.tui/corefile-run.exp: load corefile
FAIL: gdb.tui/corefile-run.exp: run until the end
...

What's going on is easier to see when also doing dump_screen if
check_contents passes, and inspecting state at the preceding PASS:
...
 +-------------------------------------------------------------------------+
 exec No process In:                                           L??   PC: ??
 [New LWP 16629]
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/lib64/libthread_db.so.1".
 Core was generated by `/data/gdb_versions/devel/build/gdb/testsuite/output
 s/gdb.tui/corefile-run/corefi'.
 Program terminated with signal SIGTRAP, Trace/breakpoint trap.
 #0  main ()
 --Type <RET> for more, q to quit, c to continue without paging--
...

The problem is that we're getting a pagination prompt, and the subsequent run
command is interpreted as an answer to that prompt.

Fix this by:
- detecting the gdb prompt in response to "load corefile", such that
  we detect the failure earlier, and
- doing a "set pagination off" in Term::clean_restart.

Tested on x86_64-linux.
2021-10-06 11:26:38 +02:00
Alan Modra
1992e26ec4 PR28420, ecoff fuzzing failures
PR 28420
	* coff-mips.c (mips_adjust_reloc_in): Replace abort with error
	message and return.
	* ecoff.c (ecoff_slurp_reloc_table): Remove assertion and aborts,
	instead handle errors gracefully.
2021-10-06 18:00:00 +10:30
Alan Modra
1808483c2f PR28402, fail to allocate line number array
This fixes a situation where the COFF code allocated memory for
internal representaion arrays before reading the external file data.
That meant the allocation didn't have any sanity check against file
size.

	PR 28402
	* coffcode.h (buy_and_read): Malloc rather than alloc memory.
	(coff_slurp_line_table): Read native line number info before
	allocating memory for internal line number array.  Adjust error
	paths to suit.  Remove now unnecessary line number count check.
	(coff_slurp_reloc_table): Adjust to suit buy_and_read change.
2021-10-06 15:30:23 +10:30
Alan Modra
0a6041ce93 PR28403, null pointer dereference in disassemble_bytes
Indexing of symbol and howto arrays wasn't checked in aout targets.

	PR 28403
	* aout-ns32k.c (MY (reloc_howto)): Sanity check howto_table index.
	Make r_index unsigned.
	(MY_swap_std_reloc_in): Make r_index unsigned.
	* aoutx.h (MOVE_ADDRESS): Sanity check symbol r_index.
	(aout_link_input_section_std): Make r_index unsigned.
	(aout_link_input_section_ext): Likewise.
	* i386lynx.c (MOVE_ADDRESS): Sanity check symbol r_index.
	(swap_ext_reloc_in, swap_std_reloc_in): Make r_index unsigned.
	* pdp11.c (MOVE_ADDRESS): Sanity check symbol r_index.
2021-10-06 11:24:29 +10:30
Alan Modra
55e3926e79 PR28401, invalid section name lookup
The PR28401 testcase has a section named "", ie. an empty string.
This results in some silly behaviour in load_debug_section, and
dump_dwarf_section.  Fix that.  Note that this patch doesn't correct
the main complaint in PR28401, "failed to allocate", since malloc
failures on sections having huge bogus sizes are to be expected.  We
can't safely catch all such cases by comparing with file size, for
example, where sections contain compressed data.

	PR 28401
	* objdump.c (load_debug_section): Don't attempt to retrieve
	empty name sections.
	(dump_dwarf_section): Likewise.
2021-10-06 11:24:29 +10:30
GDB Administrator
79fa3c401c Automatic date update in version.in 2021-10-06 00:00:10 +00:00
Tom de Vries
1457d766df [gdb/testsuite] Make tui testing less verbose
Currently, tui testing is rather verbose.  When using these RUNTESTFLAGS to
pick up all tui tests (17 in total):
...
rtf=$(echo $(cd src/gdb/testsuite/; find gdb.* -type f -name *.exp* \
  | xargs grep -l tuiterm_env) )
...
we have:
...
$ wc -l gdb.log
120592 gdb.log
...

Most of the output is related to controlling the tui screen, but that does
not give a top-level sense of how the test-case progresses.

Put differently: a lot of bandwith is used to describe how we arrive at a
certain tui screen state.  But we don't actually always show the state we
arrive at, unless there's a FAIL.

And if there's say, a PASS that should actually be FAILing, it's hard to
detect.

Fix this by:
- dropping the -log on the call to verbose in _log.  We still can get the
  same info back using runtest -v.
- dumping the screen or box that we're checking, also when the test passes.

Brings down verbosity to something more reasonable:
...
$ wc -l gdb.log
3221 gdb.log
...

Tested on x86_64-linux.
2021-10-06 01:27:58 +02:00
Tom de Vries
58d82c2c59 [gdb/testsuite] Add Term::dump_box in lib/tuiterm.exp
Factor out new proc Term::get_region and use it to implement a
new proc Term::dump_box, similar to Term::dump_screen.

Tested on x86_64-linux.
2021-10-06 01:27:58 +02:00
Lancelot SIX
1461d3712b gdb: Remove deprecated assertion in setting::get
The commit 702991711a (gdb: Have setter
and getter callbacks for settings) makes it possible for a setting not
to be backed by a memory buffer but use callback functions instead to
retrieve or set the setting's value.

An assertion was not properly updated to take into account that the
m_var member (which points to a memory buffer, if used) might be nullptr
if the setting uses callback functions.  If the setting is backed by a
memory buffer, the m_var has to be non nullptr, which is already checked
before the pointer is dereferenced.

This commit removes this assertion as it is not valid anymore.
2021-10-05 21:43:13 +00:00
Tom Tromey
acbf4a58ef Remove 'varsize-limit'
This makes the Ada-specific "varsize-limit" a synonym for
"max-value-size", and removes the Ada-specific checks of the limit.

I am not certain of the history here, but it seems to me that this
code is fully obsolete now.  And, removing this makes it possible to
index large Ada arrays without triggering an error.  A new test case
is included to demonstrate this.
2021-10-05 12:35:24 -06:00
Tom Tromey
3e44c3049f Allow lazy 'zero' value
This changes value_zero to create a lazy value.  In many cases,
value_zero is called in expression evaluation to wrap a type in a
non-eval context.  It seems senseless to allocate a buffer in these
cases.

A new 'is_zero' flag is added so we can preserve the existing
assertions in value_fetch_lazy.

A subsequent patch will add a test where creating a zero value would
fail, due to the variable size check.  However, the contents of this
value are never needed, and so creating a lazy value avoids the error
case.
2021-10-05 12:34:55 -06:00