Commit Graph

137 Commits

Author SHA1 Message Date
Alok Kumar Sharma e409c542cc Fixed gdb to print arrays with very high indexes
In the function f77_print_array_1, the variable 'i' which holds the
index is of datatype 'int', while bounds are of datatype LONGEST. Due to
size of int being smaller than LONGEST, the variable 'i' stores
incorrect values for high indexes (higher than max limit of int).  Due
to this issue in sources, two abnormal behaviors are seen while printing
arrays with high indexes (please check array-bounds-high.f90) For high
indexes with negative sign, gdb prints empty array even if the array has
elements.

    (gdb) p arr
    $1 = ()

For high indexes with positive sign, gdb crashes.  We have now changed
the datatype of 'i' to LONGEST which is same as datatype of bounds.

gdb/ChangeLog:

	* f-valprint.c (f77_print_array_1): Changed datatype of index
	variable to LONGEST from int to enable it to contain bound
	values correctly.

gdb/testsuite/ChangeLog:

	* gdb.fortran/array-bounds-high.exp: New file.
	* gdb.fortran/array-bounds-high.f90: New file.

Change-Id: Ie2dce9380a249e634e2684b9c90f225e104369b7
2020-02-03 20:24:34 -05:00
Joel Brobecker b811d2c292 Update copyright year range in all GDB files.
gdb/ChangeLog:

        Update copyright year range in all GDB files.
2020-01-01 10:20:53 +04:00
Andrew Burgess 54f73dad3b gdb/testsuite: kfail some tests if using broken gcc
In some cases the Fortran stride information generated by GCC is wrong
with versions of GCC after 7.x.x.  This commit adds kfails for the
tests in question with known bad versions of gcc.

The bug has been reported to GCC here:

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

gdb/testsuite/ChangeLog:

	* gdb.fortran/derived-type-striding.exp: KFAIL if we are using a
	broken version of GCC.

Change-Id: Iaef08e5e2c87ab3d6983b88f749d40e01aea2bc6
2019-12-09 13:06:05 +00:00
Andrew Burgess d57cbee932 gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+
The gdb.fortran/info-modules.exp and gdb.fortran/info-types.exp tests
are failing on versions of gfortran after 7.3 due to the inclusion of
extra "system" modules and type that were not being matched by the
current test patterns.

Rather than building increasingly complex patterns that would always
be at risk of breaking with future versions of GCC I have instead
added a new library that parses the output of the following commands:

  info types
  info variables
  info functions
  info modules
  info module functions
  info module variables

into a data structure, the test can than run checks against the
contents of this data structure.

The benefit is that we can simply ignore extra results that we don't
care about.

There is a small risk that a bug in GDB might allow us to start
reporting incorrect results in such a way that the new library will
not spot the error.  However, I have tried to mitigate this risk by
adding extra procedures into the test library (see check_no_entry) and
we can add more in future if we wanted to be even more defensive.

I tested this test file with gFortran 7.3.1, 8.3.0, and 9.2.0, I now
see 100% pass in all cases.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-modules.exp: Rewrite to make use of new
	sym-info-cmds library.
	* gdb.fortran/info-types.exp: Likewise.
	* lib/sym-info-cmds.exp: New file.

Change-Id: Iff81624f51b5afb6c95393932f3d94472d7c2970
2019-12-09 13:06:05 +00:00
Andrew Burgess 36c8fb93c9 gdb/fortran: Support for single/double type modifiers
Extend the Fortran parser to support 'single precision' and 'double
precision' types as well 'single complex' and 'double complex' types.

gdb/ChangeLog:

	* f-exp.y (COMPLEX_KEYWORD, SINGLE, DOUBLE, PRECISION): New
	tokens.
	(typebase): New patterns for complex, single/double precision, and
	single/double complex.
	(f77_keywords): Change token for complex keyword, and add single,
	double, and precision keywords.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): Handle
	casting to type with no kind specified.
	(test_basic_parsing_of_type_kinds): Additional tests for types
	with no kind specified, and add tests for single/double
	precision/complex types.

Change-Id: I9c82f4d392c58607747bd08862c1ee330723a1ba
2019-12-04 20:29:53 +00:00
Andrew Burgess 216a7e6b9e gdb: Dynamic string length support
Add support for strings with dynamic length using the DWARF attribute
DW_AT_string_length.

Currently gFortran generates DWARF for some strings that make use of
DW_AT_string_length like this:

 <1><2cc>: Abbrev Number: 20 (DW_TAG_string_type)
    <2cd>   DW_AT_string_length: 5 byte block: 99 bd 1 0 0      (DW_OP_call4: <0x1bd>)
    <2d3>   DW_AT_byte_size   : 4
    <2d4>   DW_AT_sibling     : <0x2e2>

In this type entry the DW_AT_string_length attribute references a
second DW_TAG_formal_parameter that contains the string length.  The
DW_AT_byte_size indicates that the length is a 4-byte value.

This commit extends GDB's DWARF parsing for strings so that we can
create dynamic types as well as static types, based on the attribute
the DWARF contains.

I then extend the dynamic type resolution code in gdbtypes.c to add
support for resolving dynamic strings.

gdb/ChangeLog:

	* dwarf2read.c (read_tag_string_type): Read the fields required to
	make a dynamic string, and possibly create a dynamic range for the
	string.
	(attr_to_dynamic_prop): Setup is_reference based on the type of
	attribute being processed.
	* gdbtypes.c (is_dynamic_type_internal): Handle TYPE_CODE_STRING.
	(resolve_dynamic_array): Rename to...
	(resolve_dynamic_array_or_string): ...this, update header comment,
	and accept TYPE_CODE_STRING.
	(resolve_dynamic_type_internal): Handle TYPE_CODE_STRING.

gdb/testsuite/ChangeLog:

	* gdb.fortran/array-slices.exp: Add test for dynamic strings.

Change-Id: I03f2d181b26156f48f27a03c8a59f9bd4d71ac17
2019-12-01 22:31:32 +00:00
Andrew Burgess 5bbd8269fa gdb/fortran: array stride support
Currently GDB supports a byte or bit stride on arrays, in DWARF this
would be DW_AT_bit_stride or DW_AT_byte_stride on DW_TAG_array_type.
However, DWARF can also support DW_AT_byte_stride or DW_AT_bit_stride
on DW_TAG_subrange_type, the tag used to describe each dimension of an
array.

Strides on subranges are used by gFortran to represent Fortran arrays,
and this commit adds support for this to GDB.

I've extended the range_bounds struct to include the stride
information.  The name is possibly a little inaccurate now, but this
still sort of makes sense, the structure represents information about
the bounds of the range, and also how to move from the lower to the
upper bound (the stride).

I've added initial support for bit strides, but I've never actually
seen an example of this being generated.  Further, I don't really see
right now how GDB would currently handle a bit stride that was not a
multiple of the byte size as the code in, for example,
valarith.c:value_subscripted_rvalue seems geared around byte
addressing.  As a consequence if we see a bit stride that is not a
multiple of 8 then GDB will give an error.

gdb/ChangeLog:

	* dwarf2read.c (read_subrange_type): Read bit and byte stride and
	create a range with stride where appropriate.
	* f-valprint.c: Include 'gdbarch.h'.
	(f77_print_array_1): Take the stride into account when walking the
	array.  Also convert the stride into addressable units.
	* gdbtypes.c (create_range_type): Initialise the stride to
	constant zero.
	(create_range_type_with_stride): New function, initialise the
	range as normal, and then setup the stride.
	(has_static_range): Include the stride here.  Also change the
	return type to bool.
	(create_array_type_with_stride): Consider the range stride if the
	array isn't given its own stride.
	(resolve_dynamic_range): Resolve the stride if needed.
	* gdbtypes.h (struct range_bounds) <stride>: New member variable.
	(struct range_bounds) <flag_is_byte_stride>: New member variable.
	(TYPE_BIT_STRIDE): Define.
	(TYPE_ARRAY_BIT_STRIDE): Define.
	(create_range_type_with_stride): Declare.
	* valarith.c (value_subscripted_rvalue): Take range stride into
	account when walking the array.

gdb/testsuite/ChangeLog:

	* gdb.fortran/derived-type-striding.exp: New file.
	* gdb.fortran/derived-type-striding.f90: New file.
	* gdb.fortran/array-slices.exp: New file.
	* gdb.fortran/array-slices.f90: New file.

Change-Id: I9af2bcd1f2d4c56f76f5f3f9f89d8f06bef10d9a
2019-12-01 22:31:30 +00:00
Andrew Burgess 640ab94712 gdb/testsuite: Fix race condition compiling fortran test
The Fortran test gdb.fortran/info-modules compiles the files
info-types.f90 and info-types-2.f90 in that order.  Unfortunately
info-types.f90 makes use of a module defined in info-types-2.f90.

This currently doesn't cause a problem if you run all of the Fortran
tests as the info-types.exp test already compiles info-types-2.f90 and
so the module description file 'mod2.mod' will be created, and can
then be found by info-modules.exp during its compile.

If however you try to run just info-modules.exp in a clean build
directory, the test will fail to compile.

Fix this by compiling the source files in the reverse order so that
the module is compiled first, then the test program that uses the
module.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-modules.exp: Compile source files in correct
	order.

Change-Id: Ic3a1eded0486f6264ebe3066cf1beafbd2534a91
2019-11-27 21:18:38 +00:00
Andrew Burgess 165f8965d7 gdb: Add new commands to list module variables and functions
This patch adds two new commands "info module functions" and "info
module variables".  These commands list all of the functions and
variables grouped by module and then by file.

For example:

  (gdb) info module functions
  All functions in all modules:

  Module "mod1":

  File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
  35:	void mod1::__copy_mod1_M1t1(Type m1t1, Type m1t1);
  25:	void mod1::sub_m1_a(integer(kind=4));
  31:	integer(kind=4) mod1::sub_m1_b(void);

  Module "mod2":

  File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
  41:	void mod2::sub_m2_a(integer(kind=4), logical(kind=4));
  49:	logical(kind=4) mod2::sub_m2_b(real(kind=4));

The new commands take set of flags that allow the output to be
filtered, the user can filter by variable/function name, type, or
containing module.

As GDB doesn't currently track the relationship between a module and
the variables or functions within it in the symbol table, so I filter
based on the module prefix in order to find the functions or variables
in each module.  What this makes clear is that a user could get this
same information using "info variables" and simply provide the prefix
themselves, for example:

  (gdb) info module functions -m mod1 _a
  All functions matching regular expression "_a",
  	in all modules matching regular expression "mod1":

  Module "mod1":

  File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
  25:	void mod1::sub_m1_a(integer(kind=4));

Is similar to:

  (gdb) info functions mod1::.*_a.*
  All functions matching regular expression "mod1::.*_a":

  File /some/path/gdb/testsuite/gdb.fortran/info-types.f90:
  25:	void mod1::sub_m1_a(integer(kind=4));

The benefits I see for a separate command are that the user doesn't
have to think (or know) about the module prefix format, nor worry
about building a proper regexp.  The user can also easily scan across
modules without having to build complex regexps.

The new function search_module_symbols is extern in this patch despite
only being used within symtab.c, this is because a later patch in this
series will also be using this function from outside symtab.c.

This patch is a new implementation of an idea originally worked on by
Mark O'Connor, Chris January, David Lecomber, and Xavier Oro from ARM.

gdb/ChangeLog:

	* symtab.c (info_module_cmdlist): New variable.
	(info_module_command): New function.
	(search_module_symbols): New function.
	(info_module_subcommand): New function.
	(struct info_modules_var_func_options): New struct.
	(info_modules_var_func_options_defs): New variable.
	(make_info_modules_var_func_options_def_group): New function.
	(info_module_functions_command): New function.
	(info_module_variables_command): New function.
	(info_module_var_func_command_completer): New function.
	(_initialize_symtab): Register new 'info module functions' and
	'info module variables' commands.
	* symtab.h (typedef symbol_search_in_module): New typedef.
	(search_module_symbols): Declare new function.
	* NEWS: Mention new commands.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new 'info module variables' and
	'info module functions' commands.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-modules.exp: Update expected results, and add
	additional tests for 'info module functinos', and 'info module
	variables'.
	* gdb.fortran/info-types.exp: Update expected results.
	* gdb.fortran/info-types.f90: Extend testcase with additional
	module variables and functions.

Change-Id: I8c2960640e2e101b77eff54027d687e21ec22e2b
2019-10-31 23:02:59 +00:00
Andrew Burgess 59c35742fb gdb/fortran: Add new 'info modules' command
Add a new command 'info modules' that lists all of the modules GDB
knows about from the debug information.

A module is a debugging entity in the DWARF defined with
DW_TAG_module, currently Fortran is known to use this tag for its
modules.  I'm not aware of any other language that currently makes use
of DW_TAG_module.

The output style is similar to the 'info type' output:

    (gdb) info modules
    All defined modules:

    File info-types.f90:
    16:     mod1
    24:     mod2
    (gdb)

Where the user is told the file the module is defined in and, on the
left hand side, the line number at which the module is defined along
with the name of the module.

This patch is a new implementation of an idea originally worked on by
Mark O'Connor, Chris January, David Lecomber, and Xavier Oro from ARM.

gdb/ChangeLog:

	* dwarf2read.c (dw2_symtab_iter_next): Handle MODULE_DOMAIN.
	(dw2_expand_marked_cus): Handle MODULES_DOMAIN.
	(dw2_debug_names_iterator::next): Handle MODULE_DOMAIN and
	MODULES_DOMAIN.
	(scan_partial_symbols): Only create partial module symbols for non
	declarations.
	* psymtab.c (recursively_search_psymtabs): Handle MODULE_DOMAIN
	and MODULES_DOMAIN.
	* symtab.c (search_domain_name): Likewise.
	(search_symbols): Likewise.
	(print_symbol_info): Likewise.
	(symtab_symbol_info): Likewise.
	(info_modules_command): New function.
	(_initialize_symtab): Register 'info modules' command.
	* symtab.h (enum search_domain): Add MODULES_DOMAIN.
	* NEWS: Mention new 'info modules' command.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new 'info modules' command.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-modules.exp: New file.
	* gdb.fortran/info-types.exp: Build with new file.
	* gdb.fortran/info-types.f90: Include and use new module.
	* gdb.fortran/info-types-2.f90: New file.

Change-Id: I2b781dd5a06bcad04620ccdc45f01a0f711adfad
2019-10-31 23:02:59 +00:00
Tom de Vries d1e36019c1 [gdb/testsuite] Remove superfluous 3rd argument from gdb_test call (2)
There's a pattern:
...
gdb_test <command> <pattern> <command>
...
that can be written shorter as:
...
gdb_test <command> <pattern>
...

Detect this pattern in proc gdb_test:
...
     global gdb_prompt
     upvar timeout timeout

     if [llength $args]>2 then {
        set message [lindex $args 2]
+       if { $message == [lindex $args 0] && [llength $args] == 3 } {
+           error "HERE"
+       }
     } else {
         set message [lindex $args 0]
     }
