unw_nto_create()

QNX SDP8.0C Library ReferenceAPIDeveloper

Create an unw_nto-info structure

Synopsis:

void *unw_nto_create (pid_t pid, pthread_t tid)

Arguments:

pid
Identifier for the target process to hold.
tid
Identifier for the target thread to hold.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The unw_nto_create() function sets up a connection to the remote process and thread, and holds the execution of the remote thread. To this end, it creates an unw_nto-info structure passing the pid and tid as the arguments. By calling tid as an argument, it holds the target thread and avoids the race conditions. The unw_nto_create() function returns a NULL pointer on failure and an opaque pointer to an internal structure on success. This opaque pointer to an internal structure is then passed to unw_init_remote() while creating a libunwind cursor.

Returns:

0
An error occurred.
Any other value
Success.

Example:

    #include "os-qnx.h"
    #include "unw_nto_internal.h"
    
    #include <errno.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/procfs.h>
    #include <sys/neutrino.h>
/**
 * Hold the target thread to avoid race conditions.
 * @param[in] ctl_fd  File descriptor for /proc process ctl file
 * @param[in] tid     Identifies thread to hold
 *
 * @returns 0 on error, otherwise on success.
 */
static int _hold_thread (int ctl_fd, pthread_t tid)
{
  procfs_threadctl tctl =
    {
    .cmd = _NTO_TCTL_ONE_THREAD_HOLD,
    .tid = tid
    };
  memcpy (tctl.data, & (tid), sizeof (tid));
  int err = devctl (ctl_fd, DCMD_PROC_THREADCTL, &tctl, sizeof (tctl), NULL);
    
  if (err != EOK)
    {
    Debug (0, "error %d in devctl(DCMD_PROC_THREADCTL): %s\n", err, strerror (err));
    }
    
  return err == EOK;
}
    
    
void *unw_nto_create (pid_t pid, pthread_t tid)
{
  unw_nto_internal_t *uni = calloc (1, sizeof (unw_nto_internal_t));
  if (uni == NULL)
    {
    return NULL;
    }
    
  mi_init ();
    
  uni->pid = pid;
  uni->tid = tid;
  uni->edi.di_cache.format = -1;
  uni->edi.di_debug.format = -1;
  int ctl_fd = unw_nto_procfs_open_ctl (pid);
    
  if (ctl_fd < 0)
    {
    Debug (0, "error %d opening procfs ctl file for pid %d: %s\n",
    errno, pid, strerror (errno));
    unw_nto_destroy (uni);
    uni = NULL;
    return uni;
    }
    
  if (!_hold_thread (ctl_fd, tid))
    {
    close (ctl_fd);
    unw_nto_destroy (uni);
    uni = NULL;
    }
    
  else
    {
    close (ctl_fd);
    }
    
  return uni;
}
Page updated: