Debugging offload compiler ICEs

Thomas Schwinge thomas@codesourcery.com
Tue May 3 10:48:00 GMT 2016


Hi!

It is currently difficult to debug offloading compiler invocations.
These are actually lto1 front ends invoked from the target compilation's
collect2 process, via the respective offloading toolchain's mkoffload.
To the best of my knowledge, it's not possible to use the target
compiler's "-wrapper" option to have GDB step into an offloading
compilation's mkoffload/lto1, or if it is (GDB follow-fork-mode "child"
maybe?), then it's very cumbersome.

A while ago, I came up with the following hack to make the (offloading)
compiler pause if an ICE is hit.  This will then result in a message on
stderr (that is, in the current offloading compilation's /tmp/cc*.le
file...), about which PID to attach to ("gdb -p [PID]").

--- gcc/diagnostic.c
+++ gcc/diagnostic.c
@@ -40,6 +40,16 @@ along with GCC; see the file COPYING3.  If not see
 # include <sys/ioctl.h>
 #endif
 
+#include <sys/prctl.h>
+void wait_for_debugger()
+{
+  // In case that Yama LSM is enabled in mode 1 ("restricted ptrace").
+  prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
+  fprintf(stderr, "Attach debugger to pid %d\n", getpid());
+  while (pause() == EINTR)
+    ;
+}
+
 #define pedantic_warning_kind(DC)			\
   ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
@@ -486,6 +496,8 @@ diagnostic_action_after_output (diagnostic_context *context,
 		    "with any bug report.\n"));
 	fnotice (stderr, "See %s for instructions.\n", bug_report_url);
 
+	wait_for_debugger();
+
 	exit (ICE_EXIT_CODE);
       }
 

Posting this here (and will add a link to the Offloading wiki page) just
in case this is useful for others, too.


Grüße
 Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20160503/0744819a/attachment.sig>


More information about the Gcc mailing list