...
and fix all occurrences in some gdb testsuite subdirs.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-10-31  Tom de Vries  <tdevries@suse.de>

	* gdb.arch/amd64-disp-step-avx.exp: Drop superfluous 3rd argument to
	gdb_test.
	* gdb.arch/amd64-disp-step.exp: Same.
	* gdb.asm/asm-source.exp: Same.
	* gdb.btrace/buffer-size.exp: Same.
	* gdb.btrace/cpu.exp: Same.
	* gdb.btrace/enable.exp: Same.
	* gdb.dwarf2/count.exp: Same.
	* gdb.dwarf2/dw2-ranges-func.exp: Same.
	* gdb.dwarf2/dw2-ranges-psym.exp: Same.
	* gdb.fortran/vla-datatypes.exp: Same.
	* gdb.fortran/vla-history.exp: Same.
	* gdb.fortran/vla-ptype.exp: Same.
	* gdb.fortran/vla-value.exp: Same.
	* gdb.fortran/whatis_type.exp: Same.
	* gdb.guile/guile.exp: Same.
	* gdb.multi/tids.exp: Same.
	* gdb.python/py-finish-breakpoint.exp: Same.
	* gdb.python/py-framefilter.exp: Same.
	* gdb.python/py-pp-registration.exp: Same.
	* gdb.python/py-xmethods.exp: Same.
	* gdb.python/python.exp: Same.
	* gdb.server/connect-with-no-symbol-file.exp: Same.
	* gdb.server/no-thread-db.exp: Same.
	* gdb.server/run-without-local-binary.exp: Same.
	* gdb.stabs/weird.exp: Same.
	* gdb.threads/attach-many-short-lived-threads.exp: Same.
	* gdb.threads/thread-find.exp: Same.
	* gdb.threads/tls-shared.exp: Same.
	* gdb.threads/tls.exp: Same.
	* gdb.threads/wp-replication.exp: Same.
	* gdb.trace/ax.exp: Same.
	* lib/gdb.exp (gdb_test_exact, help_test_raw): Same.

Change-Id: I2fa544c68f8c0099a77e03ff04ddc010eb2b6c7c
2019-10-31 23:03:25 +01:00
Tom de Vries 062f1fc13a [gdb/testsuite] Fix gdb.fortran/module.exp for debug info from other files
On openSUSE Leap 15.1, I get:
...
FAIL: gdb.fortran/module.exp: info variables -n
...
because the info variables command prints info also for init.c:
...
File init.c:^M
24:     const int _IO_stdin_used;^M
...
while the regexps in the test-case only expect info for module.f90.

Fix this by extending the regexps.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-10-17  Tom de Vries  <tdevries@suse.de>

	* gdb.fortran/module.exp: Allow info variables to print info for files
	other than module.f90.

Change-Id: I401d8018b121fc7343f6bc8b671900349462457f
2019-10-17 10:07:05 +02:00
Andrew Burgess 0b54364d92 gdb/fortran: Add test for module variables in 'info variables' output
Recent work from Tom Tromey to better handle variables with associated
copy relocations has fixed a Fortran issue where module variables
wouldn't show up in the output of 'info variables'.

This commit adds a test for this functionality to ensure it doesn't
get broken in the future.

gdb/testsuite/ChangeLog:

	* gdb.fortran/module.exp: Extend with 'info variables' test.

Change-Id: I7306b1d0a9a72947fd48ad7a03f49df774d6573b
2019-10-16 22:22:09 +01:00
Andrew Burgess 179aed7fdc gdb/fortran: Allow for matching symbols with missing scope
This commit allows symbol matching within Fortran code without having
to specify all of the symbol's scope.  For example, given this Fortran
code:

    module aaa
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo
    end module aaa

    subroutine foo
      print *, "hello."
    end subroutine foo

    program test
      call foo
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo

      subroutine bar
        use aaa
        call foo
      end subroutine bar
    end program test

The user can now do this:

    (gdb) b foo
    Breakpoint 1 at 0x4006c2: foo. (3 locations)
    (gdb) info breakpoints
    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   <MULTIPLE>
    1.1                         y   0x00000000004006c2 in aaa::foo at nest.f90:4
    1.2                         y   0x0000000000400730 in foo at nest.f90:9
    1.3                         y   0x00000000004007c3 in test::foo at nest.f90:16

The user asks for a breakpoint on 'foo' and is given a breakpoint on
all three possible 'foo' locations.  The user is, of course, still
able to specify the scope in order to place a single breakpoint on
just one of the foo functions (or use 'break -qualified foo' to break
on just the global foo).

gdb/ChangeLog:

	* f-lang.c (f_language_defn): Use cp_get_symbol_name_matcher and
	cp_search_name_hash.
	* NEWS: Add entry about nested function support.

gdb/testsuite/ChangeLog:

	* gdb.fortran/nested-funcs-2.exp: Run tests with and without the
	nested function prefix.
2019-10-03 21:25:22 +01:00
Andrew Burgess 0a4b09130a gdb/fortran: Nested subroutine support
This patch is a rebase and update of the following three patches:

   https://sourceware.org/ml/gdb-patches/2018-11/msg00298.html
   https://sourceware.org/ml/gdb-patches/2018-11/msg00302.html
   https://sourceware.org/ml/gdb-patches/2018-11/msg00301.html

I have merged these together into a single commit as the second patch,
adding scope support to nested subroutines, means that some of the
changes in the first patch are now no longer useful and would have to
be backed out.  The third patch is tightly coupled to the changes in
the second of these patches and I think deserves to live together with
it.

There is an extra change in cp-namespace.c that is new, this resolves
an issue with symbol lookup when placing breakpoints from within
nested subroutines.

There is also an extra test added to this commit 'nested-funcs-2.exp'
that was written by Richard Bunt from ARM, this offers some additional
testing of breakpoints on nested functions.

After this commit it is possible to place breakpoints on nested
Fortran subroutines and functions by using a fully scoped name, for
example, given this simple Fortran program:

    program greeting
      call message
    contains
      subroutine message
        print *, "Hello World"
      end subroutine message
    end program greeting

It is possible to place a breakpoint in 'message' with:

    (gdb) break greeting::message
    Breakpoint 1 at 0x4006c9: file basic.f90, line 5.

What doesn't work with this commit is placing a breakpoint like this:

    (gdb) break message
    Function "message" not defined.

Making this work will come in a later commit.

gdb/ChangeLog:

	* cp-namespace.c (cp_search_static_and_baseclasses): Only search
	for nested static variables when searchin VAR_DOMAIN.
	* dwarf2read.c (add_partial_symbol): Add nested subroutines to the
	global scope, update comment.
	(add_partial_subprogram): Call add_partial_subprogram recursively
	for nested subroutines when processinng Fortran.
	(load_partial_dies): Process the child entities of a subprogram
	when processing Fortran.
	(partial_die_parent_scope): Handle building scope
	for Fortran nested functions.
	(process_die): Record that nested functions have a scope.
	(new_symbol): Always record Fortran subprograms on the global
	symbol list.
	(determine_prefix): How to build the prefix for Fortran
	subprograms.

gdb/testsuite/ChangeLog:

	* gdb.fortran/nested-funcs.exp: Tests for placing breakpoints on
	nested functions.
	* gdb.fortran/nested-funcs.f90: Update expected results.
	* gdb.fortran/nested-funcs-2.exp: New file.
	* gdb.fortran/nested-funcs-2.f90: New file.

gdb/doc/ChangeLog:

	* doc/gdb.texinfo (Fortran Operators): Describe scope operator.
