|
From: <sv...@va...> - 2005-08-28 18:54:24
|
Author: tom
Date: 2005-08-28 19:54:17 +0100 (Sun, 28 Aug 2005)
New Revision: 4553
Log:
Abstract out the command line handling from m_main.c and make the launche=
r
use it to process the command line when looking for the tool to use.
Added:
branches/ASPACEM/coregrind/m_commandline.c
branches/ASPACEM/coregrind/pub_core_commandline.h
Modified:
branches/ASPACEM/coregrind/Makefile.am
branches/ASPACEM/coregrind/m_launcher.c
branches/ASPACEM/coregrind/m_main.c
Modified: branches/ASPACEM/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/Makefile.am 2005-08-28 16:29:25 UTC (rev 4=
552)
+++ branches/ASPACEM/coregrind/Makefile.am 2005-08-28 18:54:17 UTC (rev 4=
553)
@@ -43,6 +43,7 @@
coregrind.h \
pub_core_aspacemgr.h \
pub_core_basics.h \
+ pub_core_commandline.h \
pub_core_cpuid.h \
pub_core_debuginfo.h \
pub_core_debugger.h \
@@ -94,9 +95,11 @@
=20
valgrind_SOURCES =3D \
m_launcher.c \
+ m_commandline.c \
m_debuglog.c
=20
libcoregrind_a_SOURCES =3D \
+ m_commandline.c \
m_cpuid.S \
m_debugger.c \
m_debuglog.c \
Added: branches/ASPACEM/coregrind/m_commandline.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_commandline.c 2005-08-28 16:29:25 UTC (r=
ev 4552)
+++ branches/ASPACEM/coregrind/m_commandline.c 2005-08-28 18:54:17 UTC (r=
ev 4553)
@@ -0,0 +1,253 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Command line handling. m_commandline.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "pub_core_basics.h"
+#include "pub_core_commandline.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcfile.h"
+#include "pub_core_libcprint.h"
+#include "pub_core_libcproc.h"
+#include "pub_core_mallocfree.h"
+#include "pub_core_options.h"
+
+// Note that we deliberately don't free the malloc'd memory. See commen=
t
+// at call site.
+static char* get_file_clo(char* dir)
+{
+ Int n;
+ SysRes fd;
+ struct vki_stat s1;
+ Char* f_clo =3D NULL;
+ Char filename[VKI_PATH_MAX];
+
+ VG_(snprintf)(filename, VKI_PATH_MAX, "%s/.valgrindrc",=20
+ ( NULL =3D=3D dir ? "" : dir ) );
+ fd =3D VG_(open)(filename, 0, VKI_S_IRUSR);
+ if ( !fd.isError ) {
+ if ( 0 =3D=3D VG_(fstat)(fd.val, &s1) ) {
+ f_clo =3D VG_(malloc)(s1.st_size+1);
+ vg_assert(f_clo);
+ n =3D VG_(read)(fd.val, f_clo, s1.st_size);
+ if (n =3D=3D -1) n =3D 0;
+ f_clo[n] =3D '\0';
+ }
+ VG_(close)(fd.val);
+ }
+ return f_clo;
+}
+
+static Int count_args(char* s)
+{
+ Int n =3D 0;
+ if (s) {
+ char* cp =3D s;
+ while (True) {
+ // We have alternating sequences: blanks, non-blanks, blanks...
+ // count the non-blanks sequences.
+ while ( VG_(isspace)(*cp) ) cp++;
+ if ( !*cp ) break;
+ n++;
+ while ( !VG_(isspace)(*cp) && *cp ) cp++;
+ }
+ }
+ return n;
+}
+
+// Add args out of environment, skipping multiple spaces and "--" args.
+// We split 's' into multiple strings by replacing whitespace with nuls,
+// eg. "--aa --bb --cc" --> "--aa\0--bb\0--cc". And for each new string
+// carved out of 's', we put a pointer to it in 'to'.
+static char** copy_args( char* s, char** to )
+{
+ if (s) {
+ char* cp =3D s;
+ while (True) {
+ // We have alternating sequences: blanks, non-blanks, blanks...
+ // copy the non-blanks sequences, and add terminating '\0'
+ while ( VG_(isspace)(*cp) ) cp++;
+ if ( !*cp ) break;
+ *to++ =3D cp;
+ while ( !VG_(isspace)(*cp) && *cp ) cp++;
+ if ( *cp ) *cp++ =3D '\0'; // terminate if not the l=
ast
+ if (VG_STREQ(to[-1], "--")) to--; // undo any '--' arg
+ }
+ }
+ return to;
+}
+
+// Augment command line with arguments from environment and .valgrindrc
+// files.
+static void augment_command_line(Int* vg_argc_inout, char*** vg_argv_ino=
ut)
+{
+ int vg_argc0 =3D *vg_argc_inout;
+ char** vg_argv0 =3D *vg_argv_inout;
+
+ // get_file_clo() allocates the return value with malloc(). We do no=
t
+ // free f1_clo and f2_clo as they get put into vg_argv[] which must p=
ersist.
+ char* env_clo =3D VG_(getenv)(VALGRINDOPTS);
+ char* f1_clo =3D get_file_clo( VG_(getenv)("HOME") );
+ char* f2_clo =3D get_file_clo(".");
+
+ /* copy any extra args from file or environment, if present */
+ if ( (env_clo && *env_clo) || (f1_clo && *f1_clo) || (f2_clo && *f2_c=
lo) ) {
+ /* ' ' separated extra options */
+ char **from;
+ char **to;
+ int orig_arg_count, env_arg_count, f1_arg_count, f2_arg_count;
+
+ for ( orig_arg_count =3D 0; vg_argv0[orig_arg_count]; orig_arg_cou=
nt++ );
+
+ env_arg_count =3D count_args(env_clo);
+ f1_arg_count =3D count_args(f1_clo);
+ f2_arg_count =3D count_args(f2_clo);
+
+ if (0)
+ VG_(printf)("extra-argc=3D%d %d %d\n",
+ env_arg_count, f1_arg_count, f2_arg_count);
+
+ /* +2: +1 for null-termination, +1 for added '--' */
+ from =3D vg_argv0;
+ vg_argv0 =3D VG_(malloc)( (orig_arg_count + env_arg_count + f1_arg=
_count=20
+ + f2_arg_count + 2) * sizeof(char **));
+ vg_assert(vg_argv0);
+ to =3D vg_argv0;
+
+ /* copy argv[0] */
+ *to++ =3D *from++;
+
+ /* Copy extra args from env var and file, in the order: ~/.valgrin=
drc,
+ * $VALGRIND_OPTS, ./.valgrindrc -- more local options are put lat=
er
+ * to override less local ones. */
+ to =3D copy_args(f1_clo, to);
+ to =3D copy_args(env_clo, to);
+ to =3D copy_args(f2_clo, to);
+ =20
+ /* copy original arguments, stopping at command or -- */
+ while (*from) {
+ if (**from !=3D '-')
+ break;
+ if (VG_STREQ(*from, "--")) {
+ from++; /* skip -- */
+ break;
+ }
+ *to++ =3D *from++;
+ }
+
+ /* add -- */
+ *to++ =3D "--";
+
+ vg_argc0 =3D to - vg_argv0;
+
+ /* copy rest of original command line, then NULL */
+ while (*from) *to++ =3D *from++;
+ *to =3D NULL;
+ }
+
+ *vg_argc_inout =3D vg_argc0;
+ *vg_argv_inout =3D vg_argv0;
+}
+
+void VG_(get_command_line)( int argc, char** argv,
+ Int* vg_argc_out, Char*** vg_argv_out,=20
+ char*** cl_argv_out )
+{
+ int vg_argc0;
+ char** vg_argv0;
+ char** cl_argv;
+ char* env_clo =3D VG_(getenv)(VALGRINDCLO);
+
+ if (env_clo !=3D NULL && *env_clo !=3D '\0') {
+ char *cp;
+ char **cpp;
+
+ /* OK, VALGRINDCLO is set, which means we must be a child of anoth=
er
+ Valgrind process using --trace-children, so we're getting all o=
ur
+ arguments from VALGRINDCLO, and the entire command line belongs=
to
+ the client (including argv[0]) */
+ vg_argc0 =3D 1; /* argv[0] */
+ for (cp =3D env_clo; *cp; cp++)
+ if (*cp =3D=3D VG_CLO_SEP)
+ vg_argc0++;
+
+ vg_argv0 =3D VG_(malloc)(sizeof(char **) * (vg_argc0 + 1));
+ vg_assert(vg_argv0);
+
+ cpp =3D vg_argv0;
+
+ *cpp++ =3D "valgrind"; /* nominal argv[0] */
+ *cpp++ =3D env_clo;
+
+ // Replace the VG_CLO_SEP args separator with '\0'
+ for (cp =3D env_clo; *cp; cp++) {
+ if (*cp =3D=3D VG_CLO_SEP) {
+ *cp++ =3D '\0'; /* chop it up in place */
+ *cpp++ =3D cp;
+ }
+ }
+ *cpp =3D NULL;
+ cl_argv =3D argv;
+
+ } else {
+ Bool noaugment =3D False;
+
+ /* Count the arguments on the command line. */
+ vg_argv0 =3D argv;
+
+ for (vg_argc0 =3D 1; vg_argc0 < argc; vg_argc0++) {
+ Char* arg =3D argv[vg_argc0];
+ if (arg[0] !=3D '-') /* exe name */
+ break;
+ if (VG_STREQ(arg, "--")) { /* dummy arg */
+ vg_argc0++;
+ break;
+ }
+ VG_BOOL_CLO(arg, "--command-line-only", noaugment)
+ }
+ cl_argv =3D &argv[vg_argc0];
+
+ /* Get extra args from VALGRIND_OPTS and .valgrindrc files.
+ Note we don't do this if getting args from VALGRINDCLO, as=20
+ those extra args will already be present in VALGRINDCLO.
+ (We also don't do it when --command-line-only=3Dyes.) */
+ if (!noaugment)
+ augment_command_line(&vg_argc0, &vg_argv0);
+ }
+
+ if (0) {
+ Int i;
+ for (i =3D 0; i < vg_argc0; i++)
+ VG_(printf)("vg_argv0[%d]=3D\"%s\"\n", i, vg_argv0[i]);
+ }
+
+ *vg_argc_out =3D vg_argc0;
+ *vg_argv_out =3D (Char**)vg_argv0;
+ *cl_argv_out =3D cl_argv;
+}
Modified: branches/ASPACEM/coregrind/m_launcher.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_launcher.c 2005-08-28 16:29:25 UTC (rev =
4552)
+++ branches/ASPACEM/coregrind/m_launcher.c 2005-08-28 18:54:17 UTC (rev =
4553)
@@ -28,6 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
=20
+#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,17 +36,26 @@
#include <unistd.h>
=20
#include "pub_core_basics.h"
+#include "pub_core_commandline.h"
#include "pub_core_debuglog.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcfile.h"
+#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h" // For VALGRINDLIB
+#include "pub_core_mallocfree.h"
=20
/* Where we expect to find all our aux files */
static const char *valgrind_lib =3D VG_LIBDIR;
=20
int main(int argc, char** argv, char** envp)
{
+ int i, loglevel;
+ Int vg_argc;
+ Char **vg_argv;
+ char **cl_argv;
const char *toolname =3D NULL;
const char *cp;
- int i, loglevel;
char *toolfile;
=20
/* Start the debugging-log system ASAP. First find out how many=20
@@ -58,14 +68,22 @@
break;
if (0 =3D=3D strcmp(argv[i], "-d"))=20
loglevel++;
- if (0 =3D=3D strncmp(argv[i], "--tool=3D", 7))=20
- toolname =3D argv[i] + 7;
}
=20
/* ... and start the debug logger. Now we can safely emit logging
messages all through startup. */
VG_(debugLog_startup)(loglevel, "Stage 1");
=20
+ /* Get the full command line */
+ VG_(get_command_line)(argc, argv, &vg_argc, &vg_argv, &cl_argv);
+
+ /* Look for a --tool switch */
+ for (i =3D 1; i < vg_argc; i++) {
+ if (0 =3D=3D strncmp(vg_argv[i], "--tool=3D", 7))=20
+ toolname =3D vg_argv[i] + 7;
+ }
+
+ /* Make sure we know which tool we're using */
if (toolname) {
VG_(debugLog)(1, "stage1", "tool %s requested\n", toolname);
} else {
@@ -89,3 +107,102 @@
=20
exit(1);
}
+
+void* VG_(malloc) ( SizeT nbytes )
+{
+ return malloc(nbytes);
+}
+
+Bool VG_(isspace) ( Char c )
+{
+ return isspace(c);
+}
+
+Int VG_(strcmp) ( const Char* s1, const Char* s2 )
+{
+ return strcmp(s1, s2);
+}
+
+Char *VG_(getenv)(Char *varname)
+{
+ return getenv(varname);
+}
+
+SysRes VG_(open) ( const Char* pathname, Int flags, Int mode )
+{
+ SysRes res;
+ Int fd;
+ if ((fd =3D open(pathname, flags, mode)) < 0) {
+ res.isError =3D True;
+ res.val =3D errno;
+ } else {
+ res.isError =3D False;
+ res.val =3D fd;
+ }
+ return res;
+}
+
+void VG_(close) ( Int fd )
+{
+ close(fd);
+ return;
+}
+
+Int VG_(read) ( Int fd, void* buf, Int count)
+{
+ return read(fd, buf, count);
+}
+
+Int VG_(fstat) ( Int fd, struct vki_stat* buf )
+{
+ return fstat(fd, buf);
+}
+
+UInt VG_(snprintf) ( Char* buf, Int size, const HChar *format, ... )
+{
+ va_list vargs;
+ UInt n;
+
+ va_start(vargs, format);
+ n =3D vsnprintf(buf, size, format, vargs);
+ va_end(vargs);
+
+ return n;
+}
+
+void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file,=
=20
+ Int line, const Char* fn, const HChar* format, .=
.. )
+{
+ va_list vargs;
+ Char buf[256];
+
+ va_start(vargs, format);
+ vsprintf(buf, format, vargs);
+ va_end(vargs);
+
+ fprintf(stderr, "\nvalgrind: %s:%d (%s): Assertion '%s' failed.\n",
+ file, line, fn, expr );
+ if (!strcmp(buf, ""))
+ fprintf(stderr, "valgrind: %s\n", buf);
+
+ exit(1);
+}
+
+static Bool isterm ( Char c )
+{
+ return ( VG_(isspace)(c) || 0 =3D=3D c );
+}
+
+Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 )
+{
+ while (True) {
+ if (isterm(*s1) && isterm(*s2)) return 0;
+ if (isterm(*s1)) return -1;
+ if (isterm(*s2)) return 1;
+
+ if (*(UChar*)s1 < *(UChar*)s2) return -1;
+ if (*(UChar*)s1 > *(UChar*)s2) return 1;
+
+ s1++; s2++;
+ }
+}
Modified: branches/ASPACEM/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_main.c 2005-08-28 16:29:25 UTC (rev 4552=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-08-28 18:54:17 UTC (rev 4553=
)
@@ -34,6 +34,7 @@
#include "pub_core_threadstate.h"
#include "pub_core_debuginfo.h" // Needed for pub_core_aspacemgr :(
#include "pub_core_aspacemgr.h"
+#include "pub_core_commandline.h"
#include "pub_core_debuglog.h"
#include "pub_core_errormgr.h"
#include "pub_core_execontext.h"
@@ -299,227 +300,6 @@
}
=20
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
-/*=3D=3D=3D Command line setup =
=3D=3D=3D*/
-/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
-
-// Note that we deliberately don't free the malloc'd memory. See commen=
t
-// at call site.
-static char* get_file_clo(char* dir)
-{
- Int n;
- SysRes fd;
- struct vki_stat s1;
- Char* f_clo =3D NULL;
- Char filename[VKI_PATH_MAX];
-
- VG_(snprintf)(filename, VKI_PATH_MAX, "%s/.valgrindrc",=20
- ( NULL =3D=3D dir ? "" : dir ) );
- fd =3D VG_(open)(filename, 0, VKI_S_IRUSR);
- if ( !fd.isError ) {
- if ( 0 =3D=3D VG_(fstat)(fd.val, &s1) ) {
- f_clo =3D VG_(malloc)(s1.st_size+1);
- vg_assert(f_clo);
- n =3D VG_(read)(fd.val, f_clo, s1.st_size);
- if (n =3D=3D -1) n =3D 0;
- f_clo[n] =3D '\0';
- }
- VG_(close)(fd.val);
- }
- return f_clo;
-}
-
-static Int count_args(char* s)
-{
- Int n =3D 0;
- if (s) {
- char* cp =3D s;
- while (True) {
- // We have alternating sequences: blanks, non-blanks, blanks...
- // count the non-blanks sequences.
- while ( VG_(isspace)(*cp) ) cp++;
- if ( !*cp ) break;
- n++;
- while ( !VG_(isspace)(*cp) && *cp ) cp++;
- }
- }
- return n;
-}
-
-// Add args out of environment, skipping multiple spaces and "--" args.
-// We split 's' into multiple strings by replacing whitespace with nuls,
-// eg. "--aa --bb --cc" --> "--aa\0--bb\0--cc". And for each new string
-// carved out of 's', we put a pointer to it in 'to'.
-static char** copy_args( char* s, char** to )
-{
- if (s) {
- char* cp =3D s;
- while (True) {
- // We have alternating sequences: blanks, non-blanks, blanks...
- // copy the non-blanks sequences, and add terminating '\0'
- while ( VG_(isspace)(*cp) ) cp++;
- if ( !*cp ) break;
- *to++ =3D cp;
- while ( !VG_(isspace)(*cp) && *cp ) cp++;
- if ( *cp ) *cp++ =3D '\0'; // terminate if not the l=
ast
- if (VG_STREQ(to[-1], "--")) to--; // undo any '--' arg
- }
- }
- return to;
-}
-
-// Augment command line with arguments from environment and .valgrindrc
-// files.
-static void augment_command_line(Int* vg_argc_inout, char*** vg_argv_ino=
ut)
-{
- int vg_argc0 =3D *vg_argc_inout;
- char** vg_argv0 =3D *vg_argv_inout;
-
- // get_file_clo() allocates the return value with malloc(). We do no=
t
- // free f1_clo and f2_clo as they get put into vg_argv[] which must p=
ersist.
- char* env_clo =3D VG_(getenv)(VALGRINDOPTS);
- char* f1_clo =3D get_file_clo( VG_(getenv)("HOME") );
- char* f2_clo =3D get_file_clo(".");
-
- /* copy any extra args from file or environment, if present */
- if ( (env_clo && *env_clo) || (f1_clo && *f1_clo) || (f2_clo && *f2_c=
lo) ) {
- /* ' ' separated extra options */
- char **from;
- char **to;
- int orig_arg_count, env_arg_count, f1_arg_count, f2_arg_count;
-
- for ( orig_arg_count =3D 0; vg_argv0[orig_arg_count]; orig_arg_cou=
nt++ );
-
- env_arg_count =3D count_args(env_clo);
- f1_arg_count =3D count_args(f1_clo);
- f2_arg_count =3D count_args(f2_clo);
-
- if (0)
- VG_(printf)("extra-argc=3D%d %d %d\n",
- env_arg_count, f1_arg_count, f2_arg_count);
-
- /* +2: +1 for null-termination, +1 for added '--' */
- from =3D vg_argv0;
- vg_argv0 =3D VG_(malloc)( (orig_arg_count + env_arg_count + f1_arg=
_count=20
- + f2_arg_count + 2) * sizeof(char **));
- vg_assert(vg_argv0);
- to =3D vg_argv0;
-
- /* copy argv[0] */
- *to++ =3D *from++;
-
- /* Copy extra args from env var and file, in the order: ~/.valgrin=
drc,
- * $VALGRIND_OPTS, ./.valgrindrc -- more local options are put lat=
er
- * to override less local ones. */
- to =3D copy_args(f1_clo, to);
- to =3D copy_args(env_clo, to);
- to =3D copy_args(f2_clo, to);
- =20
- /* copy original arguments, stopping at command or -- */
- while (*from) {
- if (**from !=3D '-')
- break;
- if (VG_STREQ(*from, "--")) {
- from++; /* skip -- */
- break;
- }
- *to++ =3D *from++;
- }
-
- /* add -- */
- *to++ =3D "--";
-
- vg_argc0 =3D to - vg_argv0;
-
- /* copy rest of original command line, then NULL */
- while (*from) *to++ =3D *from++;
- *to =3D NULL;
- }
-
- *vg_argc_inout =3D vg_argc0;
- *vg_argv_inout =3D vg_argv0;
-}
-
-#define VG_CLO_SEP '\01'
-
-static void get_command_line( int argc, char** argv,
- Int* vg_argc_out, Char*** vg_argv_out,=20
- char*** cl_argv_out )
-{
- int vg_argc0;
- char** vg_argv0;
- char** cl_argv;
- char* env_clo =3D VG_(getenv)(VALGRINDCLO);
-
- if (env_clo !=3D NULL && *env_clo !=3D '\0') {
- char *cp;
- char **cpp;
-
- /* OK, VALGRINDCLO is set, which means we must be a child of anoth=
er
- Valgrind process using --trace-children, so we're getting all o=
ur
- arguments from VALGRINDCLO, and the entire command line belongs=
to
- the client (including argv[0]) */
- vg_argc0 =3D 1; /* argv[0] */
- for (cp =3D env_clo; *cp; cp++)
- if (*cp =3D=3D VG_CLO_SEP)
- vg_argc0++;
-
- vg_argv0 =3D VG_(malloc)(sizeof(char **) * (vg_argc0 + 1));
- vg_assert(vg_argv0);
-
- cpp =3D vg_argv0;
-
- *cpp++ =3D "valgrind"; /* nominal argv[0] */
- *cpp++ =3D env_clo;
-
- // Replace the VG_CLO_SEP args separator with '\0'
- for (cp =3D env_clo; *cp; cp++) {
- if (*cp =3D=3D VG_CLO_SEP) {
- *cp++ =3D '\0'; /* chop it up in place */
- *cpp++ =3D cp;
- }
- }
- *cpp =3D NULL;
- cl_argv =3D argv;
-
- } else {
- Bool noaugment =3D False;
-
- /* Count the arguments on the command line. */
- vg_argv0 =3D argv;
-
- for (vg_argc0 =3D 1; vg_argc0 < argc; vg_argc0++) {
- Char* arg =3D argv[vg_argc0];
- if (arg[0] !=3D '-') /* exe name */
- break;
- if (VG_STREQ(arg, "--")) { /* dummy arg */
- vg_argc0++;
- break;
- }
- VG_BOOL_CLO(arg, "--command-line-only", noaugment)
- }
- cl_argv =3D &argv[vg_argc0];
-
- /* Get extra args from VALGRIND_OPTS and .valgrindrc files.
- Note we don't do this if getting args from VALGRINDCLO, as=20
- those extra args will already be present in VALGRINDCLO.
- (We also don't do it when --command-line-only=3Dyes.) */
- if (!noaugment)
- augment_command_line(&vg_argc0, &vg_argv0);
- }
-
- if (0) {
- Int i;
- for (i =3D 0; i < vg_argc0; i++)
- VG_(printf)("vg_argv0[%d]=3D\"%s\"\n", i, vg_argv0[i]);
- }
-
- *vg_argc_out =3D vg_argc0;
- *vg_argv_out =3D (Char**)vg_argv0;
- *cl_argv_out =3D cl_argv;
-}
-
-
-/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
/*=3D=3D=3D Environment and stack setup =
=3D=3D=3D*/
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
@@ -2365,7 +2145,7 @@
// p: none
//--------------------------------------------------------------
VG_(debugLog)(1, "main", "Preprocess command line opts\n");
- get_command_line(argc, argv, &vg_argc, &vg_argv, &cl_argv);
+ VG_(get_command_line)(argc, argv, &vg_argc, &vg_argv, &cl_argv);
pre_process_cmd_line_options(&need_help, &tool, &exec);
=20
/* If this process was created by exec done by another Valgrind
Added: branches/ASPACEM/coregrind/pub_core_commandline.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_commandline.h 2005-08-28 16:29:25=
UTC (rev 4552)
+++ branches/ASPACEM/coregrind/pub_core_commandline.h 2005-08-28 18:54:17=
UTC (rev 4553)
@@ -0,0 +1,44 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Command line handling. pub_core_commandline.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_COMMANDLINE_H
+#define __PUB_CORE_COMMANDLINE_H
+
+#define VG_CLO_SEP '\01'
+
+extern void VG_(get_command_line)( int argc, char** argv,
+ Int* vg_argc_out, Char*** vg_argv_out=
,=20
+ char*** cl_argv_out=
);
+
+#endif // __PUB_CORE_COMMANDLINE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
|