示例#1
0
void vt_warning(const char* fmt, ...)
{
  va_list ap;

  if (vt_env_verbose() >= 1) {
    va_start(ap, fmt);
    vt_print_msg("WARNING", fmt, ap);
    va_end(ap);
  }
}
示例#2
0
void vt_cntl_msg(int level, const char* fmt, ...)
{
  va_list ap;

  if (vt_env_verbose() >= level) {
    va_start(ap, fmt);
    vt_print_msg(NULL, fmt, ap);
    va_end(ap);
  }
}
static void metricmap_dump(metricmap_t* map)
{
  unsigned i = 0;

  if (map == NULL || vt_env_verbose() < 3)
    return;

  vt_cntl_msg(3, "Metricmap dump (head=0x%p):", (void*)map);
  while (map != NULL) {
    vt_cntl_msg(3, "m[%3u] 0x%X %s = %s", i, map->type,
                map->event_name, map->alias_name);
    i++;
    map = map->next;
  }
  vt_cntl_msg(3, "Metricmap dumped %u maps", i);
}
示例#4
0
void VT_Dyn_attach()
{
  int mutatee_pid = getpid();

  vt_cntl_msg(1, "[%i]: Attaching instrumentor", mutatee_pid);

  /* Install signal handler for continue execution (SIGUSR1)
     and abort execution (SIGUSR2)
  */
  if( signal(SIGUSR1, sig_usr1_handler) == SIG_ERR )
    vt_error_msg("Could not install handler for signal SIGUSR1");

  if( signal(SIGUSR2, sig_usr2_handler) == SIG_ERR )
    vt_error_msg("Could not install handler for signal SIGUSR2");

  /* The Dyninst attach library (libvt-dynatt) could be set by LD_PRELOAD.
     Unset this environment variable to avoid recursion. */
  putenv((char*)"LD_PRELOAD=");
  putenv((char*)"DYLD_INSERT_LIBRARIES="); /* equivalent on MacOS */

  /* Attach Dyninst instrumentor on running executable
   */
  switch( fork() )
  {
    case -1:
    {
      vt_error_msg("Could not attach Dyninst instrumentor");
      break;
    }
    case 0:
    {
      int rc;
      char cmd[1024];
      char* filter = vt_env_filter_spec();
      char* shlibs = vt_env_dyn_shlibs();
      char* shlibs_arg = NULL;
      char* mutatee_path = NULL;

      /* Restore original signal handler
       */
      signal(SIGUSR1, SIG_DFL);
      signal(SIGUSR2, SIG_DFL);

      /* Try to get path of mutatee
       */
      vt_pform_init();
      mutatee_path = vt_env_apppath();

      /* Replace all colons by commas in list of shared libraries
       */
      if ( shlibs && strlen(shlibs) > 0 )
      {
        char* tk;
        shlibs_arg = (char*)calloc(strlen(shlibs)+2, sizeof(char));
        tk = strtok( shlibs, ":" );
        do
        {
           strcat(shlibs_arg, tk);
           strcat(shlibs_arg, ",");
        } while( (tk = strtok( 0, ":" )) );
        shlibs_arg[strlen(shlibs_arg)-1] = '\0';
      }

      snprintf(cmd,
              sizeof(cmd)-1, "%s/vtdyn %s %s %s %s %s %s %s %s %s %s %s "
                             "-p %i %s",
              vt_installdirs_get(VT_INSTALLDIR_BINDIR),
              (vt_env_verbose() == 0) ? "-q" : "",
              (vt_env_verbose() >= 2) ? "-v" : "",
              filter ? "-f" : "", filter ? filter : "",
              shlibs_arg ? "-s" : "", shlibs_arg ? shlibs_arg : "",
              (vt_env_dyn_outer_loops()) ? "--outer-loops" : "",
              (vt_env_dyn_inner_loops()) ? "--inner-loops" : "",
              (vt_env_dyn_loop_iters()) ? "--loop-iters" : "",
              (vt_env_dyn_ignore_nodbg()) ? "--ignore-nodbg" : "",
              (vt_env_dyn_detach()) ? "" : "--nodetach",
              mutatee_pid,
              mutatee_path ? mutatee_path : "");

      if ( shlibs_arg )
        free(shlibs_arg);

      /* Start mutator (instrumentor) */
      vt_cntl_msg(2, "[%i]: Executing %s", mutatee_pid, cmd);
      rc = system(cmd);

      /* Kill mutatee, if an error occurred during attaching
       */
      if(rc != 0)
        kill(mutatee_pid, SIGUSR2);

      exit(rc);

      break;
    }
    default:
    {
      /* Wait until mutator send signal to continue execution
       */
      vt_cntl_msg(1, "[%i]: Waiting until instrumentation is done",
                  mutatee_pid);

      do { usleep(1000); } while(mutatee_cont == 0);

      if ( !mutator_error )
      {
        /* Restore original signal handler
         */
        signal(SIGUSR1, SIG_DFL);
        signal(SIGUSR2, SIG_DFL);
      }
      else
      {
        vt_error_msg("An error occurred during instrumenting");
      }

      break;
    }
  }
}