Add patch from Sami Liedes <sliedes@cc.hut.fi> making GDB use more flexible:
--gdb-path=/path/to/gdb allows running some alternate GDB
--input-fd=<n> allows reading input from some fd other than stdin
I even updated the docs :-)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1754 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/docs/coregrind_core.html b/coregrind/docs/coregrind_core.html
index d9cc537..9f82ec2 100644
--- a/coregrind/docs/coregrind_core.html
+++ b/coregrind/docs/coregrind_core.html
@@ -577,6 +577,24 @@
socket, I guess this option doesn't make any sense. Caveat emptor.
</li><br><p>
+ <li><code>--gdb-path=/path/to/gdb</code>
+ <p>This specifies how Valgrind will invoke GDB. By default, it
+ will use whatever GDB is detected at build time,
+ which is usually <code>/usr/bin/gdb</code>. Using this command,
+ you can specify some alternative path to the GDB you want to
+ use.
+ </li><br><p>
+
+ <li><code>--input-fd=<number></code> [default=0, stdin]<br>
+ <p>When using <code>--gdb-attach=yes</code> and
+ <code>--gen-suppressions=yes</code>, Valgrind will stop
+ so as to read keyboard input from you, when each error occurs.
+ By default it reads from the standard input (stdin), which is
+ problematic for programs which close stdin. This option
+ allows you to specify an alternative file descriptor from
+ which to read input.
+ </li><br><p>
+
<li><code>--gen-suppressions=no</code> [the default]<br>
<code>--gen-suppressions=yes</code>
<p>When enabled, Valgrind will pause after every error shown,
diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c
index edc5594..3276d1e 100644
--- a/coregrind/vg_errcontext.c
+++ b/coregrind/vg_errcontext.c
@@ -130,14 +130,14 @@
VG_(getpid)(), action
);
- res = VG_(read)(0 /*stdin*/, &ch, 1);
+ res = VG_(read)(VG_(clo_input_fd), &ch, 1);
if (res != 1) goto ioerror;
/* res == 1 */
if (ch == '\n') return False;
if (ch != 'N' && ch != 'n' && ch != 'Y' && ch != 'y'
&& ch != 'C' && ch != 'c') goto again;
- res = VG_(read)(0 /*stdin*/, &ch2, 1);
+ res = VG_(read)(VG_(clo_input_fd), &ch2, 1);
if (res != 1) goto ioerror;
if (ch2 != '\n') goto again;
diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h
index b7b2297..aeb5c23 100644
--- a/coregrind/vg_include.h
+++ b/coregrind/vg_include.h
@@ -175,6 +175,8 @@
extern Bool VG_(clo_error_limit);
/* Enquire about whether to attach to GDB at errors? default: NO */
extern Bool VG_(clo_GDB_attach);
+/* The path to GDB? default: whatever ./configure found */
+extern Char* VG_(clo_GDB_path);
/* Enquire about generating a suppression for each error? default: NO */
extern Bool VG_(clo_gen_suppressions);
/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
@@ -205,6 +207,8 @@
extern Int VG_(clo_logfile_fd);
extern Char* VG_(clo_logfile_name);
+/* The file descriptor to read for input. default: 0 == stdin */
+extern Int VG_(clo_input_fd);
/* The number of suppression files specified. */
extern Int VG_(clo_n_suppressions);
/* The names of the suppression files. */
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index b89a411..34ee4fe 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -512,6 +512,7 @@
/* Define, and set defaults. */
Bool VG_(clo_error_limit) = True;
Bool VG_(clo_GDB_attach) = False;
+Char* VG_(clo_GDB_path) = GDB_PATH;
Bool VG_(clo_gen_suppressions) = False;
Int VG_(sanity_level) = 1;
Int VG_(clo_verbosity) = 1;
@@ -523,6 +524,7 @@
Int VG_(clo_logfile_fd) = 2;
Char* VG_(clo_logfile_name) = NULL;
+Int VG_(clo_input_fd) = 0; /* stdin */
Int VG_(clo_n_suppressions) = 0;
Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
Bool VG_(clo_profile) = False;
@@ -610,6 +612,7 @@
" -q --quiet run silently; only print error msgs\n"
" -v --verbose be more verbose, incl counts of errors\n"
" --gdb-attach=no|yes start GDB when errors detected? [no]\n"
+" --gdb-path=/path/to/gdb path to the GDB to use [/usr/bin/gdb]\n"
" --gen-suppressions=no|yes print suppressions for errors detected [no]\n"
" --demangle=no|yes automatically demangle C++ names? [yes]\n"
" --num-callers=<number> show <num> callers in stack traces [4]\n"
@@ -618,6 +621,7 @@
" --run-libc-freeres=no|yes Free up glibc memory at exit? [yes]\n"
" --logfile-fd=<number> file descriptor for messages [2=stderr]\n"
" --logfile=<file> log messages to <file>.pid<pid>\n"
+" --input-fd=<number> file descriptor for (gdb) input [0=stdin]\n"
" --logsocket=ipaddr:port log messages to socket ipaddr:port\n"
" --suppressions=<filename> suppress errors described in\n"
" suppressions file <filename>\n"
@@ -920,6 +924,9 @@
else if (VG_CLO_STREQ(argv[i], "--gdb-attach=no"))
VG_(clo_GDB_attach) = False;
+ else if (VG_CLO_STREQN(11,argv[i], "--gdb-path="))
+ VG_(clo_GDB_path) = &argv[i][11];
+
else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=yes"))
VG_(clo_gen_suppressions) = True;
else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=no"))
@@ -959,6 +966,9 @@
VG_(clo_logfile_name) = &argv[i][12];
}
+ else if (VG_CLO_STREQN(11, argv[i], "--input-fd="))
+ VG_(clo_input_fd) = (Int)VG_(atoll)(&argv[i][11]);
+
else if (VG_CLO_STREQN(15, argv[i], "--suppressions=")) {
if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) {
VG_(message)(Vg_UserMsg, "Too many suppression files specified.");
@@ -1764,11 +1774,8 @@
Int res;
UChar buf[100];
-#define TO_STRING(x) TO_STRING2(x)
-#define TO_STRING2(x) #x
-
VG_(sprintf)(buf, "%s -nw /proc/%d/exe %d",
- TO_STRING(GDB_PATH), VG_(getpid)(), VG_(getpid)());
+ VG_(clo_GDB_path), VG_(getpid)(), VG_(getpid)());
VG_(message)(Vg_UserMsg, "starting GDB with cmd: %s", buf);
res = VG_(system)(buf);
if (res == 0) {
@@ -1779,8 +1786,6 @@
VG_(message)(Vg_UserMsg, "Apparently failed!");
VG_(message)(Vg_UserMsg, "");
}
-#undef TO_STRING
-#undef TO_STRING2
}