Commit graph

110301 commits

Author SHA1 Message Date
Tom Tromey
131430937d ODR warnings for "struct insn_info"
"struct insn_info" is defined in multiple .c files, causing ODR
warnings.  This patch renames the type in z80-tdep.c, leaving the
other one alone.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
c8e41b5f14 ODR warnings from overlay constants
Some overlay-related constants are duplicated in z80-tdep.c, causing
ODR warnings.  This patch renames just the z80-specific ones.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
cec000ad60 ODR warning for "enum string_repr_result"
"enum string_repr_result" is defined in multiple .c files, causing ODR
warnings.  This patch renames the types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
ddfc4ef124 ODR warning for "struct find_targ_sec_arg"
"struct find_targ_sec_arg" is defined in multiple .c files, causing
ODR warnings.  This patch renames the types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
0fecb1a784 ODR warning for "struct stack_item"
"struct stack_item" is defined in multiple .c files, causing ODR
warnings.  This patch renames these types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
cc55e4ef62 ODR warning for "struct instruction_type"
"struct instruction_type" is defined in multiple .c files, causing an
ODR warning.  This patch renames the types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
94e079e76e ODR warning for struct ext_link_map
This renames the solib-dsbt.c copy of "struct ext_link_map" to avoid
an ODR warning.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
c01e28360d ODR warning for struct field_info
This renames one of the instance of "struct field_info" to avoid an
ODR warning.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
7e9d9756db ODR warnings for struct nextfield
"struct nextfield" is defined in multiple places in GDB.  This patch
renames just the stabs one, leaving the DWARF one untouched.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
77845a9ac6 ODR warnings for struct symloc
"struct symloc" is defined in multiple spots in gdb, causing ODR
warnings.  This patch renames these.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:45 -06:00
Tom Tromey
57ebc99013 Fix ODR warning in observable.h
observable.h triggers an ODR warning because this line:

    extern observable<struct target_ops */* target */> target_changed;

... may be the only declaration of "struct target_ops" in scope
(depending on the particular .c file) -- and this declares it in a
namespace, resulting in confusion.

This patch fixes the problem by adding a forward declaration.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
2022-06-02 09:04:44 -06:00
Tiezhu Yang
2e90d02578 gdb: LoongArch: Implement the software_single_step gdbarch method
When execute the following command on LoongArch:

  make check-gdb TESTS="gdb.base/branch-to-self.exp"

there exist the following failed testcases:

  FAIL: gdb.base/branch-to-self.exp: single-step: si (timeout)
  FAIL: gdb.base/branch-to-self.exp: break-cond: side=host: continue to breakpoint: continue to break (timeout)
  FAIL: gdb.base/branch-to-self.exp: break-cond: side=host: p counter (timeout)

Implement the software_single_step gdbarch method to decode the current
branch instruction and determine the address of the next instruction on
LoongArch to fix the above failed testcases.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-02 22:43:35 +08:00
Ilya Leoshkevich
625b6eae09 gdb: Do not add empty sections to the section map
From: Ulrich Weigand <ulrich.weigand@de.ibm.com>

build_objfile_section_table () creates four synthetic sections per
objfile, which are collected by update_section_map () and passed to
std::sort ().  When there are a lot of objfiles, for example, when
debugging JITs, the presence of these sections slows down the sorting
significantly.

The output of update_section_map () is used by find_pc_section (),
which can never return any of these sections: their size is 0, so they
cannot be accepted by bsearch_cmp ().

