root/ompi/debuggers/ompi_debuggers.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. check
  2. ompi_debugger_setup_dlls

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2008 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007-2016 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
  15  *                         reserved.
  16  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 /*
  25  * MPI portion of debugger support: initially based on the
  26  * TotalView/Etnus API for debuggers to attach to MPI jobs.
  27  *
  28  * There is a lengthy explanation of how OMPI handles parallel
  29  * debuggers attaching to MPI jobs in orte/tools/orterun/debuggers.c.
  30  */
  31 
  32 #include "ompi_config.h"
  33 
  34 #ifdef HAVE_UNISTD_H
  35 #include <unistd.h>
  36 #endif  /* HAVE_UNISTD_H */
  37 #ifdef HAVE_DIRENT_H
  38 #include <dirent.h>
  39 #endif
  40 #ifdef HAVE_SYS_TYPES_H
  41 #include <sys/types.h>
  42 #endif
  43 #ifdef HAVE_SYS_STAT_H
  44 #include <sys/stat.h>
  45 #endif
  46 #ifdef HAVE_UNISTD_H
  47 #include <unistd.h>
  48 #endif
  49 
  50 #include "opal/mca/base/base.h"
  51 #include "opal/util/argv.h"
  52 #include "opal/util/printf.h"
  53 #include "opal/mca/installdirs/installdirs.h"
  54 #include "debuggers.h"
  55 #include "ompi/mca/rte/rte.h"
  56 /**
  57  * BEWARE: The following headers are required by optimized builds in order
  58  * to get access to the type information. Some compilers remove all type
  59  * information on optimized build, and as a result we are unable to access
  60  * the fields structure (i.e. to get their displacement). This file is
  61  * included in the optimized build just to provide us with this missing
  62  * informations. Therefore, it always have to be compiled with the -g flag,
  63  * otherwise the type information will be missing and the parallel
  64  * debuggers will be unable to initialize the Open MPI debug library.
  65  */
  66 #include "opal/class/opal_list.h"
  67 #include "opal/class/opal_free_list.h"
  68 #include "ompi/request/request.h"
  69 #include "ompi/mca/pml/base/pml_base_request.h"
  70 #include "ompi/mca/pml/base/pml_base_sendreq.h"
  71 #include "ompi/mca/pml/base/pml_base_recvreq.h"
  72 #include "opal/class/opal_pointer_array.h"
  73 #include "ompi/communicator/communicator.h"
  74 #include "ompi/mca/topo/topo.h"
  75 #include "ompi/group/group.h"
  76 #include "opal/datatype/opal_datatype.h"
  77 #include "ompi/datatype/ompi_datatype.h"
  78 #include "ompi/include/mpi.h"
  79 
  80 #if defined(OMPI_MSGQ_DLL)
  81 /* This variable is old/deprecated -- the mpimsgq_dll_locations[]
  82    method is preferred because it's more flexible */
  83 OMPI_DECLSPEC char MPIR_dll_name[] = OMPI_MSGQ_DLL;
  84 #endif  /* defined(OMPI_MSGQ_DLL) */
  85 OMPI_DECLSPEC char **mpidbg_dll_locations = NULL;
  86 OMPI_DECLSPEC char **mpimsgq_dll_locations = NULL;
  87 
  88 OMPI_DECLSPEC int MPIR_debug_typedefs_sizeof[] = {
  89     sizeof(short),
  90     sizeof(int),
  91     sizeof(long),
  92     sizeof(long long),
  93     sizeof(void*),
  94     sizeof(bool),
  95     sizeof(size_t)
  96 };
  97 
  98 /*
  99  * Values defined by the standardized interface; do not change these
 100  * values
 101  */
 102 #define MPIR_DEBUG_SPAWNED   1
 103 #define MPIR_DEBUG_ABORTING  2
 104 
 105 /**
 106  * BEWARE: Try to outsmart some compilers. In some cases, when variables
 107  * are defined but not used, some compilers will optimized them out from
 108  * the build. As we need to be able to access the structure sizes from the
 109  * debugged program (in the case where the MPI library and the application
 110  * is compiled with a different architecture flag than the parallel
 111  * debugger, 32 vs. 64 bits), we have to have these variables defined.
 112  */
 113 OMPI_DECLSPEC opal_list_item_t* opal_list_item_t_type_force_inclusion = NULL;
 114 OMPI_DECLSPEC opal_list_t* opal_list_t_type_force_inclusion = NULL;
 115 OMPI_DECLSPEC opal_free_list_item_t* opal_free_list_item_t_type_force_inclusion = NULL;
 116 OMPI_DECLSPEC opal_free_list_t* opal_free_list_t_type_force_inclusion = NULL;
 117 OMPI_DECLSPEC ompi_request_t* ompi_request_t_type_force_inclusion = NULL;
 118 OMPI_DECLSPEC mca_pml_base_request_t* mca_pml_base_request_t_type_force_inclusion = NULL;
 119 OMPI_DECLSPEC mca_pml_base_send_request_t* mca_pml_base_send_request_t_type_force_inclusion = NULL;
 120 OMPI_DECLSPEC mca_pml_base_recv_request_t* mca_pml_base_recv_request_t_type_force_inclusion = NULL;
 121 OMPI_DECLSPEC opal_pointer_array_t* opal_pointer_array_t_type_force_inclusion = NULL;
 122 OMPI_DECLSPEC ompi_communicator_t* ompi_communicator_t_type_force_inclusion = NULL;
 123 OMPI_DECLSPEC ompi_group_t* ompi_group_t_type_force_inclusion = NULL;
 124 OMPI_DECLSPEC ompi_status_public_t* ompi_status_public_t_type_force_inclusion = NULL;
 125 OMPI_DECLSPEC opal_datatype_t* opal_datatype_t_type_force_inclusion = NULL;
 126 OMPI_DECLSPEC ompi_datatype_t* ompi_datatype_t_type_force_inclusion = NULL;
 127 
 128 OMPI_DECLSPEC volatile int MPIR_debug_gate = 0;
 129 
 130 static char *ompi_debugger_dll_path = NULL;
 131 
 132 /* Check for a file in few direct ways for portability */
 133 static void check(char *dir, char *file, char **locations)
 134 {
 135     char *str;
 136 
 137     opal_asprintf(&str, "%s/%s.so", dir, file);
 138 
 139 #if defined(HAVE_SYS_STAT_H)
 140     {
 141         struct stat buf;
 142 
 143         /* Use stat() */
 144         if (0 == stat(str, &buf)) {
 145             opal_argv_append_nosize(&locations, file);
 146         }
 147     }
 148 #else
 149     {
 150         FILE *fp;
 151 
 152         /* Just try to open the file */
 153         if (NULL != (fp = fopen(str, "r"))) {
 154             fclose(fp);
 155             opal_argv_append_nosize(&locations, file);
 156         }
 157     }
 158 #endif /* defined(HAVE_SYS_STAT_H) */
 159 
 160     free(str);
 161 }
 162 
 163 
 164 extern void
 165 ompi_debugger_setup_dlls(void)
 166 {
 167     int i;
 168     char **dirs, **tmp1 = NULL, **tmp2 = NULL;
 169 
 170     ompi_debugger_dll_path = opal_install_dirs.opallibdir;
 171     (void) mca_base_var_register("ompi", "ompi", "debugger", "dll_path",
 172                                  "List of directories where MPI_INIT should search for debugger plugins",
 173                                  MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
 174                                  OPAL_INFO_LVL_9,
 175                                  MCA_BASE_VAR_SCOPE_READONLY,
 176                                  &ompi_debugger_dll_path);
 177 
 178     /* Search the directory for MPI debugger DLLs */
 179     if (NULL != ompi_debugger_dll_path) {
 180         dirs = opal_argv_split(ompi_debugger_dll_path, ':');
 181         for (i = 0; dirs[i] != NULL; ++i) {
 182             check(dirs[i], OMPI_MPIHANDLES_DLL_PREFIX, tmp1);
 183             check(dirs[i], OMPI_MSGQ_DLL_PREFIX, tmp2);
 184         }
 185         opal_argv_free(dirs);
 186     }
 187 
 188     /* Now that we have a full list of directories, assign the argv
 189        arrays to the global variables (since the debugger may read the
 190        global variables at any time, we want to ensure that they have
 191        non-NULL values only when the entire array is ready). */
 192     mpimsgq_dll_locations = tmp1;
 193     mpidbg_dll_locations = tmp2;
 194 }

/* [<][>][^][v][top][bottom][index][help] */