2019-10-03 21:25:22 +01:00
Tom de Vries 8077c50dbb [gdb/testsuite] Fix gdb.fortran/info-types.exp regexp
The gdb.fortran/info-types.exp test-case passes with gcc 7 (though not on
openSUSE, due to the extra debug info) and fails with gcc 4.8 and gcc 8.

Fix the gdb_test regexp to fix all those cases.

gdb/testsuite/ChangeLog:

2019-08-29  Tom de Vries  <tdevries@suse.de>

	* gdb.fortran/info-types.exp: Fix gdb_test regexp to allow more
	diverse debug info.
	* lib/fortran.exp (fortran_int8): New proc, based on fortran_int4.
2019-08-29 14:43:11 +02:00
Andrew Burgess d8f27c6018 gdb/fortran: Don't include module symbols when searching for types
Currently the 'info types' command will return symbols that correspond
to Fortran modules.  This is because the symbols are created with
domain MODULE_DOMAIN and address_class LOC_TYPEDEF.  The address_class
LOC_TYPEDEF is the same address_class used for type symbols which is
why the modules show up when listing types.

This commit explicitly prevents symbols in the MODULE_DOMAIN from
appearing when we search for symbols in the TYPES_DOMAIN, this
prevents the Fortran module symbols from appearing in the output of
'info types'.

gdb/ChangeLog:

	* symtab.c (search_symbols): Don't include MODULE_DOMAIN symbols
	when searching for types.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-types.exp: Add module.
	* gdb.fortran/info-types.f90: Update expected results.
2019-08-28 13:33:55 +01:00
Andrew Burgess 1f20c35ea4 gdb/fortran: Implement la_print_typedef for Fortran
Implement an la_print_typedef method for Fortran, this allows 'info
types' to work for Fortran.  The implementation is just copied from
ada_print_typedef (with the appropriate changes).

To support the testing of this patch I added a new proc,
fortran_character1, to lib/fortran.exp which returns a regexp to match
a 1-byte character type.  The regexp returned is correct for current
versions of gFortran.  All of the other regexp are guesses based on
all of the other support procs in lib/fortran.exp, I haven't tested
them myself.

gdb/ChangeLog:

	* f-lang.c (f_language_defn): Use f_print_typedef.
	* f-lang.h (f_print_typedef): Declare.
	* f-typeprint.c (f_print_typedef): Define.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-types.exp: New file.
	* gdb.fortran/info-types.f90: New file.
	* lib/fortran.exp (fortran_character1): New proc.
2019-08-28 13:33:54 +01:00
Andrew Burgess 0d4e84ed37 gdb: Better support for dynamic properties with negative values
When the type of a property is smaller than the CORE_ADDR in which the
property value has been placed, and if the property is signed, then
sign extend the property value from its actual type up to the size of
CORE_ADDR.

gdb/ChangeLog:

	* dwarf2loc.c (dwarf2_evaluate_property): Sign extend property
	value if its desired type is smaller than a CORE_ADDR and signed.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-ptype.exp: Print array with negative bounds.
	* gdb.fortran/vla-sizeof.exp: Print the size of an array with
	negative bounds.
	* gdb.fortran/vla-value.exp: Print elements of an array with
	negative bounds.
	* gdb.fortran/vla.f90: Setup an array with negative bounds for
	testing.
2019-07-12 12:09:55 +01:00
Andrew Burgess 584a927c5a gdb/fortran: Show the type for non allocated / associated types
Show the type of not-allocated and/or not-associated types.  For array
types and pointer to array types we are going to print the number of
ranks.

Consider this Fortran program:

  program test
    integer, allocatable :: vla (:)
    logical l
    allocate (vla(5:12))
    l = allocated (vla)
  end program test

And this GDB session with current HEAD:

  (gdb) start
  ...
  2	  integer, allocatable :: vla (:)
  (gdb) n
  4	  allocate (vla(5:12))
  (gdb) ptype vla
  type = <not allocated>
  (gdb) p vla
  $1 = <not allocated>
  (gdb)

And the same session with this patch applied:

  (gdb) start
  ...
  2	  integer, allocatable :: vla (:)
  (gdb) n
  4	  allocate (vla(5:12))
  (gdb) ptype vla
  type = integer(kind=4), allocatable (:)
  (gdb) p vla
  $1 = <not allocated>
  (gdb)

The type of 'vla' is now printed correctly, while the value itself
still shows as '<not allocated>'.  How GDB prints the type of
associated pointers has changed in a similar way.

gdb/ChangeLog:

	* f-typeprint.c (f_print_type): Don't return early for not
	associated or not allocated types.
	(f_type_print_varspec_suffix): Add print_rank parameter and print
	ranks of array types in case they dangling.
	(f_type_print_base): Add print_rank parameter.

gdb/testsuite/ChangeLog:

	* gdb.fortran/pointers.f90: New file.
	* gdb.fortran/print_type.exp: New file.
	* gdb.fortran/vla-ptype.exp: Adapt expected results.
	* gdb.fortran/vla-type.exp: Likewise.
	* gdb.fortran/vla-value.exp: Likewise.
	* gdb.mi/mi-vla-fortran.exp: Likewise.
2019-06-16 00:29:35 +01:00
Bernhard Heckel a5fd13a915 Dwarf: Don't add nameless modules to partial symbol table
A name for BLOCK DATA in Fortran is optional.  If no name has been
assigned, GDB crashes during read-in of DWARF when BLOCK DATA is
represented via DW_TAG_module.  BLOCK DATA is used for one-time
initialization of non-pointer variables in named common blocks.

As of now there is no issue when gfortran is used as DW_TAG_module is
not emitted.  However, with Intel ifort the nameless DW_TAG_module is
present and has the following form:

 ...
  <1><dd>: Abbrev Number: 7 (DW_TAG_module)
     <de>   DW_AT_decl_line   : 46
     <df>   DW_AT_decl_file   : 1
     <e0>   DW_AT_description : (indirect string, offset: 0x110): block
 data
     <e4>   DW_AT_high_pc     : 0x402bb7
     <ec>   DW_AT_low_pc      : 0x402bb7
 ...

The missing name leads to a crash in add_partial_symbol, during length
calculation.

gdb/ChangeLog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

	* dwarf2read.c (add_partial_symbol): Skip nameless modules.

gdb/testsuite/Changelog:
2019-06-11  Bernhard Heckel  <bernhard.heckel@intel.com>

	* gdb.fortran/block-data.f: New.
	* gdb.fortran/block-data.exp: New.
2019-06-11 19:20:09 +01:00
Andrew Burgess a706786341 gdb: Check for not allocated/associated values during array slicing
When extracting an array slice we should give up if the array is
not-allocated or not-associated.  For Fortran, at least in gfortran
compiled code, the upper and lower bounds are undefined if the array
is not allocated or not associated, in which case performing checks
against these bounds will result in undefined behaviour.

Better then to throw an error if we try to slice such an array.  This
changes the error message that the user will receive in these
cases (if they got an error message before).  Previously they may have
gotten "slice out of range" now they'll get "array not allocated" or
"array not associated".

gdb/ChangeLog:

	* valops.c (value_slice): Check for not allocated or not
	associated values.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-sizeof.exp: Update expected results.
2019-06-10 23:05:58 +01:00
Andrew Burgess 34d11c682f gdb/fortran: Use floatformats_ia64_quad for fortran 16-byte floats
PR gdb/18644 is caused by GDB using the wrong floating point format
for gfortran's 16-byte floating point type, including when the 16-byte
float is used as the component of a 32-byte complex type.

