From 20f5840cbb89e7a7673e3b0208983652ea2c861e Mon Sep 17 00:00:00 2001 From: James Clark Date: Fri, 15 Feb 2019 15:20:15 +0000 Subject: [PATCH] Add a compilation flag that adds unwind info to all files that are present in the stack starting from MPI_Init. This is so when a debugger attaches using MPIR, it can step out of this stack back into main. This cannot be done with certain aggressive optimisations and missing debug information. Signed-off-by: James Clark Signed-off-by: Jeff Squyres Co-authored-by: Jeff Squyres --- config/orte_setup_debugger_flags.m4 | 42 ++++++++++++++++++++++++++++- ompi/runtime/Makefile.am | 11 +++++++- orte/mca/ess/Makefile.am | 4 +++ orte/mca/ess/pmi/Makefile.am | 6 +++++ orte/runtime/Makefile.am | 10 ++++++- 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/config/orte_setup_debugger_flags.m4 b/config/orte_setup_debugger_flags.m4 index 39ac77defe..5bd970bf7d 100644 --- a/config/orte_setup_debugger_flags.m4 +++ b/config/orte_setup_debugger_flags.m4 @@ -10,7 +10,7 @@ dnl Copyright (c) 2004-2007 High Performance Computing Center Stuttgart, dnl University of Stuttgart. All rights reserved. dnl Copyright (c) 2004-2005 The Regents of the University of California. dnl All rights reserved. -dnl Copyright (c) 2006-2009 Cisco Systems, Inc. All rights reserved. +dnl Copyright (c) 2006-2019 Cisco Systems, Inc. All rights reserved. dnl Copyright (c) 2006-2009 Sun Microsystems, Inc. All rights reserved. dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights dnl reserved. @@ -24,6 +24,28 @@ dnl dnl $HEADER$ dnl +dnl Check to see if specific CFLAGS work +dnl $1: compiler flags to check +dnl $2: Action if the flags work +dnl $3: Action if the flags do not work +AC_DEFUN([_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS],[ + OPAL_VAR_SCOPE_PUSH([ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save]) + + ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save=$CFLAGS + AC_MSG_CHECKING([if $1 compiler flag works]) + CFLAGS="$CFLAGS $1" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[int i = 3;])], + [ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=yes], + [ORTE_SETUP_DEBUGGER_FLAGS_HAPPY=no]) + AC_MSG_RESULT([$ORTE_SETUP_DEBUGGER_FLAGS_HAPPY]) + CFLAGS=$ORTE_SETUP_DEBUGGER_FLAGS_CFLAGS_save + + OPAL_VAR_SCOPE_POP + + AS_IF([test $ORTE_SETUP_DEBUGGER_FLAGS_HAPPY = yes], + [$2], [$3]) +]) + AC_DEFUN([ORTE_SETUP_DEBUGGER_FLAGS],[ # # Do a final process of the CFLAGS to make a WITHOUT_OPTFLAGS @@ -53,4 +75,22 @@ AC_DEFUN([ORTE_SETUP_DEBUGGER_FLAGS],[ AC_SUBST(CFLAGS_WITHOUT_OPTFLAGS) AC_SUBST(DEBUGGER_CFLAGS) + + # Check for compiler specific flag to add in unwind information. + # This is needed when attaching using MPIR to unwind back to the + # user's main function. Certain optimisations can prevent GDB from + # producing a stack when explicit unwind information is unavailable. + # This is implied by -g, but we want to save space and don't need + # full debug symbols. + _ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-fasynchronous-unwind-tables], + [MPIR_UNWIND_CFLAGS="-fasynchronous-unwind-tables"], + [_ORTE_SETUP_DEBUGGER_FLAGS_TRY_CFLAGS([-Meh_frame -Mframe], + [MPIR_UNWIND_CFLAGS="-Meh_frame -Mframe"], + [MPIR_UNWIND_CFLAGS=-g]) + ]) + + AC_MSG_CHECKING([for final compiler unwind flags]) + AC_MSG_RESULT([$MPIR_UNWIND_CFLAGS]) + + AC_SUBST(MPIR_UNWIND_CFLAGS) ]) diff --git a/ompi/runtime/Makefile.am b/ompi/runtime/Makefile.am index 98cc400a83..71b32e2139 100644 --- a/ompi/runtime/Makefile.am +++ b/ompi/runtime/Makefile.am @@ -33,10 +33,19 @@ headers += \ lib@OMPI_LIBMPI_NAME@_la_SOURCES += \ runtime/ompi_mpi_abort.c \ runtime/ompi_mpi_dynamics.c \ - runtime/ompi_mpi_init.c \ runtime/ompi_mpi_finalize.c \ runtime/ompi_mpi_params.c \ runtime/ompi_mpi_preconnect.c \ runtime/ompi_cr.c \ runtime/ompi_info_support.c \ runtime/ompi_spc.c + +# The MPIR portion of the library must be built with flags to +# enable stepping out of MPI_INIT into main. +# Use an intermediate library to isolate the debug object. +noinst_LTLIBRARIES += libompi_mpir.la +libompi_mpir_la_SOURCES = \ + runtime/ompi_mpi_init.c +libompi_mpir_la_CFLAGS = $(MPIR_UNWIND_CFLAGS) + +lib@OMPI_LIBMPI_NAME@_la_LIBADD += libompi_mpir.la diff --git a/orte/mca/ess/Makefile.am b/orte/mca/ess/Makefile.am index 2135443231..3edc397d32 100644 --- a/orte/mca/ess/Makefile.am +++ b/orte/mca/ess/Makefile.am @@ -19,6 +19,10 @@ AM_CPPFLAGS = $(LTDLINCL) +# Add unwind flags because files in this tree are +# involved in startup. +AM_CFLAGS = $(MPIR_UNWIND_CFLAGS) + # main library setup noinst_LTLIBRARIES = libmca_ess.la libmca_ess_la_SOURCES = diff --git a/orte/mca/ess/pmi/Makefile.am b/orte/mca/ess/pmi/Makefile.am index 3d53270285..15d38a0817 100644 --- a/orte/mca/ess/pmi/Makefile.am +++ b/orte/mca/ess/pmi/Makefile.am @@ -11,6 +11,12 @@ # $HEADER$ # +# Add MPIR unwind flags because files in this tree are +# involved in startup. This is not needed in the other +# subdirs in orte/mca/ess because the other components are +# solely used by daemons and thus are not accessible by the debugger. +AM_CFLAGS = $(MPIR_UNWIND_CFLAGS) + AM_CPPFLAGS = $(ess_pmi_CPPFLAGS) sources = \ diff --git a/orte/runtime/Makefile.am b/orte/runtime/Makefile.am index 4081e26923..a8defbf8eb 100644 --- a/orte/runtime/Makefile.am +++ b/orte/runtime/Makefile.am @@ -38,7 +38,6 @@ headers += \ lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \ runtime/orte_finalize.c \ - runtime/orte_init.c \ runtime/orte_locks.c \ runtime/orte_globals.c \ runtime/orte_quit.c \ @@ -52,3 +51,12 @@ lib@ORTE_LIB_PREFIX@open_rte_la_SOURCES += \ runtime/orte_cr.c \ runtime/orte_data_server.c \ runtime/orte_info_support.c + +# The MPIR portion of the library must be built with flags to +# enable stepping out of MPI_INIT into main. +# Use an intermediate library to isolate the debug object. +noinst_LTLIBRARIES += libruntime_mpir.la +libruntime_mpir_la_SOURCES = \ + runtime/orte_init.c +libruntime_mpir_la_CFLAGS = $(MPIR_UNWIND_CFLAGS) +lib@ORTE_LIB_PREFIX@open_rte_la_LIBADD += libruntime_mpir.la