From: Julian S. <js...@ac...> - 2003-05-12 07:57:06
|
Dan Attached is a patch which allows you to change stdin to whatever you like, if you thing V is closing it. J ------------------------------------------------------------------ [Valgrind-users] Patch to make debugging curses programs easier Date: Sun May 11 18:31:24 2003 From: Sami Liedes <sl...@cc...> To: val...@li... I found the following simple changes helpful in using Valgrind to debug curses programs with --gdb-attach=yes. I'd be happy to know if someone has found an easier way to use --gdb-attach=yes with curses programs; if not, this patch might be useful for others too. With it it's possible to read the Y/N for the "attach gdb" question from any file descriptor (--input=fd=<n>). The --gdb-command=<command> option allows e.g. using a script to start gdb in an xterm (or using openvt). Attached patch against 1.9.6. Sami diff -ur valgrind-1.9.6/coregrind/vg_errcontext.c valgrind-1.9.6-cursespatch/coregrind/vg_errcontext.c --- valgrind-1.9.6/coregrind/vg_errcontext.c 2003-01-28 21:59:35.000000000 +0200 +++ valgrind-1.9.6-cursespatch/coregrind/vg_errcontext.c 2003-05-10 18:46:47.000000000 +0300 @@ -141,14 +141,14 @@ VG_(getpid)() ); - 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 -ur valgrind-1.9.6/coregrind/vg_include.h valgrind-1.9.6-cursespatch/coregrind/vg_include.h --- valgrind-1.9.6/coregrind/vg_include.h 2003-05-05 02:34:22.000000000 +0300 +++ valgrind-1.9.6-cursespatch/coregrind/vg_include.h 2003-05-10 17:57:12.000000000 +0300 @@ -171,6 +171,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 command to run as GDB? default: gdb */ +extern Char* VG_(clo_GDB_command); /* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */ extern Int VG_(sanity_level); /* Automatically attempt to demangle C++ names? default: YES */ @@ -205,6 +207,8 @@ extern Int VG_(clo_logfile_fd); extern Char* VG_(clo_logfile_name); +/* The file descriptor to read for input. */ +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 -ur valgrind-1.9.6/coregrind/vg_main.c valgrind-1.9.6-cursespatch/coregrind/vg_main.c --- valgrind-1.9.6/coregrind/vg_main.c 2003-05-05 03:03:40.000000000 +0300 +++ valgrind-1.9.6-cursespatch/coregrind/vg_main.c 2003-05-10 18:47:35.000000000 +0300 @@ -457,6 +457,7 @@ /* Define, and set defaults. */ Bool VG_(clo_error_limit) = True; Bool VG_(clo_GDB_attach) = False; +Char* VG_(clo_GDB_command) = "gdb"; Int VG_(sanity_level) = 1; Int VG_(clo_verbosity) = 1; Bool VG_(clo_demangle) = True; @@ -469,6 +470,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; @@ -558,6 +560,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-command=<command> command to run as gdb [gdb]\n" " --demangle=no|yes automatically demangle C++ names? [yes]\n" " --num-callers=<number> show <num> callers in stack traces [4]\n" " --error-limit=no|yes stop showing new errors if too many? [yes]\n" @@ -567,6 +570,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 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" @@ -859,6 +863,9 @@ else if (STREQ(argv[i], "--gdb-attach=no")) VG_(clo_GDB_attach) = False; + else if (STREQN(14,argv[i], "--gdb-command=")) + VG_(clo_GDB_command) = &argv[i][14]; + else if (STREQ(argv[i], "--demangle=yes")) VG_(clo_demangle) = True; else if (STREQ(argv[i], "--demangle=no")) @@ -896,6 +903,9 @@ VG_(clo_logfile_name) = &argv[i][10]; } + else if (STREQN(11, argv[i], "--input-fd=")) + VG_(clo_input_fd) = (Int)VG_(atoll)(&argv[i][11]); + else if (STREQN(12, argv[i], "--logsocket=")) { VG_(clo_log_to) = VgLogTo_Socket; VG_(clo_logfile_name) = &argv[i][12]; @@ -1673,7 +1683,8 @@ Int res; UChar buf[100]; VG_(sprintf)(buf, - "/usr/bin/gdb -nw /proc/%d/exe %d", + "%s -nw /proc/%d/exe %d", + VG_(clo_GDB_command), VG_(getpid)(), VG_(getpid)()); VG_(message)(Vg_UserMsg, "starting GDB with cmd: %s", buf); res = VG_(system)(buf); |