public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* Patch: Add Option Groups
@ 2008-03-18 17:41 Phil Muldoon
  2008-03-18 18:28 ` Tom Tromey
  2008-03-18 20:11 ` Andrew Cagney
  0 siblings, 2 replies; 11+ messages in thread
From: Phil Muldoon @ 2008-03-18 17:41 UTC (permalink / raw)
  To: Frysk Hackers

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

I wanted to add option groups to fcore, and also make sure that the 
utility options come first.  I've included a draft patch.

This came up in conversation with Tom and Andrew. This required a little 
bit of hacking in bindir/fcore, util/CommandlineParser and 
util/ProcStopUntil. I've added the output and the patch that makes this 
happen. I have not checked it in. Please pay special attention to my 
comments around parse() as I am not sure this is the best place to add 
the default options. They have to be added "late" otherwise they will be 
added at the top of the --help output. There is a lot of weird indenting 
going on in the right help column, but this was happening beforehand and 
is another unrelated (but hopefully soon to be fixed) bug.

./frysk_bin/frysk-core/frysk/bindir/fcore --help

Usage: fcore <PID>

Corefile options:
  -a, -allmaps                   Include ALL process readable maps.
  -s, -segments =PATTERN        use PATTERN as regex to define maps 
inclusion.
  -o, -outputfile <filename>     Sets the name of  the corefile.

Frysk specific options:
  -debug <COMP=LEVEL,...>       Set debug-tracing of COMP to LEVEL.
                                  LEVEL can be [ NONE | FINE | FINEST ];
                                  default is FINE.
                                  Example: debug frysk.rsl=FINE
  -noexe                        Do not attempt to read an executable for a
                                  corefile
  -exe <executable>             Specify the full path of the executable 
to read
  -sysroot <path to sysroot>    Special root directory

Standard options:
  -help       print this help, then exit
  -version    print version number, then exit

Regards

Phil

[-- Attachment #2: options.patch --]
[-- Type: text/x-patch, Size: 7791 bytes --]

diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 3606ba8..60dcaf2 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-03-18  Phil Muldoon  <pmuldoon@redhat.com>
+
+	* fcore.java (addOptions): Add new group.
+	Add options to group and tweak text.
+
 2008-03-17  Andrew Cagney  <cagney@redhat.com>
 
 	* fstep.java: Update; using TaskAttachedObserverXXX.
diff --git a/frysk-core/frysk/bindir/fcore.java b/frysk-core/frysk/bindir/fcore.java
index a5d8862..07190c8 100644
--- a/frysk-core/frysk/bindir/fcore.java
+++ b/frysk-core/frysk/bindir/fcore.java
@@ -48,6 +48,7 @@ import frysk.util.ProcStopUtil;
 import frysk.isa.corefiles.LinuxElfCorefile;
 import frysk.isa.corefiles.LinuxElfCorefileFactory;
 import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionGroup;
 import gnu.classpath.tools.getopt.OptionException;
 
 
@@ -80,12 +81,12 @@ public class fcore {
      */
     private static void addOptions (ProcStopUtil fcore)
     {
+	
+      OptionGroup group = new OptionGroup("Corefile options");
+      fcore.addGroup(group);
 
-      fcore.addOption(new Option( "allmaps", 'a',
-	                          " Writes all readable maps. Does not elide"
-	                        + " or omit any readable map. Caution: could"
-	                        + " take considerable amount of time to"
-	                        + " construct core file.")
+      group.add(new Option( "allmaps", 'a',
+	                          " Include ALL process readable maps.")
 	  {
 	      public void parsed (String mapsValue) throws OptionException {
 		  try {
@@ -98,9 +99,10 @@ public class fcore {
 	      }
 	  });
       
-      fcore.addOption(new Option("segments", 's',
-				 "Define what segments to include via regex.",
-				 "RegEx") {
+      group.add(new Option("segments", 's',
+				 "Use PATTERN as regex to define "+
+				 "maps inclusion.",
+				 "=PATTERN") {
 	      public void parsed(String regEx) throws OptionException {
 		  try {
 		      mapOptionCount++;
@@ -114,10 +116,9 @@ public class fcore {
       
       
 
-      fcore.addOption(new Option( "outputfile", 'o',
-	                          " Sets the name (not extension) of the core"
-	                        + " file. Default is core.{pid}. The extension"
-				  + " will always be the pid.", "<filename>")
+      group.add(new Option( "outputfile", 'o',
+	                          " Sets the name of  the " +
+	                          "corefile.", "<filename>")
 	  {
 	      public void parsed (String filenameValue) throws OptionException {
 		  try {
@@ -141,8 +142,8 @@ public class fcore {
 	    
 	  
 	    if (mapOptionCount > 1)
-		System.err.println("Please either speciy -stackonly,"+
-		" -allmaps, or -match <pattern> for map writing.");
+		System.err.println("Please either specify "+
+		" -allmaps, or -segments=PATTERN for map writing.");
 	    else {
 		Task[] tasks = (Task[]) proc.getTasks().toArray
 	                   (new Task[proc.getTasks().size()]);
@@ -168,7 +169,7 @@ public class fcore {
 	}
 	
 	public void executeDead(Proc proc) {
-	    System.err.println ("Cannot create core file from dead process");
+	    System.err.println ("Cannot create core file from a dead process.");
 	}
     }
 }
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 1ddb337..ebf40a3 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,5 +1,12 @@
 2008-03-18  Phil Muldoon  <pmuldoon@redhat.com>
 
+	* CommandlineParser.java: (addDefaultOptions): New.
+	(parse): Set default options here.
+	(CommandlineParser): Move default option
+	creation to addDefaultOptions.
+	* ProcStopUtil.java (addGroup): New.
+	
+
 	* CommandlineParser.java (CommandlineParser): Trim
 	Sys Root help output.
 
diff --git a/frysk-core/frysk/util/CommandlineParser.java b/frysk-core/frysk/util/CommandlineParser.java
index 949c061..81ade30 100644
--- a/frysk-core/frysk/util/CommandlineParser.java
+++ b/frysk-core/frysk/util/CommandlineParser.java
@@ -46,6 +46,7 @@ import lib.dwfl.Elf;
 import lib.dwfl.ElfCommand;
 import lib.dwfl.ElfEHeader;
 import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionGroup;
 import gnu.classpath.tools.getopt.OptionException;
 import gnu.classpath.tools.getopt.Parser;
 import frysk.rsl.LogOption;
@@ -68,27 +69,6 @@ public class CommandlineParser {
 
     public CommandlineParser(String name, String version) {
 	parser = new Parser(name, version, true);
-	parser.add(new LogOption("debug"));
-	add(new Option("noexe", "Do not attempt to read an"+
-		       " executable for a corefile ") {
-		public void parsed(String exeValue) throws OptionException {
-		    extendedCore = false;
-		    explicitExe = null;
-		}
-	    });
-	add(new Option("exe",
-		       "Specify the full path of the executable to read",
-		       "<executable>") {
-		public void parsed(String exeValue) throws OptionException {
-		    extendedCore = true;
-		    explicitExe = exeValue;
-		}
-	    });
-	add(new Option("sysroot", "Special root directory", "<path to sysroot>") {
-		public void parsed(String arg) throws OptionException {
-		    parseSysRoot(arg);
-		}
-	    });
     }
 
     public CommandlineParser(String programName) {
@@ -138,6 +118,11 @@ public class CommandlineParser {
     }
 
     public String[] parse(String[] args) {
+	
+	// Add in default options here.
+	// This is to preserve the user options as "first"
+	// Seems the wrong place to do it
+	addDefaultOptions();
 	try {
 	    fine.log(this, "parse", args);
 	    String[] result = doParse(args);
@@ -259,6 +244,32 @@ public class CommandlineParser {
 
     }
 
+    private void addDefaultOptions () {
+	OptionGroup defaultGroup = new OptionGroup("Frysk specific options");
+	add(defaultGroup);
+	defaultGroup.add(new LogOption("debug"));
+	defaultGroup.add(new Option("noexe", "Do not attempt to read an"+
+				    " executable for a corefile ") {
+		public void parsed(String exeValue) throws OptionException {
+		    extendedCore = false;
+		    explicitExe = null;
+		}
+	    });
+	defaultGroup.add(new Option("exe",
+				    "Specify the full path of the executable to read",
+				    "<executable>") {
+		public void parsed(String exeValue) throws OptionException {
+		    extendedCore = true;
+		    explicitExe = exeValue;
+		}
+	    });
+	defaultGroup.add(new Option("sysroot", "Special root directory", "<path to sysroot>") {
+		public void parsed(String arg) throws OptionException {
+		    parseSysRoot(arg);
+		}
+	    });
+	
+    }
     // @Override
     protected void validate() throws OptionException {
 	// Base implementation does nothing.
@@ -272,6 +283,10 @@ public class CommandlineParser {
 	parser.add(option);
     }
 
+    public void add(OptionGroup option) {
+	parser.add(option);
+    }
+
     public void printHelp() {
 	parser.printHelp();
     }
diff --git a/frysk-core/frysk/util/ProcStopUtil.java b/frysk-core/frysk/util/ProcStopUtil.java
index af231ed..555997b 100644
--- a/frysk-core/frysk/util/ProcStopUtil.java
+++ b/frysk-core/frysk/util/ProcStopUtil.java
@@ -48,6 +48,7 @@ import frysk.proc.ProcBlockObserver;
 import frysk.proc.Task;
 import frysk.util.CommandlineParser;
 import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionGroup;
 import frysk.rsl.Log;
 
 /**
@@ -113,6 +114,10 @@ public class ProcStopUtil {
     public void addOption (Option option) {
 	parser.add (option);
     }
+
+    public void addGroup (OptionGroup option) {
+	parser.add (option);
+    }
     
     public void execute () {
 	parser.parse(args);
@@ -168,4 +173,4 @@ public class ProcStopUtil {
 	    System.exit(0);
 	}
     }
-}
\ No newline at end of file
+}

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-04-01 21:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-18 17:41 Patch: Add Option Groups Phil Muldoon
2008-03-18 18:28 ` Tom Tromey
2008-03-19  7:51   ` Phil Muldoon
2008-03-19 13:23     ` Tom Tromey
2008-03-18 20:11 ` Andrew Cagney
2008-03-19  7:46   ` Phil Muldoon
2008-03-20 11:52     ` Andrew Cagney
2008-03-20 14:23       ` Tom Tromey
2008-03-20 16:09         ` Andrew Cagney
2008-03-20 18:06           ` Tom Tromey
2008-04-01 21:36             ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).