[Cgdb-devel] [patch] -d parameter fix and enhancement
Brought to you by:
bobbybrasko,
crouchingturbo
|
From: Horst S. <ho...@sc...> - 2006-08-02 17:05:54
|
Hi,
when using cgdb 0.6.3, I stumbled upon the following problem when
trying to pass additional source paths to gdb by invoking cgdb this way:
$ cgdb -d/tmp dot
This of course does not work, as I learned very soon, due to the fact
that -d is a valid parameter for both cgdb and gdb; this is annoying,
but fixable.
But while trying to figure out what was wrong, I realized that there's a
bug in cgdb regarding the very same parameter:
$ gdb cgdb
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
[...]
(gdb) run -d/tmp
Starting program: /usr/bin/cgdb -d/tmp
Failed to read a valid object file image from memory.
(no debugging symbols found)
[...]
*** glibc detected *** free(): invalid pointer: 0x08071c80 ***
Program received signal SIGABRT, Aborted.
0xb7eee410 in ?? ()
After some debugging, I figured out the bug sits is in the
parse_long_options() function in cgdb.c: n gets increased by 2 even if
the -d parameter was passed as one argv entry (as in "-dfoo"), although
2 is only correct for separate argv entries (as in "-d foo").
Please consider including my patch (see below) in your cgdb sources; it
addresses the mentioned "-dfoo vs. -d foo" bug, adds a way to cleanly
separate cgdb parameters from gdb parameters, and documents this in the
man page.
After applying it, you can start cgdb this way:
$ cgdb -d/some/specific/gdb -- -d/tmp -d/foo dot
Btw: Thanks for this nice tool :)
Kind regards,
Horst
cgdb/src/cgdb.c | 13 ++++++++++++-
doc/cgdb.1 | 5 ++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff -Nurp cgdb-0.6.3-orig/cgdb/src/cgdb.c cgdb-0.6.3/cgdb/src/cgdb.c
--- cgdb-0.6.3-orig/cgdb/src/cgdb.c 2006-06-03 20:09:06.000000000 +0200
+++ cgdb-0.6.3/cgdb/src/cgdb.c 2006-08-02 18:34:35.000000000 +0200
@@ -717,7 +717,13 @@ parse_long_options (int *argc, char ***a
exit (0);
case 'd':
debugger_path = strdup (optarg);
- n += 2;
+ if (optarg == (*argv)[n + 1]) {
+ /* optarg is in next argv (-d foo) */
+ n += 2;
+ } else {
+ /* optarg is in this argv (-dfoo) */
+ n++;
+ }
break;
case 'h':
usage ();
@@ -729,6 +735,11 @@ parse_long_options (int *argc, char ***a
*argc -= n;
*argv += n;
+
+ if (strcmp(**argv, "--") == 0) {
+ (*argc)--;
+ (*argv)++;
+ }
}
/* init_home_dir: Attempts to create a config directory in the user's home
diff -Nurp cgdb-0.6.3-orig/doc/cgdb.1 cgdb-0.6.3/doc/cgdb.1
--- cgdb-0.6.3-orig/doc/cgdb.1 2006-06-03 20:10:47.000000000 +0200
+++ cgdb-0.6.3/doc/cgdb.1 2006-08-02 18:44:50.000000000 +0200
@@ -5,7 +5,7 @@ CGDB \- manual page for CGDB 0.6.3
.SH DESCRIPTION
.SS "CGDB Usage:"
.IP
-cgdb [cgdb options] [gdb options]
+cgdb [cgdb options] [--] [gdb options]
.SS "CGDB Options:"
.TP
\fB\-\-version\fR
@@ -16,6 +16,9 @@ Print help (this message) and then exit.
.TP
\fB\-d\fR
Set debugger to use.
+.TP
+\fB\-\-\fR
+Separator to avoid ambiguities between gdb and cgdb options.
.PP
Copyright 2002\-2006 Bob Rossi and Mike Mueller.
CGDB is free software, covered by the GNU General Public License, and you are
--
PGP-Key 0xD40E0E7A
|