public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Kempke, Nils-Christian" <nils-christian.kempke@intel.com>
To: Tom Tromey <tom@tromey.com>,
	Nils-Christian Kempke via Gdb-patches
	<gdb-patches@sourceware.org>
Subject: RE: [PATCH 1/2][PR fortran/26373][PR fortran/22497] gdb/fortran: add support for accessing fields of extended types
Date: Mon, 17 Jan 2022 10:28:04 +0000	[thread overview]
Message-ID: <BYAPR11MB32886EEBB69DA29B41FE90F3B8579@BYAPR11MB3288.namprd11.prod.outlook.com> (raw)
In-Reply-To: <87h7a6f5fu.fsf@tromey.com>

Hi Tom,

> -----Original Message-----
> From: Tom Tromey <tom@tromey.com>
> Sent: Friday, January 14, 2022 9:06 PM
> To: Nils-Christian Kempke via Gdb-patches <gdb-patches@sourceware.org>
> Cc: Kempke, Nils-Christian <nils-christian.kempke@intel.com>; Bernhard
> Heckel <bernhard.heckel@intel.com>
> Subject: Re: [PATCH 1/2][PR fortran/26373][PR fortran/22497] gdb/fortran:
> add support for accessing fields of extended types
> 
> >>>>> ">" == Nils-Christian Kempke via Gdb-patches <gdb-
> patches@sourceware.org> writes:
> 
> >> From: Bernhard Heckel <bernhard.heckel@intel.com>
> >> Fortran 2003 supports type extension.  This patch allows access
> >> to inherited members by using their fully qualified name as described
> >> in the Fortran standard.
> 
> Thanks for the patch.
> 
> >> In doing so the patch also fixes a bug in GDB when trying to access the
> >> members of a base class in a derived class via the derived class' base
> >> class member.
> 
> >> @@ -2374,6 +2374,12 @@ value_struct_elt (struct value **argp,
> >>        if (v)
> >>  	return v;
> 
> >> +      /* Fortran: If it is not a field it is the type name of an inherited
> >> +	 structure.  */
> >> +      v = search_struct_field (name, *argp, t, 1);
> >> +      if (v)
> >> +	return v;
> 
> Putting this here makes me wonder if it's possible to construct test
> cases in other languages that would work without this patch and then
> fail with it.

Well, since this patch so far did not care about the language actually used,
it enables one to do things like

  (gdb) p derived_obj
  $1 = {<base> = {...}, <No data fields>}
  (gdb) p derived_obj.base
  $2 = {...}

in all languages, which probably is unexpected.  The above example would be
C++ and some class "derived" inheriting from "base".  The syntax
derived_obj.base is no standard C++..
I am not sure whether one would actually break things since the only leftover
check in the method is a (according to the comment) C++ specific one for
member variables and I do not think that one can break C++ with the change.

> 
> I'm not sure what the options are though.  Doing the work elsewhere, say
> in a custom Fortran expression operation, might make the Python API
> harder to work with.  Maybe having value_struct_elt check
> current_language would work... that's also quite ugly but other value
> operations are doing that.

Mh, I am not too sure about the Fortran expression - would that not require
a Fortran specific version of value_struct_elt?  The methods
search_struct_method and search_struct_field are local to the valops.c file so
this would be a bigger redesign? I know that Ada has its own value_struct_elt
but it also implements the two helper methods.

Checking the language seems ok to me, considering the style of the rest of valops.

On more option that is also cleaner than directly checking the type might be to
generalize the concept of this "member access by base name" a bit and add a
method - say base_access_by_base_type_name - to language.h allowing or
disallowing an access to the base type by its type name.  Then one would have to
loop over all base types in valops.c as well.  I am not sure whether there exist other
languages that allow this kind of access though.. If not it might be a bit much?
 
Cheers,

Nils

> 
> Or maybe my fears are overblown.
> 
> Any thoughts on this?
> 
> Tom
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  reply	other threads:[~2022-01-17 10:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 16:39 [PATCH 0/2][PR fortran/26373][PR fortran/22497] GDB support for Fortran extends feature Nils-Christian Kempke
2022-01-13 16:39 ` [PATCH 1/2][PR fortran/26373][PR fortran/22497] gdb/fortran: add support for accessing fields of extended types Nils-Christian Kempke
2022-01-14 20:06   ` Tom Tromey
2022-01-17 10:28     ` Kempke, Nils-Christian [this message]
2022-02-01 15:06       ` Kempke, Nils-Christian
2022-02-10 13:20         ` Kempke, Nils-Christian
2022-02-18 16:14           ` Kempke, Nils-Christian
2022-01-13 16:39 ` [PATCH 2/2] gdb/fortran: print fortran extended types with ptype Nils-Christian Kempke
2022-01-14 20:10   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BYAPR11MB32886EEBB69DA29B41FE90F3B8579@BYAPR11MB3288.namprd11.prod.outlook.com \
    --to=nils-christian.kempke@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).