public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Sharma, Alok Kumar" <AlokKumar.Sharma@amd.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: "George, Jini Susan" <JiniSusan.George@amd.com>
Subject: RE: [PATCH] Enable Access to containing scope variables from nested inlined function
Date: Mon, 15 Aug 2022 09:45:38 +0000	[thread overview]
Message-ID: <CO6PR12MB54910CA2624FFF765D55E1169E689@CO6PR12MB5491.namprd12.prod.outlook.com> (raw)
In-Reply-To: <CO6PR12MB5491366232A784889D6975D89E609@CO6PR12MB5491.namprd12.prod.outlook.com>

[Public]

Gentle Reminder - 3 !!!

Regards,
Alok

-----Original Message-----
From: Sharma, Alok Kumar 
Sent: Sunday, August 7, 2022 8:35 PM
To: 'gdb-patches@sourceware.org' <gdb-patches@sourceware.org>
Cc: George, Jini Susan <JiniSusan.George@amd.com>
Subject: RE: [PATCH] Enable Access to containing scope variables from nested inlined function

[Public]

Gentle Reminder - 2 !!!

Regards,
Alok

-----Original Message-----
From: Sharma, Alok Kumar 
Sent: Monday, August 1, 2022 11:27 AM
To: 'gdb-patches@sourceware.org' <gdb-patches@sourceware.org>
Cc: George, Jini Susan <JiniSusan.George@amd.com>
Subject: RE: [PATCH] Enable Access to containing scope variables from nested inlined function

[Public]

Gentle Reminder -1 !!!

Regards,
Alok

-----Original Message-----
From: Sharma, Alok Kumar 
Sent: Sunday, July 24, 2022 11:46 PM
To: gdb-patches@sourceware.org
Cc: George, Jini Susan <JiniSusan.George@amd.com>
Subject: [PATCH] Enable Access to containing scope variables from nested inlined function

[Public]

Hi all,

Currently inlined functions are barred from accessing any containing local scope variable, which makes sense for global scoped functions.

The gcc compiler supports nested (local scoped) function for end user, the Clang compiler does not allow nested function for end user but compiler itself generates such artificial functions internally ( in case of Openmp). General barrier by gdb reduces debug experience, current patch enhances debugging in such cases.

Please consider below program
---------------------
     1  #include <stdio.h>
     2
     3  __attribute__((always_inline)) inline int outer_fun (int arg) {
     4    // Inlined at (A) or not, this function should not have access to
     5    // variables caller_fun_var, caller_fun_other_var in non containing
     6    // scoped function caller_fun.
     7    int outer_local = 5;
     8    outer_local = arg;
     9    printf("Value of outer_local = %d\n", outer_local);
    10  }
    11
    12  void caller_fun() {
    13    static int caller_fun_var = 9;
    14    volatile int caller_fun_other_var = 7;
    15    __attribute__((always_inline)) inline void called_fun (int arg) {
    16      // Inlined at (B) or not, this function should have access to
    17    // containing scope variables caller_fun_var, caller_fun_other_var
    18      int local = 0;
    19      local = arg;
    20      printf("Value of local = %d\n", local);
    21    }
    22
    23    outer_fun(caller_fun_other_var);  // <--- (A)
    24    called_fun(caller_fun_other_var); // <--- (B)
    25    return;
    26  }
    27
    28  int main() {
    29    caller_fun();
    30    return 0;
    31  }
-----------------------
Which produces DWARF as below
-----------------------
0x00000094:   DW_TAG_subprogram
                DW_AT_name      ("main")
0x000000b2:   DW_TAG_subprogram
                DW_AT_name      ("caller_fun")
0x000000d0:     DW_TAG_variable
                  DW_AT_name    ("caller_fun_var")
0x000000dd:     DW_TAG_variable
                  DW_AT_name    ("caller_fun_other_var")
0x000000ec:     DW_TAG_subprogram
                  DW_AT_name    ("called_fun")
0x00000112:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin (0x00000169 "outer_fun")
0x0000013f:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin (0x000000ec "called_fun")
0x00000169:   DW_TAG_subprogram
                DW_AT_external  (true)
                DW_AT_name      ("outer_fun")
-----------------------
Please note concrete instances of abstract functions "called_fun" (0x000000ec) and "outer_fun" (0x00000169) are DIE:0x00000112 and DIE:0x0000013f. Both have DWARF tag DW_TAG_inlined_subroutine.
To stop "outer_fun" (0x00000112) from accessing scope of "caller_fun", gdb generalize barrier for DW_TAG_inlined_subroutine.
GDB should instead check DW_AT_abstract_origin attribute to check actual scope of corresponding abstract functions and allow "called_fun" to access scope of "caller_fun".

Current patch stores this information into data structure DIE_BLOCK and uses that to compute actual containing scope.

Please review the patch and let me know your comments.

Regards,
Alok

  reply	other threads:[~2022-08-15  9:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-24 18:16 Sharma, Alok Kumar
2022-08-01  5:56 ` Sharma, Alok Kumar
2022-08-07 15:05   ` Sharma, Alok Kumar
2022-08-15  9:45     ` Sharma, Alok Kumar [this message]
2022-08-29 11:23       ` Sharma, Alok Kumar
2022-09-12  5:21         ` Sharma, Alok Kumar
2022-09-21  7:08           ` Sharma, Alok Kumar
2022-10-11 14:24             ` Sharma, Alok Kumar
2022-10-14 19:26 ` 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=CO6PR12MB54910CA2624FFF765D55E1169E689@CO6PR12MB5491.namprd12.prod.outlook.com \
    --to=alokkumar.sharma@amd.com \
    --cc=JiniSusan.George@amd.com \
    --cc=gdb-patches@sourceware.org \
    /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).