Filter them (and all the other empty sections) out in
insert_section_p (), which is used only by update_section_map ().
2022-06-02 14:20:05 +02:00
Jon Turney
a779012848
Fix a new warning on Cygwin
> ../../gdb/windows-nat.c: In function ‘windows_solib* windows_make_so(const char*, LPVOID)’:
> ../../gdb/windows-nat.c:714:12: error: declaration of ‘char name [512]’ shadows a parameter [-Werror=shadow=compatible-local]
>   714 |       char name[SO_NAME_MAX_PATH_SIZE];
>       |            ^~~~
> ../../gdb/windows-nat.c:655:30: note: shadowed declaration is here
>   655 | windows_make_so (const char *name, LPVOID load_addr)
>       |                  ~~~~~~~~~~~~^~~~
2022-06-02 10:39:49 +01:00
Jon Turney
a115c6d62e
Fix Cygwin build after 85b25bd9
Fix Cygwin build after 85b25bd9 ("Simplify windows-nat.c solib handling").
2022-06-02 10:39:47 +01:00
Jon Turney
1f03fa9921
Fix Cygwin build after 0578e87f
Fix Cygwin build after 0578e87f ("Remove some globals from
nat/windows-nat.c").  Update code under ifdef __CYGWIN__ for globals
moved to members of struct windows_process_info.
2022-06-02 10:39:46 +01:00
Jon Turney
c9c157c765
Fix Cygwin build after fcab5839
Fix Cygwin build after fcab5839 ("Implement pid_to_exec_file for Windows
in gdbserver"). That change moves code from gdb/windows-nat.c to
gdb/nat/windows-nat.c, but doesn't add the required typedefs and
includes for parts of that code under ifdef __CYGWIN__.
2022-06-02 10:39:44 +01:00
Alan Modra
6a031255cf Re: ubsan: signed integer overflow in atof_generic
Oops.

	* atof-generic.c: Include limits.h.
2022-06-02 18:42:01 +09:30
Alan Modra
b038f394a9 ubsan: signed integer overflow in atof_generic
Fix the signed overflows by using unsigned variables and detect
overflow at BUG! comment.

	* atof-generic.c (atof_generic): Avoid signed integer overflow.
	Return ERROR_EXPONENT_OVERFLOW if exponent overflows a long.
2022-06-02 18:28:57 +09:30
Alan Modra
ee6cbff213 asan: uninit write _bfd_ecoff_write_object_contents
* ecoff.c (_bfd_ecoff_write_object_contents): zalloc reloc_buff.
2022-06-02 16:43:48 +09:30
Alan Modra
f66d30a6e5 asan: null deref in coff_write_relocs
* coffcode.h (coff_write_relocs): Don't deref NULL howto.
2022-06-02 16:31:42 +09:30
Alan Modra
e0ad09cfa5 ubsan: undefined shift in frag_align_code
* frags.c (MAX_MEM_FOR_RS_ALIGN_CODE): Avoid signed integer
	overflow.
2022-06-02 16:10:30 +09:30
Alan Modra
53f2b36a54 gas read_a_source_file #APP processing
This fixes some horrible code using do_scrub_chars.  What we had ran
text through do_scrub_chars twice, directly in read_a_source_file and
again via the input_scrub_include_sb call.  That's silly, and since
do_scrub_chars is a state machine, possibly wrong.  More silliness is
evident in the temporary malloc'd buffer for do_scrub_chars output,
which should have been written directly to sbuf.

So, get rid of the do_scrub_chars call and support functions, leaving
scrubbing to input_scrub_include_sb.  I did wonder about #NO_APP
overlapping input_scrub_next_buffer buffers, but that should only
happen if the string starts in one file and finishes in another.

	* read.c (scrub_string, scrub_string_end): Delete.
	(scrub_from_string): Delete.
	(read_a_source_file): Rewrite #APP processing.
2022-06-02 15:54:18 +09:30
Alan Modra
cd826186c8 sb_scrub_and_add_sb not draining input string buffer
It is possible for sb_scrub_and_add_sb to not consume all of the input
string buffer.  If this happens for reasons explained in the comment,
do_scrub_chars can leave pointers to the string buffer for the next
call.  This patch fixes that by ensuring the input is drained.  Note
that the behaviour for an empty string buffer is also changed,
avoiding another do_scrub_chars bug where empty input and single char
sized output buffers could result in a write past the end of the
output.

	sb.c (sb_scrub_and_add_sb): Loop until all of input sb is
	consumed.
2022-06-02 15:54:14 +09:30
Alan Modra
6f87d3fd27 asan: heap buffer overflow in dwarf2_directive_filename
Seen with .file 4294967289 "xxx.c"

	* dwarf2dbg.c (assign_file_to_slot): Catch more cases of integer
	overflow.  Make param i an unsigned int.
2022-06-02 15:54:14 +09:30
Alan Modra
b3abcebcae asan: NULL deref in scan_unit_for_symbols
Since commit b43771b045 it has been possible to look up addresses
that match a unit with errors, since ranges are added to a trie while
the unit is being parsed.  On error, parse_comp_unit leaves
first_child_die_ptr NULL which results in a NULL info_ptr being passed
to scan_unit_for_symbols.  Fix this by setting unit->error.

Also wrap some overlong lines, and fix some formatting errors.

	* dwarf2.c: Formatting.
	(parse_comp_unit): Set unit->error on err_exit path.
2022-06-02 15:54:14 +09:30
GDB Administrator
a115b27934 Automatic date update in version.in 2022-06-02 00:00:18 +00:00
Tom de Vries
fc18b1c5af [gdb] Fix warning in foreach_arch selftests
When running the selftests, I run into:
...
$ gdb -q -batch -ex "maint selftest"
  ...
Running selftest execute_cfa_program::aarch64:ilp32.
warning: A handler for the OS ABI "GNU/Linux" is not built into this
configuration of GDB.  Attempting to continue with the default aarch64:ilp32
settings.
...
and likewise for execute_cfa_program::i8086 and
execute_cfa_program::ia64-elf32.

The warning can easily be reproduced outside the selftests by doing:
...
$ gdb -q -batch -ex "set arch aarch64:ilp32"
...
and can be prevented by first doing "set osabi none".

Fix the warning by setting osabi to none while doing selftests that iterate
over all architectures.

Tested on x86_64-linux.
2022-06-01 19:29:40 +02:00
Tom Tromey
80fa4b2a60 Add gdb.current_language and gdb.Frame.language
This adds the gdb.current_language function, which can be used to find
the current language without (1) ever having the value "auto" or (2)
having to parse the output of "show language".

It also adds the gdb.Frame.language, which can be used to find the
language of a given frame.  This is normally preferable if one has a
Frame object handy.
2022-06-01 06:15:53 -06:00
Yvan Roux
46c7fd95fc [arm] Don't use special treatment for PC
In an exception frame the PC register is extracted from the stack
just like other base registers, so there is no need for a special
treatment.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-01 11:14:39 +01:00
Yvan Roux
de76473c2d [arm] Add support for FPU registers in prologue unwinder
The prologue unwinder had support for FPU registers, but only to
calculate the correct offset on the stack, the values were not saved.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-01 11:14:36 +01:00
Yvan Roux
39fc7ff66b [arm] d0..d15 are 64-bit each, not 32-bit
When unwinding the stack, the floating point registers d0 to d15
need to be handled as double words, not words.

Only the first 8 registers have been confirmed fixed with this patch
on a STM32F407-DISC0 board, but the upper 8 registers on Cortex-M33
should be handled in the same way.

The test consisted of running a program compiled with float-abi=hard.
In the main function, a function taking a double as an argument was
called. After the function call, a hardware timer was used to
trigger an interrupt.

In the debug session, a breakpoint was set in the function called
from main to verify the content of the registers using "info float"
and another breakpoint in the interrupt handler was used to check
the same registers using "info float" on frame 2 (the frame just
before the dummy frame created for the signal handler in gdb).

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-01 11:14:32 +01:00
Yvan Roux
1d2eeb660f [arm] Cleanup: use hex for offsets
Changed offset from decimal to hex to match architecture reference
manual terminology and keep coherency with the rest of the code.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-01 11:14:27 +01:00
Jiangshuai Li
68538bbeaa gdb:csky save fpu and vdsp info to struct csky_gdbarch_tdep
First, add three variables fpu_abi, fpu_hardfp and vdsp_version
to csky_gdbarch_tdep. They will be initialized from info.abfd in
cskg_gdbarch_init.

Now, they are just used to find a candidate among the list of pre-declared
architectures

Later, they will be used in gdbarch_return_value and gdbarch_push_dummy_call
for funtions described below:
fpu_abi: to check if the bfd is using VAL_CSKY_FPU_ABI_HARD or
VAL_CSKY_FPU_ABI_SOFT
fpu_hardfp: to check if the bfd is using VAL_CSKY_FPU_HARDFP_SINGLE
or VAL_CSKY_FPU_HARDFP_DOUBLE
vdsp_version: to check if a function is returned with CSKY_VRET_REGNUM
2022-06-01 14:46:01 +08:00
Alan Modra
b0de9ed86f Re: use libiberty xmalloc in bfd/doc/chew.c
We can't use libiberty.a in chew.  libiberty is a host library, chew
a build program.  Partly revert commit 7273d78f3f, instead define
local versions of the libiberty functions.  ansidecl.h also isn't
needed.

	* doc/chew.c: Don't include libiberty.h or ansidecl.h.
	(xmalloc, xrealloc, xstrdup): New functions.
	* doc/local.mk (LIBIBERTY): Don't define or use.
	* Makefile.in: Regenerate.
2022-06-01 10:52:05 +09:30
GDB Administrator
739f950664 Automatic date update in version.in 2022-06-01 00:00:08 +00:00
H.J. Lu
98a1627f19 x86: Properly handle IFUNC function pointer reference
Update

commit 68c4956b14
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Apr 26 09:08:54 2022 -0700

    x86: Properly handle function pointer reference

to properly handle IFUNC function pointer reference.  Since IFUNC symbol
value is only known at run-time, set pointer_equality_needed for IFUNC
function pointer reference in PDE so that it will be resolved to its PLT
entry directly.

bfd/

	PR ld/29216
	* elf32-i386.c (elf_i386_scan_relocs): Set pointer_equality_needed
	for IFUNC function pointer reference in PDE.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.

ld/

	PR ld/29216
	* testsuite/ld-ifunc/ifunc.exp: Run PR ld/29216 test.
	* testsuite/ld-ifunc/pr29216.c: New file.
2022-05-31 16:28:06 -07:00
H.J. Lu
b8be9aea5c i386: Ajdust more tests for opcodes/i386: remove trailing whitespace
This fixes:

FAIL: Build ifunc-1a with -z ibtplt
FAIL: Build ifunc-1a with PIE -z ibtplt
FAIL: Build libno-plt-1b.so
FAIL: No PLT (dynamic 1a)
FAIL: No PLT (dynamic 1b)
FAIL: No PLT (dynamic 1c)
FAIL: No PLT (static 1d)
FAIL: No PLT (PIE 1e)
FAIL: No PLT (PIE 1f)
FAIL: No PLT (PIE 1g)
FAIL: No PLT (dynamic 1h)
FAIL: No PLT (dynamic 1i)
FAIL: No PLT (static 1j)

	* ld-i386/libno-plt-1b.dd: Remove trailing whitespaces.
	* ld-i386/no-plt-1a.dd: Likewise.
	* ld-i386/no-plt-1b.dd: Likewise.
	* ld-i386/no-plt-1c.dd: Likewise.
	* ld-i386/no-plt-1d.dd: Likewise.
	* ld-i386/no-plt-1e.dd: Likewise.
	* ld-i386/no-plt-1f.dd: Likewise.
	* ld-i386/no-plt-1g.dd: Likewise.
	* ld-i386/no-plt-1h.dd: Likewise.
	* ld-i386/no-plt-1i.dd: Likewise.
	* ld-i386/no-plt-1j.dd: Likewise.
	* ld-i386/plt-main-ibt.dd: Likewise.
	* ld-i386/plt-pie-ibt.dd: Likewise.
2022-05-31 14:55:41 -07:00
Tom Tromey
e2904e1ff0 Use unique_ptr for objfiles
A while back, I changed objfiles to be held via a shared_ptr.  The
idea at the time was that this was a step toward writing to the index
cache in the background, and this would let gdb keep a reference alive
to do so.  However, since then we've rewritten the DWARF reader, and
the new index can do this without requiring a shared pointer -- in
fact there are patches pending to implement this.

This patch switches objfile management to unique_ptr, which makes more
sense now.

Regression tested on x86-64 Fedora 34.
2022-05-31 14:46:11 -06:00
Nils-Christian Kempke
ebad7c6613 gdb/testsuite: fixup common-block.exp for intel compilers
The order in which the variables in info common and info locals are
displayed is compiler (and dwarf) dependent.  While all symbols should
be displayed the order is not fixed.

I added a gdb_test_multiple that lets ifx and ifort pass in cases where
only the order differs.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
0df017fbca gdb, testsuite, fortran: fixup mixed-lang-stack for Intel/LLVM compilers
When value-printing a pointer within GDB by default GDB will look for
defined symbols residing at the address of the pointer.  For the given
test the Intel/LLVM compiler stacks both display a symbol associated
with a printed pointer while the gnu stack does not.  This leads to
failures in the test when running the test with CC_FOR_TARGET='clang'
CXX_FOR_TARGET='clang' F90_FOR_TARGET='flang'"

  (gdb) b 37
  (gdb) r
  (gdb) f 6
  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = 4 + 5i
  f = 0x419ed0 "abcdef"
  g = 0x4041a0 <.BSS4>

or CC_FOR_TARGET='icx' CXX_FOR_TARGET='icpx' F90_FOR_TARGET='ifx'"

  (gdb) b 37
  (gdb) r
  (gdb) f 6
  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = 4 + 5i
  f = 0x52eee0 "abcdef"
  g = 0x4ca210 <mixed_func_1a_$OBJ>

For the compiled binary the Intel/LLVM compilers both decide to move the
local variable g into the .bss section of their executable.  The gnu
stack will keep the variable locally on the stack and not define a
symbol for it.

Since the behavior for Intel/LLVM is actually expected I adapted the
testcase at this point to be a bit more allowing for other outputs.
I added the optional "<SYMBOLNAME>" to the regex testing for g.

The given changes reduce the test fails for Intel/LLVM stack by 4 each.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
a60ead5ded gdb, testsuite, fortran: fix double free in mixed-lang-stack.exp
While testing mixed-lang-stack I realized that valgrind actually
complained about a double free in the test.

   All done
  ==2503051==
  ==2503051== HEAP SUMMARY:
  ==2503051==     in use at exit: 0 bytes in 0 blocks
  ==2503051==   total heap usage: 26 allocs, 27 frees, 87,343 bytes allocated
  ==2503051==
  ==2503051== All heap blocks were freed -- no leaks are possible
  ==2503051==
  ==2503051== For lists of detected and suppressed errors, rerun with: -s
  ==2503051== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Reason for this is that in mixed-lang-stack.cpp in mixed_func_1f an
object "derived_type obj" goes on the stack which is then passed-by-value
(so copied) to mixed_func_1g.  The default copy-ctor will be called but,
since derived_type contains a heap allocated string and the copy
constructor is not implemented it will only be able to shallow copy the
object.  Right after each of the functions the object gets freed - on the
other hand the d'tor of derived_type actually is implemented and calls
free on the heap allocated string which leads to a double free.  Instead
of obeying the rule of 3/5 I just got rid of all that since it does not
serve the test.  The string is now just a const char* = ".." object
member.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
6b7b705d7c testsuite, fortran: allow additional completions in module.exp
For ifort, ifx, and flang the tests "complete modm" and "complete
modmany" fail.  This is because all three emit additional completion
suggestions.  These additional suggestions have their origin in symbols
emitted by the compilers which can also be completed from the respective
incomplete word (modm or modmany).  For this specific example gfortran
does not emit any additional symbols.

For example, in this test the linkage name for var_a in ifx is
"modmany_mp_var_a_" while gfortran uses "__modmany_MOD_var_a" instead.
Since modmany_mp_var_a can be completed from modm and also modmany they
will get displayed, while gfortran's symbol starts with "__" and thus will
be ignored (it cannot be a completion of a word starting with "m").

Similar things happen in flang and ifort.  Some example output is shown
below:

FLANG
  (gdb) complete p modm
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p modmany_

IFX/IFORT
  (gdb) complete p modm
  p modmany
  p modmany._
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p modmany_mp_var_a_
  p modmany_mp_var_b_
  p modmany_mp_var_c_
  p modmany_mp_var_i_

GFORTRAN
  (gdb) complete p modm
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i

I want to emphasize: for Fortran (and also C/C++) the complete command
does not actually check whether its suggestions make sense - all it does
is look for any symbol (in the minimal symbols, partial symbols etc.)
that a given substring can be completed to (meaning that the given substring
is the beginning of the symbol).  One can easily produce a similar
output for the gfortran compiled executable.  For this look at the
slightly modified "complete p mod" in gfortran:

  (gdb) complete p mod
  p mod1
  p mod1::var_const
  ...
  p mod_1.c
  p modcounter
  p mode_t
  p modf
  ...
  p modify_ldt
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p module
  p module.f90
  p module_entry
  p moduse
  p moduse::var_x
  p moduse::var_y

Many of the displayed symbols do not actually work with print:

  (gdb) p mode_t
  Attempt to use a type name as an expression
  (gdb) p mod_1.c
  No symbol "mod_1" in current context.
  (gdb)

I think that in the given test the output for gfortran only looks nice
"by chance" rather than is actually expected.  Expected is any output
that also contains the completions

  p modmany

  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i

while anythings else can be displayed as well (depending on the
compiler and its emitted symbols).

This, I'd consider all three outputs as valid and expected - one is just
somewhat lucky that gfortran does not produce any additional symbols that
got matched.

The given patch improves test performance for all three compilers
by allowing additional suggested completions inbetween and after
the two given blocks in the test.  I did not allow additional print
within the modmany_list block since the output is ordered alphabetically
and there should normally not appear any additional symbols there.

For flang/ifx/ifort I each see 2 failures less (which are exactly the two
complete tests).

As a side note and since I mentioned C++ in the beginning: I also tried
the gdb.cp/completion.exp.  The output seems a bit more reasonable,
mainly since C++ actually has a demangler in place and linkage symbols
do not appear in the output of complete.  Still, with a poor enough
to-be-completed string one can easily produce similar results:

  (gdb) complete p t
  ...
  p typeinfo name for void
  p typeinfo name for void const*
  p typeinfo name for void*
  p typeinfo name for wchar_t
  p typeinfo name for wchar_t const*
  p typeinfo name for wchar_t*
  p t *** List may be truncated, max-completions reached. ***
  (gdb) p typeinfo name for void*
  No symbol "typeinfo" in current context.
  (gdb) complete p B
  p BACK_SLASH
  p BUF_FIRST
  p BUF_LAST
  ...
  p Base
  p Base::Base()
  p Base::get_foo()
  p bad_key_err
  p buf
  p buffer
  p buffer_size
  p buflen
  p bufsize
  p build_charclass.isra
  (gdb) p bad_key_err
  No symbol "bad_key_err" in current context.

(compiled with gcc/g++ and breaking at main).

This patch is only about making the referenced test more 'fair' for the
other compilers.  Generally, I find the behavior of complete a bit
confusing and maybe one wants to change this at some point but this
would be a bigger task.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
b8dd7ddff9 testsuite, fortran: fix info-types for intel compilers
This info-types.exp test case had a few issues that this patch fixes.

First, the emitted symbol character(kind=1)/character*1 (different
compilers use different naming converntions here) which is checkedin the
test is not actually expected given the test program.  There is no
variable of that type in the test.  Still, gfortran emits it for every
Fortran program there is.  The reason is the way gfortran handles Fortran's
named main program.  It generates a wrapper around the Fortran program
that is quite similar to a C main function.  This C-like wrapper has
argc and argv arguments for command line argument passing and the argv
pointer type has a base type character(kind=1) DIE emitted at CU scope.

Given the program

  program prog
  end program prog

the degbug info gfortran emits looks somewhat like

   <0><c>: Abbrev Number: 3 (DW_TAG_compile_unit)
      ...
   <1><2f>: Abbrev Number: 4 (DW_TAG_subprogram)
      <30>   DW_AT_external    : 1
      <30>   DW_AT_name        : (indirect string, ...): main
      ...
   <2><51>: Abbrev Number: 1 (DW_TAG_formal_parameter)
      <52>   DW_AT_name        : (indirect string, ...): argc
      ...
   <2><5d>: Abbrev Number: 1 (DW_TAG_formal_parameter)
      <5e>   DW_AT_name        : (indirect string, ...): argv
      ...
      <62>   DW_AT_type        : <0x77>
      ...
   <2><6a>: Abbrev Number: 0
   ...
   <1><77>: Abbrev Number: 6 (DW_TAG_pointer_type)
      <78>   DW_AT_byte_size   : 8
      <79>   DW_AT_type        : <0x7d>
   <1><7d>: Abbrev Number: 2 (DW_TAG_base_type)
      <7e>   DW_AT_byte_size   : 1
      <7f>   DW_AT_encoding    : 8        (unsigned char)
      <80>   DW_AT_name        : (indirect string, ...): character(kind=1)
   <1><84>: Abbrev Number: 7 (DW_TAG_subprogram)
      <85>   DW_AT_name        : (indirect string, ...): prog
   ...

Ifx and flang do not emit any debug info for a wrapper main method so
the type is missing here.  There was the possibility of actually adding
a character*1 type variable to the Fortran executable, but both, ifx and
gfortran chose to emit this variable's type as a DW_TAG_string_type of
length one (instead of a character(kind=1), or whatever the respective
compiler naming convention is).  While string types are printed as
character*LENGHT in the fortran language part (e.g. when issuing a
'ptype') they do not generate any symbols inside GDB.  In read.c it says

   /* These dies have a type, but processing them does not create
      a symbol or recurse to process the children.  Therefore we can
      read them on-demand through read_type_die.  */

So they did not add any output to 'info types'.  Only flang did emit a
character type here.
As adding a type would have a) not solved the problem for ifx and would
have b) somehow hidden the curious behavior of gfortran, instead, the
check for this character type was chagened to optional with the
check_optional_entry to allow for the symbols's absence and to allow
flang and ifx to pass this test as well.

