diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2015-07-06 16:41:55 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2015-07-06 19:02:20 +0100 |
commit | 59f21c4d124373cea4cb98e976704d4b2da900b3 (patch) | |
tree | 0c87425d429042d9707d47c855d0a16837e272b9 | |
parent | 7383464db0ec6fd64a2f8e9372be495df11fd05e (diff) |
inject: Allow to control verbosity via a command line option.
-rw-r--r-- | cli/cli_trace.cpp | 9 | ||||
-rw-r--r-- | inject/inject.h | 1 | ||||
-rw-r--r-- | inject/injectee.cpp | 4 | ||||
-rw-r--r-- | inject/injector.cpp | 22 |
4 files changed, 26 insertions, 10 deletions
diff --git a/cli/cli_trace.cpp b/cli/cli_trace.cpp index 5875057a..d7ed3439 100644 --- a/cli/cli_trace.cpp +++ b/cli/cli_trace.cpp @@ -92,7 +92,7 @@ static int traceProgram(trace::API api, char * const *argv, const char *output, - bool verbose, + int verbose, bool debug) { const char *wrapperFilename; @@ -155,6 +155,9 @@ traceProgram(trace::API api, if (debug) { args.push_back("-d"); } + for (int i = 1; i < verbose; ++i) { + args.push_back("-v"); + } args.push_back("-D"); args.push_back(wrapperPath); args.push_back("--"); @@ -345,7 +348,7 @@ longOptions[] = { static int command(int argc, char *argv[]) { - bool verbose = false; + int verbose = 0; trace::API api = trace::API_GL; const char *output = NULL; bool debug = false; @@ -357,7 +360,7 @@ command(int argc, char *argv[]) usage(); return 0; case 'v': - verbose = true; + ++verbose; break; case 'a': if (strcmp(optarg, "gl") == 0) { diff --git a/inject/inject.h b/inject/inject.h index e72dfeca..3c823d92 100644 --- a/inject/inject.h +++ b/inject/inject.h @@ -133,6 +133,7 @@ getModuleName(char *szModuleName, size_t n, const char *szFilename) { struct SharedMem { BOOL bReplaced; + char cVerbosity; char szDllName[4096 - sizeof(BOOL)]; }; diff --git a/inject/injectee.cpp b/inject/injectee.cpp index 42d152e2..0814da24 100644 --- a/inject/injectee.cpp +++ b/inject/injectee.cpp @@ -54,7 +54,7 @@ #include "inject.h" -#define VERBOSITY 0 +static int VERBOSITY = 0; #define NOOP 0 @@ -1037,6 +1037,8 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) return FALSE; } + VERBOSITY = pSharedMem->cVerbosity; + static char szSharedMemCopy[MAX_PATH]; strncpy(szSharedMemCopy, pSharedMem->szDllName, _countof(szSharedMemCopy) - 1); szSharedMemCopy[_countof(szSharedMemCopy) - 1] = '\0'; diff --git a/inject/injector.cpp b/inject/injector.cpp index a734a0be..43d7dad3 100644 --- a/inject/injector.cpp +++ b/inject/injector.cpp @@ -454,13 +454,17 @@ help(void) } +static const char *short_options = +"hdD:p:t:v"; + static const struct option long_options[] = { - { "help", 0, NULL, 'h'}, - { "debug", 0, NULL, 'd'}, - { "dll", 1, NULL, 'D'}, - { "pid", 1, NULL, 'p'}, - { "tid", 1, NULL, 't'}, + { "help", no_argument, NULL, 'h'}, + { "debug", no_argument, NULL, 'd'}, + { "dll", required_argument, NULL, 'D'}, + { "pid", required_argument, NULL, 'p'}, + { "tid", required_argument, NULL, 't'}, + { "verbose", no_argument, 0, 'v'}, { NULL, 0, NULL, 0} }; @@ -472,12 +476,13 @@ main(int argc, char *argv[]) BOOL bAttach = FALSE; DWORD dwProcessId = 0; DWORD dwThreadId = 0; + char cVerbosity = 0; const char *szDll = NULL; int option_index = 0; while (true) { - int opt = getopt_long_only(argc, argv, "hdD:p:t:", long_options, &option_index); + int opt = getopt_long_only(argc, argv, short_options, long_options, &option_index); if (opt == -1) { break; } @@ -499,6 +504,9 @@ main(int argc, char *argv[]) dwThreadId = strtoul(optarg, NULL, 0); bAttach = TRUE; break; + case 'v': + ++cVerbosity; + break; default: debugPrintf("inject: invalid option '%c'\n", optopt); help(); @@ -559,6 +567,8 @@ main(int argc, char *argv[]) return 1; } + pSharedMem->cVerbosity = cVerbosity; + strncpy(pSharedMem->szDllName, szDll, _countof(pSharedMem->szDllName) - 1); pSharedMem->szDllName[_countof(pSharedMem->szDllName) - 1] = '\0'; } |