From 1b9cd12c9f7e22a6620bedf65b7bb1fd6e2c56e2 Mon Sep 17 00:00:00 2001 From: "Christopher J. Morrone" <morrone2@llnl.gov> Date: Tue, 26 Jul 2005 17:30:56 +0000 Subject: [PATCH] Move pdebug functions into their own file --- src/slurmd/Makefile.am | 3 +- src/slurmd/mgr.c | 48 ++-------------------------- src/slurmd/pdebug.c | 71 ++++++++++++++++++++++++++++++++++++++++++ src/slurmd/pdebug.h | 52 +++++++++++++++++++++++++++++++ src/slurmd/task.c | 34 ++------------------ 5 files changed, 130 insertions(+), 78 deletions(-) create mode 100644 src/slurmd/pdebug.c create mode 100644 src/slurmd/pdebug.h diff --git a/src/slurmd/Makefile.am b/src/slurmd/Makefile.am index 753950f9c46..d7b7a410418 100644 --- a/src/slurmd/Makefile.am +++ b/src/slurmd/Makefile.am @@ -30,7 +30,8 @@ slurmd_SOURCES = \ ulimits.c ulimits.h \ kill_tree.c kill_tree.h \ proctrack.c proctrack.h \ - setproctitle.c setproctitle.h + setproctitle.c setproctitle.h \ + pdebug.c pdebug.h slurmd_LDFLAGS = -export-dynamic $(CMD_LDFLAGS) $(FEDERATION_LDFLAGS) diff --git a/src/slurmd/mgr.c b/src/slurmd/mgr.c index c8850ac03ef..9a8cf9d73a1 100644 --- a/src/slurmd/mgr.c +++ b/src/slurmd/mgr.c @@ -41,7 +41,6 @@ #include <sys/stat.h> #include <sys/param.h> #include <sys/poll.h> -#include <sys/ptrace.h> #include <unistd.h> #include <pwd.h> #include <grp.h> @@ -76,6 +75,7 @@ #include "src/slurmd/io.h" #include "src/slurmd/shm.h" #include "src/slurmd/proctrack.h" +#include "src/slurmd/pdebug.h" /* * Map session manager exit status to slurm errno: @@ -146,20 +146,6 @@ static char * _make_batch_dir(slurmd_job_t *job); static char * _make_batch_script(batch_job_launch_msg_t *msg, char *path); static int _complete_job(uint32_t jobid, uint32_t stepid, int err, int status); -/* - * Parallel debugger support - */ -static void _pdebug_trace_process(slurmd_job_t *job, pid_t pid); -#ifdef HAVE_PTRACE64 -# define _PTRACE(r,p,a,d) ptrace64((r),(long long)(p),(long long)(a),(d),NULL) -#else -# ifdef PTRACE_FIVE_ARGS -# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(d),NULL) -# else -# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(void *)(d)) -# endif -#endif - static slurmd_job_t *reattach_job; @@ -632,6 +618,7 @@ _fork_all_tasks(slurmd_job_t *job) /* * Pre-allocate a pipe for each of the tasks */ + debug3("num tasks on this node = %d", job->ntasks); writefds = (int *) xmalloc (job->ntasks * sizeof(int)); if (!writefds) error("writefds xmalloc failed!"); @@ -729,12 +716,11 @@ _fork_all_tasks(slurmd_job_t *job) close(writefds[i]); - debug3("Before _pdebug_trace_process"); /* * Prepare process for attach by parallel debugger * (if specified and able) */ - _pdebug_trace_process(job, job->task[i]->pid); + pdebug_trace_process(job, job->task[i]->pid); } xfree(writefds); xfree(readfds); @@ -1256,31 +1242,3 @@ _become_user(slurmd_job_t *job) } -/* - * Prepare task for parallel debugger attach - */ -static void -_pdebug_trace_process(slurmd_job_t *job, pid_t pid) -{ - /* If task to be debugged, wait for it to stop via - * child's ptrace(PTRACE_TRACEME), then SIGSTOP, and - * ptrace(PTRACE_DETACH). This requires a kernel patch, - * which you may already have in place for TotalView. - * If not, apply the kernel patch in etc/ptrace.patch - */ - - if (job->task_flags & TASK_PARALLEL_DEBUG) { - int status; - waitpid(pid, &status, WUNTRACED); - if ((pid > (pid_t) 0) && (kill(pid, SIGSTOP) < 0)) - error("kill(%lu): %m", (unsigned long) pid); -#ifdef HAVE_AIX - if (_PTRACE(PT_DETACH, pid, NULL, 0)) -#else - if (_PTRACE(PTRACE_DETACH, pid, NULL, 0)) -#endif - error("ptrace(%lu): %m", (unsigned long) pid); - } -} - - diff --git a/src/slurmd/pdebug.c b/src/slurmd/pdebug.c new file mode 100644 index 00000000000..515136a44e2 --- /dev/null +++ b/src/slurmd/pdebug.c @@ -0,0 +1,71 @@ +/*****************************************************************************\ + * src/slurmd/ptrace_debug.c - ptrace functions for slurmd + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Mark Grondona <mgrondona@llnl.gov>. + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ +#include "pdebug.h" + +/* + * Prepare task for parallel debugger attach + */ +void +pdebug_trace_process(slurmd_job_t *job, pid_t pid) +{ + /* If task to be debugged, wait for it to stop via + * child's ptrace(PTRACE_TRACEME), then SIGSTOP, and + * ptrace(PTRACE_DETACH). This requires a kernel patch, + * which you may already have in place for TotalView. + * If not, apply the kernel patch in etc/ptrace.patch + */ + + if (job->task_flags & TASK_PARALLEL_DEBUG) { + int status; + waitpid(pid, &status, WUNTRACED); + if ((pid > (pid_t) 0) && (kill(pid, SIGSTOP) < 0)) + error("kill(%lu): %m", (unsigned long) pid); +#ifdef HAVE_AIX + if (_PTRACE(PT_DETACH, pid, NULL, 0)) +#else + if (_PTRACE(PTRACE_DETACH, pid, NULL, 0)) +#endif + error("ptrace(%lu): %m", (unsigned long) pid); + } +} + +/* + * Stop current task on exec() for connection from a parallel debugger + */ +void +pdebug_stop_current(slurmd_job_t *job) +{ + /* + * Stop the task on exec for TotalView to connect + */ + if ( (job->task_flags & TASK_PARALLEL_DEBUG) +#ifdef HAVE_AIX + && (_PTRACE(PT_TRACE_ME, 0, NULL, 0) < 0) ) +#else + && (_PTRACE(PTRACE_TRACEME, 0, NULL, 0) < 0) ) +#endif + error("ptrace: %m"); +} diff --git a/src/slurmd/pdebug.h b/src/slurmd/pdebug.h new file mode 100644 index 00000000000..f6e432529f0 --- /dev/null +++ b/src/slurmd/pdebug.h @@ -0,0 +1,52 @@ +/*****************************************************************************\ + * src/slurmd/ptrace_debug.h - ptrace functions for slurmd + ***************************************************************************** + * Copyright (C) 2002 The Regents of the University of California. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Mark Grondona <mgrondona@llnl.gov>. + * UCRL-CODE-2002-040. + * + * This file is part of SLURM, a resource management program. + * For details, see <http://www.llnl.gov/linux/slurm/>. + * + * SLURM is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with SLURM; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\*****************************************************************************/ +#ifndef _PDEBUG_H +#define _PDEBUG_H + +#include <sys/ptrace.h> +#include <sys/wait.h> +#include "src/slurmd/slurmd_job.h" + +/* + * Stop current task on exec() for connection from a parallel debugger + */ +void pdebug_stop_current(slurmd_job_t *job); +/* + * Prepare task for parallel debugger attach + */ +void pdebug_trace_process(slurmd_job_t *job, pid_t pid); + +#ifdef HAVE_PTRACE64 +# define _PTRACE(r,p,a,d) ptrace64((r),(long long)(p),(long long)(a),(d),NULL) +#else +# ifdef PTRACE_FIVE_ARGS +# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(d),NULL) +# else +# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(void *)(d)) +# endif +#endif + +#endif diff --git a/src/slurmd/task.c b/src/slurmd/task.c index 17d2e3e554f..0dd110ff5b9 100644 --- a/src/slurmd/task.c +++ b/src/slurmd/task.c @@ -32,7 +32,6 @@ #include <sys/wait.h> #include <sys/stat.h> #include <sys/param.h> -#include <sys/ptrace.h> #include <unistd.h> #include <pwd.h> #include <grp.h> @@ -66,6 +65,7 @@ #include "src/slurmd/io.h" #include "src/slurmd/proctrack.h" #include "src/slurmd/shm.h" +#include "src/slurmd/pdebug.h" /* @@ -76,17 +76,6 @@ static char *_signame(int signo); static void _cleanup_file_descriptors(slurmd_job_t *job); static void _setup_spawn_io(slurmd_job_t *job); -static void _pdebug_stop_current(slurmd_job_t *job); -#ifdef HAVE_PTRACE64 -# define _PTRACE(r,p,a,d) ptrace64((r),(long long)(p),(long long)(a),(d),NULL) -#else -# ifdef PTRACE_FIVE_ARGS -# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(d),NULL) -# else -# define _PTRACE(r,p,a,d) ptrace((r),(p),(a),(void *)(d)) -# endif -#endif - static void _setup_spawn_io(slurmd_job_t *job) { @@ -199,7 +188,7 @@ exec_task(slurmd_job_t *job, int i, int waitfd) slurmd_mpi_init (job, job->task[i]->gtid); - _pdebug_stop_current(job); + pdebug_stop_current(job); } /* @@ -267,22 +256,3 @@ _make_tmpdir(slurmd_job_t *job) return; } - - -/* - * Stop current task on exec() for connection from a parallel debugger - */ -static void -_pdebug_stop_current(slurmd_job_t *job) -{ - /* - * Stop the task on exec for TotalView to connect - */ - if ( (job->task_flags & TASK_PARALLEL_DEBUG) -#ifdef HAVE_AIX - && (_PTRACE(PT_TRACE_ME, 0, NULL, 0) < 0) ) -#else - && (_PTRACE(PTRACE_TRACEME, 0, NULL, 0) < 0) ) -#endif - error("ptrace: %m"); -} -- GitLab