This commit addresses the issue in two places, first in i386-tdep.c,
there is already some code to force the use of floatformats_ia64_quad
for specific named types, this is extended to include the type names
that gfortran uses for its 16-byte floats.

Second, the builtin 16-byte float type (in f-lang.c) is changed so it
no longer uses gdbarch_long_double_format.  On i386 this type is not
16-bytes, but is smaller, this is not what gfortran is expecting.
Instead we now use gdbarch_floatformat_for_type and ask for a
16-byte (128 bit) type using the common gfortran type name.  This is
then spotted in i386-tdep.c (thanks to the first change above) and we
again get floatformats_ia64_quad returned.

This patch was tested on X86-64/GNU-Linux using '--target_board=unix'
and '--target_board=unix/-m32', and resolves all of the known failures
associated with PR gdb/18644.  I've also added the test case from the
original bug report.

gdb/ChangeLog:

	PR gdb/18644:
	* f-lang.c (build_fortran_types): Use floatformats_ia64_quad for
	16-byte floats.
	* i386-tdep.c (i386_floatformat_for_type): Use
	floatformats_ia64_quad for the 16-byte floating point component
	within a fortran 32-byte complex number.

gdb/testsuite/ChangeLog:

	PR gdb/18644
	* gdb.fortran/complex.exp: Remove setup_kfail calls.
	* gdb.fortran/printing-types.exp: Add new test.
	* gdb.fortran/printing-types.f90: Add 16-byte real variable for
	testing.
	* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): Remove
	setup_kfail call.
2019-05-18 09:49:02 +01:00
Andrew Burgess 14237686d7 gdb/fortran: Add sizeof tests for indexed and sliced arrays
Add tests for calling sizeof on indexed and sliced arrays, and on
pointers to arrays.  These are all things that currently work, but
were previously untested.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-sizeof.exp: Add tests of sizeof applied to
	indexed and sliced arrays, and pointers to arrays.
2019-05-15 22:26:33 +01:00
Andrew Burgess bc68014d16 gdb/fortran: Add allocatable type qualifier
Types in Fortran can have the 'allocatable' qualifier attached to
indicate that memory needs to be explicitly allocated by the user.
This patch extends GDB to show this qualifier when printing types.

Lots of tests results are then updated to include this new qualifier
in the expected results.

gdb/ChangeLog:

	* f-typeprint.c (f_type_print_base): Print 'allocatable' type
	qualifier.
	* gdbtypes.h (TYPE_IS_ALLOCATABLE): Define.

gdb/testsuite/ChangeLog:

	* gdb.fortran/vla-datatypes.exp: Update expected results.
	* gdb.fortran/vla-ptype.exp: Likewise.
	* gdb.fortran/vla-type.exp: Likewise.
	* gdb.fortran/vla-value.exp: Likewise.
2019-04-30 10:36:57 +01:00
Andrew Burgess f1fdc96066 gdb/fortran: Update rules for printing whitespace in types
The whitespace produced as types are printed seems inconsistent.  This
commit updates the rules in an attempt to make whitespace more
balanced and consistent.  Expected results are updated.

gdb/ChangeLog:

	* f-typeprint.c (f_print_type): Update rules for printing
	whitespace.
	(f_type_print_varspec_suffix): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.fortran/ptr-indentation.exp: Update expected results.
	* gdb.fortran/ptype-on-functions.exp: Likewise.
	* gdb.fortran/vla-ptr-info.exp: Likewise.
	* gdb.fortran/vla-value.exp: Likewise.
2019-04-30 10:36:56 +01:00
Andrew Burgess bf7a4de172 gdb/fortran: print function arguments when printing function type
Before this commit using ptype on a Fortran function will include
information about the functions return type, but not the expected
arguments as it would for C or C++.  After this commit argument types
are included in the ptype output.

For example, before GDB prints:

    (gdb) ptype fun1
    type = integer(kind=4) ()
    (gdb) ptype is_bigger
    type = logical(kind=4) ()

and after GDB prints:

    (gdb) ptype fun1
    type = integer(kind=4) (integer(kind=4))
    (gdb) ptype is_bigger
    type = logical(kind=4) (integer(kind=4), integer(kind=4))

gdb/ChangeLog:

	* f-typeprint.c (f_type_print_varspec_suffix): Handle printing
	function arguments.

gdb/testsuite/ChangeLog:

	* gdb.fortran/ptype-on-functions.exp: New file.
	* gdb.fortran/ptype-on-functions.f90: New file.
2019-04-30 10:34:26 +01:00
Andrew Burgess bbe75b9d00 gdb/fortran: Print 'void' type in lower case
For a program compiled with gfortran the base type names are written
as lower cases in the DWARF, and so GDB will display them as lower
case.  Additionally, in most places where GDB supplies its own type
names (for example all of the types defined in f-lang.c in
`build_fortran_types`), the type names are all lower case.

An exception to this is where GDB prints the void type for Fortran.
In this case GDB uses upper case.

I'm not aware of any reason why this type should merit special
attention, and it looks our of place when printing types, so this
commit changes from 'VOID' to 'void' to match all the other types.

gdb/ChangeLog:

	* f-lang.c (build_fortran_types): Change name of void type to
	lower case.
	* f-typeprint.c (f_type_print_base): Print the name of the void
	type, rather than a fixed string.
	* f-valprint.c (f_decorations): Use lower case void string.

gdb/testsuite/ChangeLog:

	* gdb.fortran/exprs.exp (test_convenience_variables): Expect lower
	case void string.
2019-04-30 10:17:01 +01:00
Andrew Burgess 1db455a76c gdb/fortran: better types for components of complex numbers
Currently when using $_creal and $_cimag to access the components of a
complex number the types of these components will have C type names
'float', 'double', etc.  This is because the components of a complex
number are not given type names in DWARF, so GDB has to pick some
suitable names, and currently we always use the C names.

This commit changes the type names used based on the language, so for
Fortran we will now use the Fortran float types, and so will get the
Fortran float type names 'real', 'real*8', etc.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_init_complex_target_type): Use different
	types for Fortran.

gdb/testsuite/ChangeLog:

	* gdb.fortran/complex.exp: Expand.
	* gdb.fortran/complex.f: Renamed to...
	* gdb.fortran/complex.f90: ...this, and extended to add more
	complex values.
2019-04-30 10:10:31 +01:00
Andrew Burgess b6d03bb2b6 gdb/fortran: Additional builtin procedures
Add some additional builtin procedures for Fortran, these are MOD,
CEILING, FLOOR, MODULO, and CMPLX.

gdb/ChangeLog:

	* f-exp.y (BINOP_INTRINSIC): New token.
	(exp): New parser rule handling BINOP_INTRINSIC.
	(f77_keywords): Add new builtin procedures.
	* f-lang.c (evaluate_subexp_f): Handle BINOP_MOD, UNOP_FORTRAN_CEILING,
	UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
	(operator_length_f): Handle UNOP_FORTRAN_CEILING,
	UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
	(print_unop_subexp_f): New function.
	(print_binop_subexp_f): New function.
	(print_subexp_f): Handle UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
	BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
	(dump_subexp_body_f): Likewise.
	(operator_check_f): Likewise.
	* fortran-operator.def: Add UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
	BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX

gdb/testsuite/ChangeLog:

	* gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
	MODULO, CMPLX.
2019-04-30 10:10:24 +01:00
Andrew Burgess 2e62ab400f gdb: Introduce 'print max-depth' feature
Introduce a new print setting max-depth which can be set with 'set
print max-depth DEPTH'.  The default value of DEPTH is 20, but this
can also be set to unlimited.

