This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Debugging offload compiler ICEs


On Tue, May 3, 2016 at 12:47 PM, Thomas Schwinge
<thomas@codesourcery.com> wrote:
> 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]").

Does -v -save-temps not provide enough info to re-launch the lto1 process?

Richard.

> --- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]