diff mbox series

[committed,OG10] Fix offload dwarf info

Message ID 76859c2d-ae26-ac85-ff8a-bea712909d62@codesourcery.com
State New
Headers show
Series [committed,OG10] Fix offload dwarf info | expand

Commit Message

Andrew Stubbs Jan. 15, 2021, 11:43 a.m. UTC
This patch corrects a problem in which GDB ignores the debug info for 
offload kernel entry functions because they're represented as nested 
functions inside a function that does not exist on the accelerator 
device (only on the host).

The fix is to add a notional code range to the non-existent parent 
function. Setting it the same as the inner function is good enough 
because GDB selects the innermost.

I'll submit this the mainline when stage 1 opens. Committed to 
devel/omp/gcc-10 for now.

Andrew

Comments

Andrew Stubbs Jan. 16, 2021, 3:53 p.m. UTC | #1
On 15/01/2021 11:43, Andrew Stubbs wrote:
> This patch corrects a problem in which GDB ignores the debug info for 
> offload kernel entry functions because they're represented as nested 
> functions inside a function that does not exist on the accelerator 
> device (only on the host).

Apparently I had a bug in this patch that only showed up after another 
clean build (not sure what was different).

This patch fixes it. Apparently the flag_generate_offload was wrong.

Committed to OG10. I will squash the two patches when they go to mainline.

Andrew
diff mbox series

Patch

Fix offload dwarf info

Add a notional code range to the notional parent function of offload kernel
functions.  This is enough to prevent GDB discarding them.

gcc/ChangeLog:

	* dwarf2out.c (gen_subprogram_die): Add high/low_pc attributes for
	parents of offload kernels.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 4d84a9e9607..a4a1b934dc7 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -23079,6 +23079,20 @@  gen_subprogram_die (tree decl, dw_die_ref context_die)
 	      /* We have already generated the labels.  */
              add_AT_low_high_pc (subr_die, fde->dw_fde_begin,
                                  fde->dw_fde_end, false);
+
+	     /* Offload kernel functions are nested within a parent function
+	        that doesn't actually exist within the offload object.  GDB
+		will ignore the function and everything nested within unless
+		we give it a notional code range (the values aren't
+		important, as long as they are valid).  */
+	     if (flag_generate_offload
+		 && lookup_attribute ("omp target entrypoint",
+				      DECL_ATTRIBUTES (decl))
+		 && subr_die->die_parent
+		 && subr_die->die_parent->die_tag == DW_TAG_subprogram
+		 && !get_AT_low_pc (subr_die->die_parent))
+	       add_AT_low_high_pc (subr_die->die_parent, fde->dw_fde_begin,
+				   fde->dw_fde_end, false);
 	    }
 	  else
 	    {