When GDB is printing a value containing nested structures GDB will
stop descending at depth DEPTH.  Here is a small example:

    typedef struct s1 { int a; } s1;
    typedef struct s2 { s1 b; } s2;
    typedef struct s3 { s2 c; } s3;
    typedef struct s4 { s3 d; } s4;

    s4 var = { { { { 3 } } } };

The following table shows how various depth settings affect printing
of 'var':

    | Depth Setting | Result of 'p var'              |
    |---------------+--------------------------------|
    |     Unlimited | $1 = {d = {c = {b = {a = 3}}}} |
    |             4 | $1 = {d = {c = {b = {a = 3}}}} |
    |             3 | $1 = {d = {c = {b = {...}}}}   |
    |             2 | $1 = {d = {c = {...}}}         |
    |             1 | $1 = {d = {...}}               |
    |             0 | $1 = {...}                     |

Only structures, unions, and arrays are replaced in this way, scalars
and strings are not replaced.

The replacement is counted from the level at which you print, not from
the top level of the structure.  So, consider the above example and
this GDB session:

    (gdb) set print max-depth 2
    (gdb) p var
    $1 = {d = {c = {...}}}
    (gdb) p var.d
    $2 = {c = {b = {...}}}
    (gdb) p var.d.c
    $3 = {b = {a = 3}}

Setting the max-depth to 2 doesn't prevent the user from exploring
deeper into 'var' by asking for specific sub-fields to be printed.

The motivation behind this feature is to try and give the user more
control over how much is printed when examining large, complex data
structures.

The default max-depth of 20 means that there is a change in GDB's
default behaviour.  Someone printing a data structure with 20 levels
of nesting will now see '{...}' instead of their data, they would need
to adjust the max depth, or call print again naming a specific field
in order to dig deeper into their data structure.  If this is
considered a problem then we could increase the default, or even make
the default unlimited.

This commit relies on the previous commit, which added a new field to
the language structure, this new field was a string that contained the
pattern that should be used when a structure/union/array is replaced
in the output, this allows languages to use a syntax that is more
appropriate, mostly this will be selecting the correct types of
bracket '(...)' or '{...}', both of which are currently in use.

This commit should have no impact on MI output, expressions are
printed through the MI using -var-create and then -var-list-children.
As each use of -var-list-children only ever displays a single level of
an expression then the max-depth setting will have no impact.

This commit also adds the max-depth mechanism to the scripting
language pretty printers following basically the same rules as for the
built in value printing.

One quirk is that when printing a value using the display hint 'map',
if the keys of the map are structs then GDB will hide the keys one
depth level after it hides the values, this ensures that GDB produces
output like this:

  $1 = map_object = {[{key1}] = {...}, [{key2}] = {...}}

Instead of this less helpful output:

  $1 = map_object = {[{...}] = {...}, [{...}] = {...}}

This is covered by the new tests in gdb.python/py-nested-maps.exp.

gdb/ChangeLog:

	* cp-valprint.c (cp_print_value_fields): Allow an additional level
	of depth when printing anonymous structs or unions.
	* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer):
	Don't print either the top-level value, or the children if the
	max-depth is exceeded.
	(ppscm_print_children): When printing the key of a map, allow one
	extra level of depth.
	* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Don't
	print either the top-level value, or the children if the max-depth
	is exceeded.
	(print_children): When printing the key of a map, allow one extra
	level of depth.
	* python/py-value.c (valpy_format_string): Add max_depth keyword.
	* valprint.c: (PRINT_MAX_DEPTH_DEFAULT): Define.
	(user_print_options): Initialise max_depth field.
	(val_print_scalar_or_string_type_p): New function.
	(val_print): Check to see if the max depth has been reached.
	(val_print_check_max_depth): Define new function.
	(show_print_max_depth): New function.
	(_initialize_valprint): Add 'print max-depth' option.
	* valprint.h (struct value_print_options) <max_depth>: New field.
	(val_print_check_max_depth): Declare new function.
	* NEWS: Document new feature.

gdb/doc/ChangeLog:

	* gdb.texinfo (Print Settings): Document 'print max-depth'.
	* guile.texi (Guile Pretty Printing API): Document that 'print
	max-depth' can effect the display of a values children.
	* python.texi (Pretty Printing API): Likewise.
	(Values From Inferior): Document max_depth keyword.

gdb/testsuite/ChangeLog:

	* gdb.base/max-depth.c: New file.
	* gdb.base/max-depth.exp: New file.
	* gdb.python/py-nested-maps.c: New file.
	* gdb.python/py-nested-maps.exp: New file.
	* gdb.python/py-nested-maps.py: New file.
	* gdb.python/py-format-string.exp (test_max_depth): New proc.
	(test_all_common): Call test_max_depth.
	* gdb.fortran/max-depth.exp: New file.
	* gdb.fortran/max-depth.f90: New file.
	* gdb.go/max-depth.exp: New file.
	* gdb.go/max-depth.go: New file.
	* gdb.modula2/max-depth.exp: New file.
	* gdb.modula2/max-depth.c: New file.
	* lib/gdb.exp (get_print_expr_at_depths): New proc.
2019-04-29 22:01:09 +01:00
Keith Seitz 2880242dd0 Allow really large fortran array bounds: fortran type/value printers
This is the fortran part of the patch, including tests, which
are essentially unchanged from Siddhesh's original 2012 submission:

  https://sourceware.org/ml/gdb-patches/2012-08/msg00562.html

There is, however, one large departure.  In the above thread,
Jan pointed out problems with GCC debuginfo for -m32 builds
(filed usptream as gcc/54934).  After investigating the issue,
I am dropping the hand-tweaked assembler source file to workaround
this case.

While I would normally do something to accommodate this, in
this case, given the ubiquity of 64-bit systems today (where
the tests pass) and the apparent lack of urgency on the compiler
side (by users), I don't think the additional complexity and
maintenance costs are worth it. It will be very routinely tested
on 64-bit systems. [For example, at Red Hat, we always
test -m64 and -m32 configurations for all GDB releases.]

