Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debugger examples #1030

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions examples/debugger/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ static void iof_reg_callbk(pmix_status_t status, size_t evhandler_ref, void *cbd
DEBUG_WAKEUP_THREAD(lock);
}

static void iof_dereg_callbk(pmix_status_t status, void *cbdata)
{
printf("%s called as result of de-registering I/O forwarding\n",
__FUNCTION__);
}

int parse_tool_options(int argc, char **argv)
{
char *endp;
Expand Down Expand Up @@ -266,11 +260,13 @@ int main(int argc, char **argv)
{
pmix_status_t rc;
pmix_info_t *info;
void *attr_list;
size_t ninfo;
char *nspace = NULL;
mylock_t mylock;
pid_t pid;
int ns_index;
pmix_data_array_t attr_array;

pid = getpid();

Expand All @@ -291,15 +287,19 @@ int main(int argc, char **argv)
info = NULL;
ninfo = 1;

PMIX_INFO_CREATE(info, ninfo);
PMIX_INFO_LOAD(&info[0], PMIX_LAUNCHER, NULL, PMIX_BOOL);

/* Initialize as a tool */
PMIX_INFO_LIST_START(attr_list);
PMIX_INFO_LIST_ADD(rc, attr_list, PMIX_LAUNCHER, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, attr_list, PMIX_IOF_LOCAL_OUTPUT, NULL, PMIX_BOOL);
PMIX_INFO_LIST_CONVERT(rc, attr_list, &attr_array);
PMIX_INFO_LIST_RELEASE(attr_list);
info = attr_array.array;
ninfo = attr_array.size;
if (PMIX_SUCCESS != (rc = PMIx_tool_init(&myproc, info, ninfo))) {
fprintf(stderr, "PMIx_tool_init failed: %s(%d)\n", PMIx_Error_string(rc), rc);
exit(rc);
}
PMIX_INFO_FREE(info, ninfo);
PMIX_DATA_ARRAY_DESTRUCT(&attr_array);

printf("Debugger ns %s rank %d pid %lu: Running\n", myproc.nspace, myproc.rank,
(unsigned long) pid);
Expand All @@ -313,8 +313,6 @@ int main(int argc, char **argv)
if (PMIX_SUCCESS != (rc = attach_to_running_job(nspace))) {
fprintf(stderr, "Failed to attach to nspace %s: error code %d\n", nspace, rc);
}
rc = PMIx_IOF_deregister(iof_handler_id, NULL, 0, iof_dereg_callbk, NULL);
printf("PMIx_IOF_deregister completed with status %s\n", PMIx_Error_string(rc));
PMIx_tool_finalize();
if (NULL != iof_data) {
printf("Forwarded stdio data:\n%s", iof_data);
Expand All @@ -330,7 +328,7 @@ static int attach_to_running_job(char *nspace)
pmix_proc_t daemon_proc, target_proc;
pmix_info_t *info;
pmix_app_t *app;
pmix_status_t codes[] = {PMIX_EVENT_JOB_END, PMIX_ERR_LOST_CONNECTION};
pmix_status_t code = PMIX_ERR_LOST_CONNECTION;
size_t ninfo;
int n;
mylock_t mylock, iof_lock;
Expand Down Expand Up @@ -436,17 +434,16 @@ static int attach_to_running_job(char *nspace)
DEBUG_CONSTRUCT_LOCK(&myrel.lock);
myrel.nspace = strdup(dspace);

/* Register a handler for PMIX_ERR_LOST_CONNECTION, which will occur when the
* daemon terminates. */
PMIX_INFO_LIST_START(dirs);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_EVENT_RETURN_OBJECT, &myrel, PMIX_POINTER);
/* Only call me back when this specific job terminates */
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_EVENT_AFFECTED_PROC, &daemon_proc, PMIX_PROC);

PMIX_INFO_LIST_CONVERT(rc, dirs, &darray);
PMIX_INFO_LIST_RELEASE(dirs);
info = darray.array;
ninfo = darray.size;
DEBUG_CONSTRUCT_LOCK(&mylock);
PMIx_Register_event_handler(codes, 2, info, 2, release_fn, evhandler_reg_callbk,
PMIx_Register_event_handler(&code, 1, info, ninfo, release_fn, evhandler_reg_callbk,
(void *) &mylock);
DEBUG_WAIT_THREAD(&mylock);
PMIX_DATA_ARRAY_DESTRUCT(&darray);
Expand Down
10 changes: 2 additions & 8 deletions examples/debugger/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,9 @@ int main(int argc, char **argv)
/* Call PMIx_tool_finalize to shut down the PMIx runtime */
printf("Debugger daemon ns %s rank %d pid %lu: Finalizing\n", myproc.nspace, myproc.rank,
(unsigned long) pid);
if (PMIX_SUCCESS != (rc = PMIx_tool_finalize())) {
fprintf(stderr, "Debugger daemon ns %s rank %d:PMIx_Finalize failed: %s\n", myproc.nspace,
myproc.rank, PMIx_Error_string(rc));
} else {
printf("Debugger daemon ns %s rank %d pid %lu:PMIx_Finalize successfully completed\n",
myproc.nspace, myproc.rank, (unsigned long) pid);
}
rc = PMIx_tool_finalize();
fclose(stdout);
fclose(stderr);
sleep(1);
return (0);
return (rc);
}
1 change: 1 addition & 0 deletions examples/debugger/direct-multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ int main(int argc, char **argv)
PMIX_INFO_LIST_START(tinfo);
PMIX_INFO_LIST_ADD(rc, tinfo, PMIX_CONNECT_SYSTEM_FIRST, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, tinfo, PMIX_LAUNCHER, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, tinfo, PMIX_IOF_LOCAL_OUTPUT, NULL, PMIX_BOOL);
PMIX_INFO_LIST_CONVERT(rc, tinfo, &darray);
info = (pmix_info_t*)darray.array;
ninfo = darray.size;
Expand Down
1 change: 1 addition & 0 deletions examples/debugger/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ int main(int argc, char **argv)
/* Use the system connection first, if available */
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_CONNECT_SYSTEM_FIRST, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_LAUNCHER, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_IOF_LOCAL_OUTPUT, NULL, PMIX_BOOL);
PMIX_INFO_LIST_CONVERT(rc, dirs, &darray);
PMIX_INFO_LIST_RELEASE(dirs);
info = darray.array;
Expand Down
2 changes: 1 addition & 1 deletion examples/debugger/indirect-multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void terminate_fn(size_t evhdlr_registration_id, pmix_status_t status,
pmix_info_t results[], size_t nresults,
pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata)
{
printf("[%d]%s called with status %s\n", getpid(), __FUNCTION__, PMIx_Error_string(status));
printf("%s called with status %s\n", __FUNCTION__, PMIx_Error_string(status));
/* this example doesn't do anything further */
if (NULL != cbfunc) {
cbfunc(PMIX_EVENT_ACTION_COMPLETE, NULL, 0, NULL, NULL, cbdata);
Expand Down
14 changes: 7 additions & 7 deletions examples/debugger/indirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ int main(int argc, char **argv)
PMIX_INFO_LIST_START(dirs);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_TOOL_DO_NOT_CONNECT, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_LAUNCHER, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_IOF_LOCAL_OUTPUT, NULL, PMIX_BOOL);
PMIX_INFO_LIST_CONVERT(rc, dirs, &darray);
PMIX_INFO_LIST_RELEASE(dirs);
info = darray.array;
Expand Down Expand Up @@ -257,15 +258,15 @@ int main(int argc, char **argv)
* from the application as the launcher will have had it forwarded
* to itself */
PMIX_INFO_LIST_START(jinfo);
PMIX_INFO_LIST_ADD(rc, jinfo, PMIX_NOTIFY_JOB_EVENTS, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, jinfo, PMIX_FWD_STDOUT, NULL, PMIX_BOOL); // forward stdout to me
PMIX_INFO_LIST_ADD(rc, jinfo, PMIX_FWD_STDERR, NULL, PMIX_BOOL); // forward stderr to me
PMIX_INFO_LIST_ADD(rc, jinfo, PMIX_SPAWN_TOOL, NULL, PMIX_BOOL); // we are spawning a tool
/* create the launch directives to tell the launcher what
* to do with the app it is going to spawn for us */
PMIX_INFO_LIST_START(linfo);
rank = PMIX_RANK_WILDCARD;
PMIX_INFO_LIST_ADD(rc, linfo, PMIX_DEBUG_STOP_IN_INIT, &rank, PMIX_PROC_RANK); // stop all procs in init
PMIX_INFO_LIST_ADD(rc, linfo, PMIX_NOTIFY_JOB_EVENTS, NULL, PMIX_BOOL);
PMIX_INFO_LIST_ADD(rc, linfo, PMIX_FWD_STDOUT, NULL, PMIX_BOOL); // forward stdout to me
PMIX_INFO_LIST_ADD(rc, linfo, PMIX_FWD_STDERR, NULL, PMIX_BOOL); // forward stderr to me
PMIX_INFO_LIST_ADD(rc, linfo, PMIX_SPAWN_TOOL, NULL, PMIX_BOOL); // we are spawning a tool
PMIX_INFO_LIST_CONVERT(rc, linfo, &darray2);
PMIX_INFO_LIST_ADD(rc, jinfo, PMIX_LAUNCH_DIRECTIVES, &darray2, PMIX_DATA_ARRAY);
PMIX_INFO_LIST_RELEASE(linfo);
Expand Down Expand Up @@ -315,12 +316,11 @@ int main(int argc, char **argv)
/* register to receive the ready-for-debug event alerting us that things are ready
* for us to spawn the debugger daemons - this will be registered
* with the IL we started */
printf("REGISTERING READY-FOR-DEBUG HANDLER for %s@%d\n", proc.nspace, proc.rank);
printf("REGISTERING READY-FOR-DEBUG HANDLER\n");
DEBUG_CONSTRUCT_LOCK(&mylock);
code = PMIX_READY_FOR_DEBUG;
PMIX_INFO_LIST_START(dirs);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_EVENT_HDLR_NAME, "READY-FOR-DEBUG", PMIX_STRING);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_EVENT_AFFECTED_PROC, &proc, PMIX_PROC);
PMIX_INFO_LIST_CONVERT(rc, dirs, &darray);
PMIX_INFO_LIST_RELEASE(dirs);
info = darray.array;
Expand All @@ -335,7 +335,7 @@ int main(int argc, char **argv)
goto done;
}

printf("RELEASING %s [%s:%d]\n", argv[1], proc.nspace, proc.rank);
printf("RELEASING %s [%s,%d]\n", argv[1], proc.nspace, proc.rank);
/* release the IL to spawn its job */
PMIX_INFO_LIST_START(dirs);
PMIX_INFO_LIST_ADD(rc, dirs, PMIX_EVENT_NON_DEFAULT, NULL, PMIX_BOOL);
Expand Down