Exemplo n.º 1
0
Bool VG_(split_up_argv)( Int argc, HChar** argv )
{
    Int  i;
    Bool augment = True;
    static Bool already_called = False;

    HChar* hwArgs = HARDWIRED_ARGS_FOR_BGQ;
    if (hwArgs) {
        // This is never freed.  The strduping is necessary because
        // hwArgs is subsequently modified.
        hwArgs = VG_(strdup)("commandline.sua.5", hwArgs);
    }

    XArray* /* of HChar* */ tmp_xarray;

    /* This function should be called once, at startup, and then never
       again. */
    vg_assert(!already_called);
    already_called = True;

    tmp_xarray = VG_(newXA)( VG_(malloc), "commandline.sua.1",
                             VG_(free), sizeof(HChar*) );
    vg_assert(tmp_xarray);

    vg_assert( ! VG_(args_for_valgrind) );
    VG_(args_for_valgrind)
        = VG_(newXA)( VG_(malloc), "commandline.sua.2",
                      VG_(free), sizeof(HChar*) );
    vg_assert( VG_(args_for_valgrind) );

    vg_assert( ! VG_(args_for_client) );
    VG_(args_for_client)
        = VG_(newXA)( VG_(malloc), "commandline.sua.3",
                      VG_(free), sizeof(HChar*) );
    vg_assert( VG_(args_for_client) );

    /* Collect up the args-for-V. */
    i = 1; /* skip the exe (stage2) name. */
    for (; i < argc; i++) {
        vg_assert(argv[i]);
        if (hwArgs != NULL) {
            break;
        }
        if (0 == VG_(strcmp)(argv[i], "--")) {
            i++;
            break;
        }
        if (0 == VG_(strcmp)(argv[i], "--command-line-only=yes"))
            augment = False;
#     if !defined(VGPV_ppc64_linux_bgq)
        /* If we find an arg which doesn't start with '-', assume it is
           the executable name, so stop copying args for Valgrind at
           this point.  Except on statically-linked-in scenarios (BGQ),
           in which case the args for V must be terminated by "--", and
           the first arg that follows is the first arg for the client. */
        if (argv[i][0] != '-')
            break;
#     endif
        add_string( tmp_xarray, argv[i] );
    }

    /* Set VG_(args_the_exename).  Different in the
       statically-linked-in case (BGQ). */
#  if defined(VGPV_ppc64_linux_bgq)
    vg_assert(!VG_(args_the_exename));
    vg_assert(argv[0]);
    VG_(args_the_exename) = argv[0];
#  else
    /* Should now be looking at the exe name. */
    if (i < argc) {
        vg_assert(argv[i]);
        VG_(args_the_exename) = argv[i];
        i++;
    }
#  endif

    /* The rest are args for the client. */
    for (; i < argc; i++) {
        vg_assert(argv[i]);
        add_string( VG_(args_for_client), argv[i] );
    }

    /* Get extra args from ~/.valgrindrc, $VALGRIND_OPTS and
       ./.valgrindrc into VG_(args_for_valgrind). */
    if (augment) {
        // read_dot_valgrindrc() allocates the return value with
        // VG_(malloc)().  We do not free f1_clo and f2_clo as they get
        // put into VG_(args_for_valgrind) and so must persist.
        HChar* home    = VG_(getenv)("HOME");
        HChar* f1_clo  = home ? read_dot_valgrindrc( home ) : NULL;
        HChar* env_clo = VG_(strdup)( "commandline.sua.4",
                                      VG_(getenv)(VALGRIND_OPTS) );
        HChar* f2_clo  = NULL;

        // Don't read ./.valgrindrc if "." is the same as "$HOME", else its
        // contents will be applied twice. (bug #142488)
        if (home) {
            HChar cwd[VKI_PATH_MAX+1];
            Bool  cwd_ok = VG_(get_startup_wd)(cwd, VKI_PATH_MAX);
            f2_clo = ( (cwd_ok && VG_STREQ(home, cwd))
                       ? NULL : read_dot_valgrindrc(".") );
        }

        if (f1_clo)  add_args_from_string( f1_clo );
        if (env_clo) add_args_from_string( env_clo );
        if (f2_clo)  add_args_from_string( f2_clo );
        if (hwArgs)  add_args_from_string( hwArgs );
    }

    /* .. and record how many extras we got. */
    VG_(args_for_valgrind_noexecpass)
        = VG_(sizeXA)( VG_(args_for_valgrind) );

    /* Finally, copy tmp_xarray onto the end. */
    for (i = 0; i < VG_(sizeXA)( tmp_xarray ); i++)
        add_string( VG_(args_for_valgrind),
                    * (HChar**)VG_(indexXA)( tmp_xarray, i ) );

    VG_(deleteXA)( tmp_xarray );

    return hwArgs != NULL;
}
Exemplo n.º 2
0
void VG_(split_up_argv)( Int argc, HChar** argv )
{
          Int  i;
          Bool augment = True;
   static Bool already_called = False;

   XArrayStrings tmp_xarray = {0,0,NULL};

   /* This function should be called once, at startup, and then never
      again. */
   vg_assert(!already_called);
   already_called = True;

   /* Collect up the args-for-V. */
   i = 1; /* skip the exe (stage2) name. */
   for (; i < argc; i++) {
      vg_assert(argv[i]);
      if (0 == VG_(strcmp)(argv[i], "--")) {
         i++;
         break;
      }
      if (0 == VG_(strcmp)(argv[i], "--command-line-only=yes"))
         augment = False;
      if (argv[i][0] != '-')
	break;
      add_string( &tmp_xarray, argv[i] );
   }

   /* Should now be looking at the exe name. */
   if (i < argc) {
      vg_assert(argv[i]);
      VG_(args_the_exename) = argv[i];
      i++;
   }

   /* The rest are args for the client. */
   for (; i < argc; i++) {
      vg_assert(argv[i]);
      add_string( &VG_(args_for_client), argv[i] );
   }

   VG_(args_for_valgrind).size = 0;
   VG_(args_for_valgrind).used = 0;
   VG_(args_for_valgrind).strs = NULL;

   /* Get extra args from ~/.valgrindrc, $VALGRIND_OPTS and
      ./.valgrindrc into VG_(args_for_valgrind). */
   if (augment) {
      // read_dot_valgrindrc() allocates the return value with
      // VG_(malloc)().  We do not free f1_clo and f2_clo as they get
      // put into VG_(args_for_valgrind) and so must persist.
      HChar* home    = VG_(getenv)("HOME");
      HChar* f1_clo  = home ? read_dot_valgrindrc( home ) : NULL;
      HChar* env_clo = VG_(strdup)( VG_(getenv)(VALGRIND_OPTS) );
      HChar* f2_clo  = NULL;

      // Don't read ./.valgrindrc if "." is the same as "$HOME", else its
      // contents will be applied twice. (bug #142488)
      if (home) {
         HChar cwd[VKI_PATH_MAX+1];
         Bool  cwd_ok = VG_(getcwd)(cwd, VKI_PATH_MAX);
         f2_clo = ( (cwd_ok && VG_STREQ(home, cwd))
                       ? NULL : read_dot_valgrindrc(".") );
      }

      if (f1_clo)  add_args_from_string( f1_clo );
      if (env_clo) add_args_from_string( env_clo );
      if (f2_clo)  add_args_from_string( f2_clo );
   }

   /* .. and record how many extras we got. */
   VG_(args_for_valgrind_noexecpass) = VG_(args_for_valgrind).used;

   /* Finally, copy tmp_xarray onto the end. */
   for (i = 0; i < tmp_xarray.used; i++)
      add_string( &VG_(args_for_valgrind), tmp_xarray.strs[i] );

   if (tmp_xarray.strs)
      VG_(free)(tmp_xarray.strs);
}
void VG_(split_up_argv)( Int argc, HChar** argv )
{
          Int  i;
          Bool augment = True;
   static Bool already_called = False;

   XArray* /* of HChar* */ tmp_xarray;

   /* This function should be called once, at startup, and then never
      again. */
   vg_assert(!already_called);
   already_called = True;

   tmp_xarray = VG_(newXA)( VG_(malloc), "commandline.sua.1",
                            VG_(free), sizeof(HChar*) );

   vg_assert( ! VG_(args_for_valgrind) );
   VG_(args_for_valgrind)
      = VG_(newXA)( VG_(malloc), "commandline.sua.2",
                    VG_(free), sizeof(HChar*) );

   vg_assert( ! VG_(args_for_client) );
   VG_(args_for_client)
      = VG_(newXA)( VG_(malloc), "commandline.sua.3",
                    VG_(free), sizeof(HChar*) );

   /* Collect up the args-for-V. */
   i = 1; /* skip the exe (stage2) name. */
   for (; i < argc; i++) {
      vg_assert(argv[i]);
      if (0 == VG_(strcmp)(argv[i], "--")) {
         i++;
         break;
      }
      if (0 == VG_(strcmp)(argv[i], "--command-line-only=yes"))
         augment = False;
      if (argv[i][0] != '-')
	break;
      add_string( tmp_xarray, argv[i] );
   }

   /* Should now be looking at the exe name. */
   if (i < argc) {
      vg_assert(argv[i]);
      VG_(args_the_exename) = argv[i];
      i++;
   }

   /* The rest are args for the client. */
   for (; i < argc; i++) {
      vg_assert(argv[i]);
      add_string( VG_(args_for_client), argv[i] );
   }

   /* Get extra args from ~/.valgrindrc, $VALGRIND_OPTS and
      ./.valgrindrc into VG_(args_for_valgrind). */
   if (augment) {
      // read_dot_valgrindrc() allocates the return value with
      // VG_(malloc)().  We do not free f1_clo and f2_clo as they get
      // put into VG_(args_for_valgrind) and so must persist.
      HChar* home    = VG_(getenv)("HOME");
      HChar* f1_clo  = home ? read_dot_valgrindrc( home ) : NULL;
      HChar* env_clo = VG_(strdup)( "commandline.sua.4",
                                    VG_(getenv)(VALGRIND_OPTS) );
      HChar* f2_clo  = NULL;

      // Don't read ./.valgrindrc if "." is the same as "$HOME", else its
      // contents will be applied twice. (bug #142488)
      if (home) {
         const HChar *cwd = VG_(get_startup_wd)();
         f2_clo = ( VG_STREQ(home, cwd)
                       ? NULL : read_dot_valgrindrc(".") );
      }

      if (f1_clo)  add_args_from_string( f1_clo );
      if (env_clo) add_args_from_string( env_clo );
      if (f2_clo)  add_args_from_string( f2_clo );
   }

   /* .. and record how many extras we got. */
   VG_(args_for_valgrind_noexecpass) 
      = VG_(sizeXA)( VG_(args_for_valgrind) );

   /* Finally, copy tmp_xarray onto the end. */
   for (i = 0; i < VG_(sizeXA)( tmp_xarray ); i++)
      add_string( VG_(args_for_valgrind), 
                  * (HChar**)VG_(indexXA)( tmp_xarray, i ) );

   VG_(deleteXA)( tmp_xarray );
}