Second, the line checked for s1 was hardcoded as 37 in the test.  Given
that the type is actually defined on line 41 (which is what is emitted by
ifx) it even seems wrong.  The line check for s1 was changed to actually
check for 41 and a gfortran bug has been filed here

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105454

The test is now marked as xfail for gfortran.

Third, the whole test of checking for the 'Type s1' in info types seemed
questionable.  The type s1 is declared iside the scope of the Fortran
program info_types_test.  Its DIE however is emitted as a child of the
whole compilation unit making it visible outside of the program's scope.
The 'info types' command checks for types stored in the GLOBAL_BLOCK,
or STATIC_BLOCKm wgucm according to block.h

   The GLOBAL_BLOCK contains all the symbols defined in this compilation
   whose scope is the entire program linked together.
   The STATIC_BLOCK contains all the symbols whose scope is the
   entire compilation excluding other separate compilations.

so for gfortran, the type shows up in the output of 'info types'.  For
flang and ifx on the other hand this is not the case.  The two compilers
emit the type (correctly) as a child of the Fortran program, thus not
adding it to either, the GLOBAL_BLOCK nor the LOCAL_BLOCK.  A bug has
been opened for the gfortran scoping issue:

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105454

While the most correct change might have been removing the check for s1,
the change made here was to only check for this type in case of gfortran
being used as the compiler, as this check also covers the declaration
line issue mentioned above.  A comment was added to maybe remove this
check once the scoping issue is resolved (and it starts to fail with
newer gfortran versions).  The one used to test these changes was 13.0.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
5c8ff7f6d9 testsuite/lib: add check_optional_entry for GDBInfoSymbols
There was already a similar functionality for the GDBInfoModuleSymbols.
This just extends the GDBInfoSymbols.  We will use this feature in a
later commit to make a testcase less GNU specific and more flexible for
other compilers.

