Switch gdb command parameters parsing algorithm from UNIX rules to Windows rules.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3482
R=eaeltsin@google.com
Review URL: https://codereview.chromium.org/16339009
diff --git a/gdb/utils.c b/gdb/utils.c
index 5566149..fa7a6ac 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -78,6 +78,10 @@
#include "interps.h"
#include "gdb_regex.h"
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <windows.h>
+#endif
+
#if !HAVE_DECL_MALLOC
extern PTR malloc (); /* ARI: PTR */
#endif
@@ -165,6 +169,20 @@
}
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+static void
+do_freeargv (void *arg)
+{
+ int i = 0;
+ char** args = (char**) arg;
+ for (i = 0; args[i] != NULL; i++)
+ free(args[i]);
+ free(args);
+}
+
+#else
+
/* Cleanup utilities.
These are not defined in cleanups.c (nor declared in cleanups.h)
@@ -177,6 +195,8 @@
freeargv ((char **) arg);
}
+#endif
+
struct cleanup *
make_cleanup_freeargv (char **arg)
{
@@ -3480,6 +3500,45 @@
return dirname;
}
+#if defined(_WIN32) && !defined(__CYGWIN__)
+
+char **
+gdb_buildargv (const char *s)
+{
+ LPWSTR wide_string;
+ int wide_len;
+ int arg_len;
+ int num_args;
+ LPWSTR* args;
+ char** result;
+ int i;
+ if (s == NULL)
+ return NULL;
+ wide_len = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
+ wide_string = malloc(2 * wide_len);
+ if (wide_string == NULL)
+ malloc_failure (0);
+ MultiByteToWideChar(CP_UTF8, 0, s, -1, wide_string, wide_len);
+ args = CommandLineToArgvW(wide_string, &num_args);
+ free(wide_string);
+ result = malloc((num_args + 1) * sizeof(char*));
+ for (i = 0; i < num_args; i++)
+ {
+ arg_len = WideCharToMultiByte(CP_UTF8, 0, args[i], -1, NULL, 0,
+ NULL, NULL);
+ result[i] = malloc(arg_len);
+ if (result[i] == NULL)
+ malloc_failure(0);
+ WideCharToMultiByte(CP_UTF8, 0, args[i], -1, result[i], arg_len,
+ NULL, NULL);
+ }
+ result[num_args] = NULL;
+ LocalFree(args);
+ return result;
+}
+
+#else
+
/* Call libiberty's buildargv, and return the result.
If buildargv fails due to out-of-memory, call nomem.
Therefore, the returned value is guaranteed to be non-NULL,
@@ -3495,6 +3554,8 @@
return argv;
}
+#endif
+
int
compare_positive_ints (const void *ap, const void *bp)
{