gdb/ChangeLog:

	From Siddhesh Poyarekar:
	* f-lang.h (f77_get_upperbound): Return LONGEST.
	(f77_get_lowerbound): Likewise.
	* f-typeprint.c (f_type_print_varspec_suffix): Expand
	UPPER_BOUND and LOWER_BOUND to LONGEST.  Use plongest to format
	print them.
	(f_type_print_base): Expand UPPER_BOUND to LONGEST.  Use
	plongest to format print it.
	* f-valprint.c (f77_get_lowerbound): Return LONGEST.
	(f77_get_upperbound): Likewise.
	(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
	LOWER_BOUND to LONGEST.
	(f77_create_arrayprint_offset_tbl): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.fortran/array-bounds.exp: New file.
	* gdb.fortran/array-bounds.f90: New file.
2019-03-29 10:35:19 -07:00
Andrew Burgess efbecbc143 gdb/fortran: Handle older TYPE*SIZE typenames
This patch adds support for the older TYPE*SIZE typenames that are
still around in older code.

For implementation this currently reuses the kind mechanism, as under
gFortran the kind number is equivalent to the size, however, this is
not necessarily true for all compilers.  If the rules for other
compilers are better understood then this code might need to be
improved slightly to allow for a distinction between size and kind,
however, adding this extra complexity now seems pointless.

gdb/ChangeLog:

	* f-exp.y (direct_abs_decl): Handle TYPE*SIZE type names.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp: Extend to cover TYPE*SIZE cases.
2019-03-06 18:11:31 +00:00
Andrew Burgess 0841c79a3d gdb/fortran: Add support for the ABS intrinsic function
Adds support for the abs intrinsic function, this requires adding a
new pattern to the Fortran parser.  Currently only float and integer
argument types are supported to ABS, complex is still not supported,
this can be added later if needed.

gdb/ChangeLog:

	* f-exp.y: New token, UNOP_INTRINSIC.
	(exp): New pattern using UNOP_INTRINSIC token.
	(f77_keywords): Add 'abs' keyword.
	* f-lang.c: Add 'target-float.h' and 'math.h' includes.
	(value_from_host_double): New function.
	(evaluate_subexp_f): Support UNOP_ABS.

gdb/testsuite/ChangeLog:

	* gdb.fortran/intrinsics.exp: Extend to cover ABS.
2019-03-06 18:11:31 +00:00
Andrew Burgess 4a270568d9 gdb/fortran: Use TYPE_CODE_CHAR for character types
Switch to using TYPE_CODE_CHAR for character types.  This appears to
have little impact on the test results as gFortran uses the
DW_TAG_string_type to represent all character variables (as far as I
can see).  The only place this has an impact is when the user casts a
variable to a character type, in which case GDB does now use the CHAR
type, and prints the variable as both a value and a character, for
example, before:

    (gdb) p ((character) 97)
    $1 = 97

and after:

    (gdb) p ((character) 97)
    $1 = 97 'a'

gdb/ChangeLog:

	* f-lang.c (build_fortran_types): Use TYPE_CODE_CHAR for character
	types.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp: Update expected results.
2019-03-06 18:11:31 +00:00
Andrew Burgess 067630bdb5 gdb/fortran: Add builtin 8-byte integer type with (kind=8) support
Add a new builtin type, an 8-byte integer, and allow GDB to parse
'integer (kind=8)', returning the new 8-byte integer.

gdb/ChangeLog:

	* f-exp.y (convert_to_kind_type): Handle integer (kind=8).
	* f-lang.c (build_fortran_types): Setup builtin_integer_s8.
	* f-lang.h (struct builtin_f_type): Add builtin_integer_s8 field.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp: Test new integer type kind.
2019-03-06 18:11:31 +00:00
Andrew Burgess 3be47f7aa9 gdb/fortran: Expand the set of types that support (kind=N)
Expand the number of types that can be adjusted with a (kind=N) type
extension.

gdb/ChangeLog:

	* f-exp.y (convert_to_kind_type): Handle more type kinds.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): New
	function.
	(test_basic_parsing_of_type_kinds): Expand types tested.
	(test_parsing_invalid_type_kinds): New function.
2019-03-06 18:11:31 +00:00
Andrew Burgess 4d00f5d8f6 gdb/fortran: Add Fortran 'kind' intrinsic and keyword
The 'kind' keyword has two uses in Fortran, it is the name of a
builtin intrinsic function, and it is also a keyword used to create a
type of a specific kind.

This commit adds support for using kind as an intrinsic function, and
also adds some initial support for using kind to create types of a
specific kind.

This commit only allows the creation of the type 'character(kind=1)',
however, it will be easy enough to extend this in future to support
more type kinds.

The kind of any expression can be queried using the kind intrinsic
function.  At the moment the kind returned corresponds to the size of
the type, this matches how gfortran handles kinds.  However, the
correspondence between kind and type size depends on the compiler
and/or the specific target, so this might not be correct for
everyone.  If we want to support different compilers/targets in future
the code to compute the kind from a type will need to be updated.

gdb/ChangeLog:

	* expprint.c (dump_subexp_body_standard): Support UNOP_KIND.
	* f-exp.y: Define 'KIND' token.
	(exp): New pattern for KIND expressions.
	(ptype): Handle types with a kind extension.
	(direct_abs_decl): Extend to spot kind extensions.
	(f77_keywords): Add 'kind' to the list.
	(push_kind_type): New function.
	(convert_to_kind_type): New function.
	* f-lang.c (evaluate_subexp_f): Support UNOP_KIND.
	* parse.c (operator_length_standard): Likewise.
	* parser-defs.h (enum type_pieces): Add tp_kind.
	* std-operator.def: Add UNOP_KIND.

gdb/testsuite/ChangeLog:

	* gdb.fortran/intrinsics.exp: New file.
	* gdb.fortran/intrinsics.f90: New file.
	* gdb.fortran/type-kinds.exp: New file.
2019-03-06 18:11:31 +00:00
Andrew Burgess c8f9160408 gdb/fortran: Simplify handling of Fortran dot operations and keywords
Use strncasecmp to compare Fortran dot operations (like .AND.) and for
the keywords list.  This allows for some duplication to be removed
from the token arrays.  I've also performed whitespace cleanup around
the code I've changed.

I have added some tests to ensure that upper and lowercase dot
operations are correctly tested.  The keywords list remains always
lowercase for now.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* f-exp.y (struct token): Add comments.
	(dot_ops): Remove uppercase versions and the end marker.
	(f77_keywords): Likewise.
	(yylex): Use ARRAY_SIZE to iterate over dot_ops, assert all
	entries in the dot_ops array are case insensitive, and use
	strncasecmp to compare strings.  Also some whitespace cleanup in
	this area.  Similar for the f77_keywords array, except entries in
	this list might be case sensitive.

gdb/testsuite/ChangeLog:

	* gdb.fortran/dot-ops.exp: New file.
2019-03-06 18:11:31 +00:00
Andrew Burgess dd9f2c763b gdb/fortran: Cleanup code for parsing logical constants
This patch cleans up the code used for parsing the Fortran logical
constants '.TRUE.' and '.FALSE.'.  Instead of listing both upper and
lowercase versions of these strings we now use strncasecmp.

I've also switched to use ARRAY_SIZE for the array iteration, and I've
cleaned up whitespace in the vicinity of the code I've changed.

Finally, I've added a test to ensure that both the upper and lower
case versions of the logical constants are understood by GDB,
something that was missing previously.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* f-exp.y (struct f77_boolean_val): Add comments.
	(boolean_values): Remove uppercase versions, and end marker.
	(yylex): Use ARRAY_SIZE for iterating over boolean_values array,
	and use strncasecmp to achieve case insensitivity.  Additionally,
	perform whitespace cleanup around this code.

gdb/testsuite/ChangeLog:

	* gdb.fortran/types.exp (test_logical_literal_types_accepted):
	Check upper and lower case logical literals.
2019-03-06 18:11:30 +00:00
Andrew Burgess 84ec972406 gdb/fortran: Remove some duplicate tests
Make the test names unique in gdb.fortran/types.exp by removing a few
duplicate tests.

gdb/testsuite/ChangeLog:

	* gdb.fortran/types.exp (test_float_literal_types_accepted):
	Remove duplicate tests.
2019-03-06 18:11:30 +00:00
Richard Bunt aa3cfbda2f Fortran function calls with arguments
Prior to this patch, calling functions on the inferior with arguments and
then using these arguments within a function resulted in an invalid
memory access. This is because Fortran arguments are typically passed as
pointers to values.

It is possible to call Fortran functions, but memory must be allocated in
the inferior, so a pointer can be passed to the function, and the
language must be set to C to enable C-style casting. This is cumbersome
and not a pleasant debug experience.

This patch implements the GNU Fortran argument passing conventions with
caveats. Firstly, it does not handle the VALUE attribute as there is
insufficient DWARF information to determine when this is the case.
Secondly, functions with optional parameters can only be called with all
parameters present. Both these cases are marked as KFAILS in the test.

Since the GNU Fortran argument passing convention has been implemented,
there is no guarantee that this patch will work correctly, in all cases,
with other compilers.

