📄 totalview.c
字号:
/* -*- C -*- * * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2007 Los Alamos National Security, LLC. All rights * reserved. * Copyright (c) 2007 Cisco, Inc. All rights reserved. * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */#include "orte_config.h"/* * Debugger support for orterun * * We interpret the MPICH debugger interface as follows: * * a) The launcher * - spawns the other processes, * - fills in the table MPIR_proctable, and sets MPIR_proctable_size * - sets MPIR_debug_state to MPIR_DEBUG_SPAWNED ( = 1) * - calls MPIR_Breakpoint() which the debugger will have a * breakpoint on. * * b) Applications start and then spin until MPIR_debug_gate is set * non-zero by the debugger. * * This file implements (a). */#include <stdio.h>#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif /* HAVE_STDLIB_H */#ifdef HAVE_STRINGS_H#include <strings.h>#endif /* HAVE_STRINGS_H */#ifdef HAVE_UNISTD_H#include <unistd.h>#endif /* HAVE_UNISTD_H */#include <ctype.h>#include "opal/util/opal_environ.h"#include "opal/util/output.h"#include "opal/util/argv.h"#include "opal/util/show_help.h"#include "opal/util/path.h"#include "opal/util/os_path.h"#include "opal/class/opal_list.h"#include "opal/mca/base/base.h"#include "orte/mca/errmgr/errmgr.h"#include "orte/mca/rmgr/rmgr_types.h"#include "orte/mca/rmaps/rmaps.h"#include "orte/runtime/runtime.h"#include "orterun.h"#include "orterun.h"#include "totalview.h"/* +++ begin MPICH/TotalView interface definitions */#define MPIR_DEBUG_SPAWNED 1#define MPIR_DEBUG_ABORTING 2struct MPIR_PROCDESC { char *host_name; /* something that can be passed to inet_addr */ char *executable_name; /* name of binary */ int pid; /* process pid */};ORTE_DECLSPEC struct MPIR_PROCDESC *MPIR_proctable = NULL;ORTE_DECLSPEC int MPIR_proctable_size = 0;ORTE_DECLSPEC int MPIR_being_debugged = 0;ORTE_DECLSPEC int MPIR_force_to_main = 0;ORTE_DECLSPEC volatile int MPIR_debug_state = 0;ORTE_DECLSPEC volatile int MPIR_i_am_starter = 0;ORTE_DECLSPEC volatile int MPIR_debug_gate = 0;ORTE_DECLSPEC volatile int MPIR_acquired_pre_main = 0;/* --- end MPICH/TotalView interface definitions *//* * NOTE: The job description in the registry will likely evolve to use * the "jobgrp_t", but this works for now. * * An initial skeleton of how to implement this with jobgrp_t is * available in SVN as orte/tools/orterun/totalview.c, version 7075. */#define DUMP_INT(X) fprintf(stderr, " %s = %d\n", # X, X);static void dump(void){ int i; DUMP_INT(MPIR_being_debugged); DUMP_INT(MPIR_debug_gate); DUMP_INT(MPIR_debug_state); DUMP_INT(MPIR_acquired_pre_main); DUMP_INT(MPIR_i_am_starter); DUMP_INT(MPIR_proctable_size); fprintf(stderr, " MPIR_proctable:\n"); for (i = 0; i < MPIR_proctable_size; i++) { fprintf(stderr, " (i, host, exe, pid) = (%d, %s, %s, %d)\n", i, MPIR_proctable[i].host_name, MPIR_proctable[i].executable_name, MPIR_proctable[i].pid); }}/* * Process one line from the orte_base_user_debugger MCA param and * look for that debugger in the path. If we find it, fill in * new_argv. */static int process(char *orig_line, char *basename, opal_cmd_line_t *cmd_line, int argc, char **argv, char ***new_argv) { int i; char *line, *full_line = strdup(orig_line); char *user_argv, *tmp, *tmp2, **tmp_argv, **executable; char cwd[PATH_MAX]; bool used_num_procs = false; bool fail_single_app = false; bool fail_needed_executable = false; line = full_line; if (NULL == line) { return ORTE_ERR_OUT_OF_RESOURCE; } /* Trim off whitespace at the beginning and ending of line */ for (i = 0; '\0' != line[i] && isspace(line[i]); ++line) { continue; } for (i = strlen(line) - 2; i > 0 && isspace(line[i]); ++i) { line[i] = '\0'; } if (strlen(line) <= 0) { return ORTE_ERROR; } /* Get the tail of the command line (i.e., the user executable / argv) */ opal_cmd_line_get_tail(cmd_line, &i, &executable); /* Remove --debug, --debugger, and -tv from the user command line params */ if (1 == argc) { user_argv = strdup(""); } else { tmp_argv = opal_argv_copy(argv); for (i = 0; NULL != tmp_argv[i]; ++i) { if (0 == strcmp(tmp_argv[i], "-debug") || 0 == strcmp(tmp_argv[i], "--debug")) { free(tmp_argv[i]); tmp_argv[i] = strdup(""); } else if (0 == strcmp(tmp_argv[i], "-tv") || 0 == strcmp(tmp_argv[i], "--tv")) { free(tmp_argv[i]); tmp_argv[i] = strdup(""); } else if (0 == strcmp(tmp_argv[i], "--debugger") || 0 == strcmp(tmp_argv[i], "-debugger")) { free(tmp_argv[i]); tmp_argv[i] = strdup(""); if (NULL != tmp_argv[i + 1]) { ++i; free(tmp_argv[i]); tmp_argv[i] = strdup(""); } } } user_argv = opal_argv_join(tmp_argv + 1, ' '); opal_argv_free(tmp_argv); } /* Replace @@ tokens - line should never realistically be bigger than MAX_INT, so just cast to int to remove compiler warning */ for (i = 0; i < (int) strlen(line); ++i) { tmp = NULL; if (0 == strncmp(line + i, "@mpirun@", 8)) { line[i] = '\0'; asprintf(&tmp, "%s%s%s", line, argv[0], line + i + 8); } else if (0 == strncmp(line + i, "@orterun@", 9)) { line[i] = '\0'; asprintf(&tmp, "%s%s%s", line, argv[0], line + i + 9); } else if (0 == strncmp(line + i, "@mpirun_args@", 13)) { line[i] = '\0'; asprintf(&tmp, "%s%s%s", line, user_argv, line + i + 13); } else if (0 == strncmp(line + i, "@orterun_args@", 14)) { line[i] = '\0'; asprintf(&tmp, "%s%s%s", line, user_argv, line + i + 14); } else if (0 == strncmp(line + i, "@np@", 4)) { line[i] = '\0'; asprintf(&tmp, "%s%d%s", line, orterun_globals.num_procs, line + i + 4); used_num_procs = true; } else if (0 == strncmp(line + i, "@single_app@", 12)) { line[i] = '\0'; /* This token is only a flag; it is not replaced with any alternate text */ asprintf(&tmp, "%s%s", line, line + i + 12); tmp2 = opal_argv_join(executable + 1, ' '); if (NULL != strchr(tmp2, ':')) { fail_single_app = true; } free(tmp2); } else if (0 == strncmp(line + i, "@executable@", 12)) { line[i] = '\0'; /* If we found the executable, paste it in. Otherwise, this is a possible error. */ if (NULL != executable) { asprintf(&tmp, "%s%s%s", line, executable[0], line + i + 12); } else { fail_needed_executable = true; } } else if (0 == strncmp(line + i, "@executable_argv@", 17)) { line[i] = '\0'; /* If we found the tail, paste in the argv. Otherwise, this is a possible error. */ if (NULL != executable) { if (NULL != executable[1]) { /* Put in the argv */ tmp2 = opal_argv_join(executable + 1, ' '); asprintf(&tmp, "%s%s%s", line, tmp2, line + i + 17); free(tmp2); } else { /* There is no argv; just paste the front and back together, removing the @token@ */ asprintf(&tmp, "%s%s", line, line + i + 17); } } else { fail_needed_executable = true; } } if (NULL != tmp) { free(full_line); full_line = line = tmp; --i; } } /* Split up into argv */ *new_argv = opal_argv_split(line, ' '); free(line);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -