gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23986 - monkey/trunk/pathologist/src/pathologist


From: gnunet
Subject: [GNUnet-SVN] r23986 - monkey/trunk/pathologist/src/pathologist
Date: Tue, 25 Sep 2012 02:27:15 +0200

Author: teichm
Date: 2012-09-25 02:27:15 +0200 (Tue, 25 Sep 2012)
New Revision: 23986

Modified:
   monkey/trunk/pathologist/src/pathologist/pathologist.c
Log:
pathologist is now using gnunets getopt


Modified: monkey/trunk/pathologist/src/pathologist/pathologist.c
===================================================================
--- monkey/trunk/pathologist/src/pathologist/pathologist.c      2012-09-24 
22:28:21 UTC (rev 23985)
+++ monkey/trunk/pathologist/src/pathologist/pathologist.c      2012-09-25 
00:27:15 UTC (rev 23986)
@@ -29,20 +29,20 @@
 #include <sys/stat.h>
 #include "monkey_common.h"
 #include "pathologist_action.h"
+#include "gnunet_getopt_lib.h"
 
 #define MIN_ARG_REQUIRED 2
 
-static char *mode = NULL;
-static char *dumpFileName = NULL;
-static char *binaryName = NULL;
-static char *binaryArgs = NULL;
-static char *emailAddress = NULL;
-static char *edbFilePath = NULL;
-static char *gdbBinaryPath = NULL;
-static char *valgrindBinaryPath = NULL;
-static char *inspectExpression = NULL;
-static char *inspectFunction = NULL;
-static char *scopeDepth = NULL;
+static char *dumpFileName;
+static char *binaryName;
+static char *binaryArgs;
+static char *emailAddress;
+static char *edbFilePath;
+static char *gdbBinaryPath;
+static char *valgrindBinaryPath;
+static char *inspectExpression;
+static char *inspectFunction;
+static int scopeDepth;
 static int reverseExecutionAllowed = MONKEY_NO;
 static int ret = 0;
 
@@ -170,17 +170,17 @@
          MONKEY_asprintf(&dumpFileName, "%s_PID%d", bn, getpid());
     }
 
-  if (strcasecmp (mode, "email") == 0)
-    {
-      if (NULL == emailAddress)
-       {
-         fprintf( stderr,
-                     "Working in email mode requires an email address!\n");
-         MONKEY_break (0);
-         ret = 1;
-         return;
-       }
-    }
+//  if (strcasecmp (mode, "email") == 0)
+//    {
+//      if (NULL == emailAddress)
+//     {
+//       fprintf( stderr,
+//                   "Working in email mode requires an email address!\n");
+//       MONKEY_break (0);
+//       ret = 1;
+//       return;
+//     }
+//    }
 
   /* Initialize context for the Action API */
   cntxt = MONKEY_malloc (sizeof (struct MONKEY_ACTION_Context));
@@ -192,7 +192,7 @@
   cntxt->valgrind_binary_path = valgrindBinaryPath;
   cntxt->inspect_expression = inspectExpression;
   cntxt->inspect_function = inspectFunction;
-  cntxt->scope_depth = (NULL == scopeDepth) ? 0 : atoi(scopeDepth);
+  cntxt->scope_depth = scopeDepth;
   cntxt->bug_detected = NO_BUG_DETECTED;
   cntxt->has_null = MONKEY_NO;
   cntxt->xml_report_node = NULL;
@@ -248,7 +248,7 @@
                      "Error in generating debug report!\n");
          ret = 1;
        }
-      if (strcasecmp (mode, "email") == 0)
+      if (emailAddress != NULL)
        {
          if (MONKEY_OK != MONKEY_ACTION_report_email (cntxt, dumpFileName))
            {
@@ -256,9 +256,8 @@
              ret = 1;
            }
        }
-      else
+     if (dumpFileName != NULL)
        {
-         /* text mode */
          if (MONKEY_OK !=
              MONKEY_ACTION_report_file (cntxt, dumpFileName, MONKEY_YES))
            {
@@ -276,31 +275,8 @@
 }
 
 
-/* display help */
-void showHelp() {
-   printf("Monkey Pathologist: Automatically debug a service\n");
-   printf ("\t-b: binary: path to a binary file for a program to debug with 
pathologist [mandatory]\n");
-   printf ("\t-d: database: path to Expression Database file [mandatory]\n");
-   printf ("\t-m: mode: pathologist's mode of operation: options are \"text\" 
or \"email\" [mandatory]\n");
-   printf ("\t-a: address: email address to which pathologist will send debug 
report [optional]\n");
-   printf ("\t-f: function: function name at which pathologist will set a 
breakpoint [optional]\n");
-   printf ("\t-g: gdb: path to gdb binary to use. If not passed, pathologist 
will set it to /usr/bin/gdb [optional]\n");
-   printf ("\t-l: valgrind: path to valgrind binary. If not passed, 
pathologist will set it to /usr/bin/valgrind [optional]\n");
-   printf ("\t-p: depth: scope depth. How many scopes should pathologist 
lookup expression values outer than the scope in which the problem occurs.\n\t 
Default is 0 which means, pathologist is restricted to the scope of the 
expression in which the debugged program stopped [optional]\n");
-   printf ("\t-r: reverse: enables reverse execution. By default it's not 
allowed [optional]\n");
-   printf ("\t-h: help: print this help [optional]\n");
-   printf ("\t-i: inspect: expression to inspect in the function specified 
after argument f [optional]\n");
-   printf ("\t-o: output: path to the debug report generated by 
pathologist.\n\t If not provided pathologist will save the report in a file 
named pathologist_output in the current working directory [optional]\n");
-   printf ("\t-v: version: pathologist's version [optional]\n");
-   printf ("Report bugs to address@hidden");
-   printf ("GNUnet home page:  http://www.gnu.org/software/gnunet/\n";);
-   printf ("General help using GNU software: http://www.gnu.org/gethelp/\n";);
-}
-
 int freePathologistArgs()
 {
-       if (NULL != mode)
-               MONKEY_free(mode);
        if (NULL != dumpFileName)
                MONKEY_free(dumpFileName);
        if (NULL != binaryName)
@@ -317,8 +293,6 @@
                MONKEY_free(inspectExpression);
        if (NULL != inspectFunction)
                MONKEY_free(inspectFunction);
-       if (NULL != scopeDepth)
-               MONKEY_free(scopeDepth);
 
        return MONKEY_OK;
 }
@@ -330,10 +304,7 @@
                 printf("Error: missing argument: path to the binary file.\n");
         if (NULL == edbFilePath)
                 printf("Error: missing argument: path to expression database 
file.\n");
-        if (NULL == mode)
-                printf("Error: missing argument: mode of operation.\n");
-        if (NULL == binaryName || NULL == edbFilePath || NULL == mode) {
-                showHelp();
+        if (NULL == binaryName || NULL == edbFilePath) {
                 exit(EXIT_FAILURE);
         }
 }
@@ -355,69 +326,48 @@
 int
 main (int argc, char *argv[])
 {
-       int i;
+       static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+               {'b', "binary", "FILENAME", "the binary to debug",
+                       1, &GNUNET_GETOPT_set_string, &binaryName},
+               {'d', "database", "FILENAME", "the expression database to use, 
generated by seaspider",
+                       1, &GNUNET_GETOPT_set_string, &edbFilePath},
+               {'f', "function", "FUNCTIONNAME", "the name of the function, in 
which pathologist will set a breakpoint",
+                       1, &GNUNET_GETOPT_set_string, &inspectFunction},
+               {'i', "inspect", "EXPRESSIONNAME", "expression to inspect in 
the function specified after argument f",
+                       1, &GNUNET_GETOPT_set_string, &inspectExpression},
+               {'m', "mail", "MAILADDRESS", "if specified, pathologist will 
send the bugreport to the given address",
+                       1, &GNUNET_GETOPT_set_string, &emailAddress},
+               {'o', "report", "FILENAME", "saves the xml formated report to 
the given file",
+                       1, &GNUNET_GETOPT_set_string, &dumpFileName},
+               {'p', "depth", "UINT", "scope depth. How many scopes should 
pathologist lookup expression values outer than the scope in which the problem 
occurs. Default is 0 which means, pathologist is restricted to the scope of the 
expression in which the debugged program stopped" ,
+                       1, &GNUNET_GETOPT_set_uint, &scopeDepth},
+               {'r', "reverse", NULL, "enables reverse execution",
+                       0, &GNUNET_GETOPT_set_one, &reverseExecutionAllowed},
+               {'g', "gdb", "FILENAME", "path to gdb binary to use. If not 
passed, pathologist will set it to /usr/bin/gdb",
+                       1, &GNUNET_GETOPT_set_string, &gdbBinaryPath},
+               {'l', "valgrind", "FILENAME", "path to valgrind binary. If not 
passed, pathologist will set it to /usr/bin/valgrind",
+                       1, &GNUNET_GETOPT_set_string, &valgrindBinaryPath},
+               {'h', "help", NULL, "shows this help",
+                       0, &GNUNET_GETOPT_format_help_, "Monkey Pathologist: 
Automatically debug a service"},
+               {'v', "version", NULL, "print the version number",
+                       0, &GNUNET_GETOPT_print_version_, "0.1 alpha"},
+               GNUNET_GETOPT_OPTION_END
+       };
 
-        if (argc < MIN_ARG_REQUIRED)
-           {
-             fprintf (stderr,
-                     "Pathologist should take arguments: Use -h to get a list 
of options.\n");
-             return 1;
-           }
-        /* Parsing arguments */
-        for (i = 1; i < argc; i++) {
-                if (strcmp("-h", argv[i]) == 0) {
-                        showHelp();
-                        freePathologistArgs();
-                        return 1;
-                }
-                if (strcmp("-b", argv[i]) == 0) {
-                        binaryName = MONKEY_strdup(argv[++i]);
-                        /* All remaining args are considered program arguments 
*/
-                        i++;
-                        binaryArgs = buildBinaryArgs(argc - i, &argv[i]);
-                        break;
-                }
-                else if (strcmp("-d", argv[i]) == 0) {
-                        edbFilePath = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-m", argv[i]) == 0) {
-                        mode = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-o", argv[i]) == 0) {
-                        dumpFileName = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-a", argv[i]) == 0) {
-                        emailAddress = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-g", argv[i]) == 0) {
-                        gdbBinaryPath = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-l", argv[i]) == 0) {
-                        valgrindBinaryPath = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-f", argv[i]) == 0) {
-                        inspectFunction = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-i", argv[i]) == 0) {
-                        inspectExpression = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-p", argv[i]) == 0) {
-                        scopeDepth = MONKEY_strdup(argv[++i]);
-                }
-                else if (strcmp("-r", argv[i]) == 0) {
-                        reverseExecutionAllowed = MONKEY_YES;
-                } else {
-                        fprintf(stderr, "Unknown argument %s\n", argv[i]);
-                        showHelp();
-                        freePathologistArgs();
-                        return 1;
-                }
-        }
+       if (-1 == (ret = GNUNET_GETOPT_run ("pathologist", options, (unsigned 
int) argc, argv)))
+               return -1;
 
-        checkRequiredArgs();
+       
+       checkRequiredArgs(); 
 
-        /* Run Pathologist */
-        run();
+       /* All remaining args are considered program arguments */
+       binaryArgs = buildBinaryArgs(argc - ret, &argv[ret]);
 
-  return ret;
+       /* Run Pathologist */
+       run();
+
+       /* clean up */
+       freePathologistArgs();
+
+       return ret;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]