Despite these limitations, this patch improves the ease with which
functions can be called in many cases, without taking away the existing
approach of calling with the language set to C.

Regression tested on x86_64, aarch64 and POWER9 with GCC 7.3.0.
Regression tested with Ada on x86_64.
Regression tested with native-extended-gdbserver target board.

gdb/ChangeLog:

	* eval.c (evaluate_subexp_standard): Call Fortran argument
	wrapping logic.
	* f-lang.c (struct value): A value which can be passed into a
	Fortran function call.
	(fortran_argument_convert): Wrap Fortran arguments in a pointer
	where appropriate.
	(struct type): Value ready for a Fortran function call.
	(fortran_preserve_arg_pointer): Undo check_typedef, the pointer
	is needed.
	* f-lang.h (fortran_argument_convert): Declaration.
	(fortran_preserve_arg_pointer): Declaration.
	* infcall.c (value_arg_coerce): Call Fortran argument logic.

gdb/testsuite/ChangeLog:

	* gdb.fortran/function-calls.exp: New file.
	* gdb.fortran/function-calls.f90: New test.
2019-03-06 08:24:12 +00:00
Richard Bunt 7b63ad86ab gdbserver short-circuit-argument-list failures
This patch fixes test case failures observed when running
short-circuit-argument-list.exp with gdb server boards. Thanks to Sergio
Durigan Junior for pointing this out.

Assertions failed with the native{,-extended}-gdbserver boards as the
standard output from the test program appears in a different location
than observed on non-gdbserver boards. This standard output was used to
determine whether a function, which had been logically short-circuited,
was called or not. Since the location of the standard out cannot be
relied upon to verify this, a new mechanism was needed.

The test program now records function calls in variables named the same
as the function with a "_called" suffix. These variables can then be
queried from the test case to verify the occurrence of a call.

A method to reset the call counts has been included in the test case, so
that any future assertions added to this test can ensure a fresh set of
initial values before proceeding. Not resetting values between groups of
assertions creates a dependency between them, which increases the
likelihood that a single failure causes subsequent assertions to fail.

Regression tested on x86_64, aarch64 and ppc64le.
Regression tested with Ada on x86_64.
Regression tested with the native{,-extended}-gdbserver boards on x86_64.
2019-03-04 15:08:51 +00:00
Joel Brobecker 42a4f53d2b Update copyright year range in all GDB files.
This commit applies all changes made after running the gdb/copyright.py
script.

Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.

gdb/ChangeLog:

	Update copyright year range in all GDB files.
2019-01-01 10:01:51 +04:00
Tom de Vries 812cd6eb05 [gdb/testsuite] Fix capitalized test names
At https://sourceware.org/gdb/wiki/GDBTestcaseCookbook\
  #Follow_the_test_name_convention we find:
..
Test names should start with a lower case and don't need to end with a period
(they are not sentences).
...

Fix some capitalized test names.

Tested on x86_64-linux.

2018-10-18  Tom de Vries  <tdevries@suse.de>

	* gdb.ada/bp_inlined_func.exp: Fix capitalized test name.
	* gdb.ada/excep_handle.exp: Same.
	* gdb.ada/mi_string_access.exp: Same.
	* gdb.ada/mi_var_union.exp: Same.
	* gdb.arch/arc-analyze-prologue.exp: Same.
	* gdb.arch/arc-decode-insn.exp: Same.
	* gdb.base/readnever.exp: Same.
	* gdb.fortran/printing-types.exp: Same.
	* gdb.guile/scm-lazy-string.exp: Same.
2018-10-18 15:06:38 +02:00
Richard Bunt 23be8da739 Logical short circuiting with argument lists
When evaluating Fortran expressions such as the following:

	print truth_table(1,1) .OR. truth_table(2,1)

where truth_table(1,1) evaluates to true, the debugger would report that
it could not perform substring operations on this type. This patch
addresses this issue.

Investigation revealed that EVAL_SKIP was not being handled correctly
for all types serviced by the OP_F77_UNDETERMINED_ARGLIST case in
evaluate_subexp_standard. While skipping an undetermined argument list
the type is resolved to be an integer (as this is what evaluate_subexp
returns when skipping) and so it was not possible to delegate to the
appropriate case (e.g. array, function call).

The solution implemented here updates OP_VAR_VALUE to return correct
type information when skipping. This way OP_F77_UNDETERMINED_ARGLIST
can delegate the skipping to the appropriate case or routine, which
should know how to skip/evaluate the type in question.

koenig.exp was updated to include a testcase which exercises the
modified skip logic in OP_VAR_VALUE, as it falls through from
OP_ADL_FUNC.

This patch has been tested for regressions with GCC 7.3 on aarch64,
ppc64le and x86_64.

gdb/ChangeLog:

	* eval.c (skip_undetermined_arglist): Skip argument list helper.
	(evaluate_subexp_standard): Return a dummy type when
	honoring EVAL_SKIP in OP_VAR_VALUE and handle skipping in the
	OP_F77_UNDETERMINED_ARGLIST case.
	* expression.h (enum noside): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.cp/koenig.exp: Extend to test logical short circuiting.
	* gdb.fortran/short-circuit-argument-list.exp: New file.
	* gdb.fortran/short-circuit-argument-list.f90: New test.
2018-09-19 10:43:56 +01:00
Simon Marchi 045cf01286 Fix gdb.fortran/nested-funcs.exp failure
Commit 87d6a7aa93 ("Add DWARF index cache") broke
gdb.fortran/nested-funcs.exp.  Because of the new "set index-cache"
command, the expression "set index = 42" now fails:

  set index = 42
  Undefined set index-cache command: "= 42".  Try "help set index-cache".
  (gdb) PASS: gdb.fortran/nested-funcs.exp: set index = 42

Fix it by changing it to "set variable index = 42".  Also, use
gdb_test_no_output to confirm that it worked (since that particular test
wrongfully passed).

gdb/testsuite/ChangeLog:

	* gdb.fortran/nested-funcs.exp: Replace "set index = 42" with
	"set variable index = 42".
2018-08-07 22:46:37 -04:00
Joel Brobecker e2882c8578 Update copyright year range in all GDB files
gdb/ChangeLog:

        Update copyright year range in all GDB files
2018-01-02 07:38:06 +04:00
Yao Qi 1cc75e929f Replace mail address with the URL in copyright header
The copyright header in most of GDB files were changed from mail address
to the URL in the conversion to GPLv3 in Aug 2007.  However, some files
still use mail address instead of the URL.  This patch fixes them.

gdb/testsuite:

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

	* gdb.arch/aarch64-atomic-inst.exp: Replace mail address with
	the URL in copyright header.
	* gdb.arch/aarch64-fp.exp: Likewise.
	* gdb.arch/ppc64-atomic-inst.exp: Likewise.
	* gdb.arch/ppc64-isa207-atomic-inst.exp: Likewise.
	* gdb.base/expand-psymtabs.exp: Likewise.
	* gdb.cp/expand-psymtabs-cxx.exp: Likewise.
	* gdb.fortran/common-block.exp: Likewise.
	* gdb.fortran/common-block.f90: Likewise.
	* gdb.fortran/logical.exp: Likewise.
	* gdb.fortran/vla-datatypes.f90: Likewise.
	* gdb.fortran/vla-sub.f90: Likewise.
2017-12-01 11:34:14 +00:00
Christoph Weinmann 469412dd9c Remove C/C++ relevant code in Fortran specific file.
Remove code relevant for printing C/C++ Integer values in a
Fortran specific file to unify printing of Fortran values.
This does not change the output.
2017-09-08 15:11:47 +02:00