From e9c296ba6d779ab24d5bdf19ce214e685a8eba91 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Fri, 7 Aug 2009 23:19:09 +0000 Subject: [PATCH] callgrind_control: be strict on parsing options Get rid of "-v" as short form of "--version". Also, help text for dumps/instrumentation shows only the long versions now. However, '-i on' or '-d dump now!' is still possible. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10754 --- callgrind/callgrind_control.in | 137 +++++++++++++++++++++++++-------- callgrind/docs/cl-manual.xml | 14 ++-- 2 files changed, 110 insertions(+), 41 deletions(-) diff --git a/callgrind/callgrind_control.in b/callgrind/callgrind_control.in index 02af9afb33..74df0317c0 100644 --- a/callgrind/callgrind_control.in +++ b/callgrind/callgrind_control.in @@ -84,21 +84,21 @@ sub shortHelp { sub printHelp { printHeader; - print "Usage: callgrind_control [options] [ | ...]\n\n"; - print "If no PIDs/Names are given, an action is applied to all currently\n"; + print "Usage: callgrind_control [options] [| ...]\n\n"; + print "If no pids/names are given, an action is applied to all currently\n"; print "active Callgrind runs. Default action is printing short information.\n\n"; print "Options:\n"; - print " -h --help Show this help text\n"; - print " -v --version Show version\n"; - print " -l --long Show more information\n"; - print " -s --stat Show statistics\n"; - print " -b --back Show stack/back trace\n"; - print " -e [A, ...] Show event counters for A, ... (default: all)\n"; - print " -d --dump [s] Request a profile dump using as description\n"; - print " -z --zero Zero all event counters\n"; - print " -k --kill Kill\n"; - print " -i [on|off] Switch instrumentation state on/off (default: on)\n"; - print " -w Specify the startup directory of an active callgrind run\n"; + print " -h --help Show this help text\n"; + print " --version Show version\n"; + print " -l --long Show more information\n"; + print " -s --stat Show statistics\n"; + print " -b --back Show stack/back trace\n"; + print " -e [,...] Show event counters for ,... (default: all)\n"; + print " --dump[=] Request a dump optionally using as description\n"; + print " -z --zero Zero all event counters\n"; + print " -k --kill Kill\n"; + print " --instr= Switch instrumentation state on/off\n"; + print " -w= Specify the startup directory of an active Callgrind run\n"; print "\n"; exit; } @@ -223,20 +223,76 @@ foreach $arg (@ARGV) { if ($requestEvents == 1) { $requestEvents = 2; } if ($gotW == 1) { $gotW = 2; } - if ($arg =~ /^-?-h/) { printHelp; } - if ($arg =~ /^-?-v/) { printVersion; } - if ($arg =~ /^-?-l/) { $printLong = 1; next; } - if ($arg =~ /^-?-s/) { $printStatus = 1; next; } - if ($arg =~ /^-?-b/) { $printBacktrace = 1; next; } - if ($arg =~ /^-e/) { $requestEvents = 1; next; } - if ($arg =~ /^-?-d/) { $requestDump = 1; next; } - if ($arg =~ /^-?-z/) { $requestZero = 1; next; } - if ($arg =~ /^-?-k/) { $requestKill = 1; next; } - if ($arg =~ /^-?-i/) { $switchInstr = 1; $switchInstrMode = "+"; next; } - if ($arg =~ /^-w/) { $gotW = 1; next; } - - print "Error: unknown command line option '$arg'.\n"; - shortHelp; + if ($arg =~ /^(-h|--help)$/) { + printHelp; + } + elsif ($arg =~ /^--version$/) { + printVersion; + } + elsif ($arg =~ /^(-l|--long)$/) { + $printLong = 1; + next; + } + elsif ($arg =~ /^(-s|--stat)$/) { + $printStatus = 1; + next; + } + elsif ($arg =~ /^(-b|--back)$/) { + $printBacktrace = 1; + next; + } + elsif ($arg =~ /^-e$/) { + $requestEvents = 1; + next; + } + elsif ($arg =~ /^(-d|--dump)(|=.*)$/) { + if ($2 ne "") { + $requestDump = 2; + $dumpHint = substr($2,1); + } + else { + # take next argument as dump hint + $requestDump = 1; + } + next; + } + elsif ($arg =~ /^(-z|--zero)$/) { + $requestZero = 1; + next; + } + elsif ($arg =~ /^(-k|--kill)$/) { + $requestKill = 1; + next; + } + elsif ($arg =~ /^(-i|--instr)(|=on|=off)$/) { + $switchInstr = 2; + if ($2 eq "=on") { + $switchInstrMode = "+"; + } + elsif ($2 eq "=off") { + $switchInstrMode = "-"; + } + else { + # check next argument for "on" or "off" + $switchInstr = 1; + } + next; + } + elsif ($arg =~ /^-w(|=.*)$/) { + if ($1 ne "") { + $gotW = 2; + $workingDir = substr($1,1); + } + else { + # take next argument as working directory + $gotW = 1; + } + next; + } + else { + print "Error: unknown command line option '$arg'.\n"; + shortHelp; + } } if ($arg =~ /^[A-Za-z_]/) { @@ -255,8 +311,15 @@ foreach $arg (@ARGV) { if ($switchInstr == 1) { $switchInstr = 2; - if (($arg eq "off") || ($arg eq "no")) { - $switchInstrMode = "-"; + if ($arg eq "on") { + $switchInstrMode = "+"; + } + elsif ($arg eq "off") { + $switchInstrMode = "-"; + } + else { + print "Error: need to specify 'on' or 'off' after '-i'.\n"; + shortHelp; } next; } @@ -265,10 +328,6 @@ foreach $arg (@ARGV) { if ($gotW == 1) { $gotW = 2; $workingDir = $arg; - if (!-d $workingDir) { - print "Error: directory '$workingDir' does not exist.\n"; - shortHelp; - } next; } @@ -287,11 +346,21 @@ foreach $arg (@ARGV) { } if ($gotW == 1) { - print "Error: no directory specified after -w.\n"; + print "Error: no directory specified after '-w'.\n"; + shortHelp; +} + +if ($switchInstr == 1) { + print "Error: need to specify 'on' or 'off' after '-i'.\n"; shortHelp; } if ($workingDir ne "") { + if (!-d $workingDir) { + print "Error: directory '$workingDir' does not exist.\n"; + shortHelp; + } + # Generate dummy information for dummy pid 0 $pid = "0"; $mversion{$pid} = "1.0"; diff --git a/callgrind/docs/cl-manual.xml b/callgrind/docs/cl-manual.xml index 21c8737869..6715165f42 100644 --- a/callgrind/docs/cl-manual.xml +++ b/callgrind/docs/cl-manual.xml @@ -1227,7 +1227,7 @@ their arguments. - + Show version of callgrind_control. @@ -1260,7 +1260,7 @@ their arguments. - (default: all) + (default: all) Show the current per-thread, exclusive cost values of event counters. If no explicit event names are given, figures for all event @@ -1273,17 +1273,17 @@ their arguments. - (default: empty description) + (default: no description) Request the dumping of profile information. Optionally, a - description can be specified which is written into the dump as part of + description can be specified which is written into the dump as part of the information giving the reason which triggered the dump action. This can be used to distinguish multiple dumps. - + Zero all event counters. @@ -1297,7 +1297,7 @@ their arguments. - (default: on) + Switch instrumentation mode on or off. If a Callgrind run has instrumentation disabled, no simulation is done and no events are @@ -1308,7 +1308,7 @@ their arguments. - + Specify the startup directory of an active Callgrind run. On some systems, active Callgrind runs can not be detected. To be able to -- 2.47.3