Namely, in gdb.fortran/info-types.exp currenlty
GDBInfoSymbols::check_entry is used to verify and test the output of the
info symbols command.  The test, however was written with gfortran as a
basis and some of the tests are not fair with e.g. ifx and ifort as
they test for symbols that are not actually required to be emitted.  The
lines
   GDBInfoSymbols::check_entry "${srcfile}" "" "${character1}"
and
   GDBInfoSymbols::check_entry "${srcfile}" "37" "Type s1;"

check for types that are either not used in the source file (character1)
or should not be emitted by the compiler at global scope (s1) thus no
appearing in the info symbols command.  In order to fix this we will
later use the newly introduced check_optional_entry over check_entry.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
4212a8c907 testsuite, fortran: Add '-debug-parameters all' when using ifx/ifort
In order for ifx and ifort to emit all debug entries, even for unused
parameters in modules we have to define the '-debug-parameters all' flag.

This commit adds it to the ifx-*/ifort-* specific flags in gdb.exp.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
15868bc883 testsuite, fortran: add compiler dependent types to dynamic-ptype-whatis
The test was earlier not using the compiler dependent type print system
in fortran.exp.  I changed this.  It should generally improve the test
performance for different compilers.  For ifx and gfortran I do not see
any failures.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
93bbd6c793 testsuite, fortran: add required external keyword
Currenlty, ifx/ifort cannot compile the given executable as it is not
valid Fortran.  It is missing the external keyword on the
no_arg_subroutine.  Gfortran compiles the example but this is actually
a bug and there is an open gcc ticket for this here:

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50377

Adding the keyword does not change the gfortran compiling of the example.
It will, however, prevent a future fail once 50377 has been addressed.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
87364601b8 gdb/testsuite: disable charset.exp for intel compilers
The test specifically tests for the Fortran CHARACTER(KIND=4) which is
not available in ifx/ifort.

Since the other characters are also printed elsewhere, we disable this
test for the unsupported compilers.
2022-05-31 16:44:54 +02:00
Nils-Christian Kempke
22582546c1 gdb/testsuite: rename intel next gen c/cpp compilers
The name for icx and icpx in the testsuite was earlier set to 'intel-*'
by the compiler identification.  This commit changes this to 'icx-*'.

Note, that currently these names are not used within the testsuite so no
tests have to be adapted here.
2022-05-31 16:44:54 +02:00