[PATCH] Enable Access to containing scope variables from nested inlined function
Sharma, Alok Kumar
AlokKumar.Sharma@amd.com
Mon Aug 29 11:23:41 GMT 2022
[Public]
Gentle Reminder - 4 !!!
Hi Andrew, Tom,
May I request you to have a look at it ?
Regards,
Alok
-----Original Message-----
From: Sharma, Alok Kumar
Sent: Monday, August 15, 2022 3:16 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 - 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
More information about the Gdb-patches
mailing list