Thread: [Cgdb-devel] -d parameter fix and enhancement
Brought to you by:
bobbybrasko,
crouchingturbo
|
From: Horst S. <ho...@sc...> - 2006-08-02 17:36:35
|
Re-sending my previous patch, which now
- patches SVN HEAD (r830)
- modifies cgdb/src/usage.c instead of the autogenerated cgdb.1
cgdb.c | 13 ++++++++++++-
usage.c | 3 ++-
2 files changed, 14 insertions(+), 2 deletions(-)
Index: cgdb/src/cgdb.c
===================================================================
--- cgdb/src/cgdb.c (revision 830)
+++ cgdb/src/cgdb.c (working copy)
@@ -719,7 +719,13 @@
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 ();
@@ -731,6 +737,11 @@
*argc -= n;
*argv += n;
+
+ if (strcmp(**argv, "--") == 0) {
+ (*argc)--;
+ (*argv)++;
+ }
}
/* init_home_dir: Attempts to create a config directory in the user's home
Index: cgdb/src/usage.c
===================================================================
--- cgdb/src/usage.c (revision 830)
+++ cgdb/src/usage.c (working copy)
@@ -13,7 +13,7 @@
{
printf(
"CGDB Usage:\n"
-" cgdb [cgdb options] [gdb options]\n"
+" cgdb [cgdb options] [--] [gdb options]\n"
"\n"
"CGDB Options:\n"
#ifdef HAVE_GETOPT_H
@@ -27,5 +27,6 @@
" -h Print help (this message) and then exit.\n"
#endif
" -d Set debugger to use.\n"
+" -- Separator to avoid ambiguities between gdb and cgdb options.\n"
);
}
--
PGP-Key 0xD40E0E7A
|
|
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
|
|
From: Horst S. <ho...@sc...> - 2006-08-02 17:43:18
|
*sigh* my last try, fixing a SIGSEGV when **argv is NULL when comparing
to "--"... Sorry for the noise.
cgdb.c | 13 ++++++++++++-
usage.c | 3 ++-
2 files changed, 14 insertions(+), 2 deletions(-)
Index: cgdb/src/cgdb.c
===================================================================
--- cgdb/src/cgdb.c (revision 830)
+++ cgdb/src/cgdb.c (working copy)
@@ -719,7 +719,13 @@
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 ();
@@ -731,6 +737,11 @@
*argc -= n;
*argv += n;
+
+ if (**argv && strcmp(**argv, "--") == 0) {
+ (*argc)--;
+ (*argv)++;
+ }
}
/* init_home_dir: Attempts to create a config directory in the user's home
Index: cgdb/src/usage.c
===================================================================
--- cgdb/src/usage.c (revision 830)
+++ cgdb/src/usage.c (working copy)
@@ -13,7 +13,7 @@
{
printf(
"CGDB Usage:\n"
-" cgdb [cgdb options] [gdb options]\n"
+" cgdb [cgdb options] [--] [gdb options]\n"
"\n"
"CGDB Options:\n"
#ifdef HAVE_GETOPT_H
@@ -27,5 +27,6 @@
" -h Print help (this message) and then exit.\n"
#endif
" -d Set debugger to use.\n"
+" -- Separator to avoid ambiguities between gdb and cgdb options.\n"
);
}
--
PGP-Key 0xD40E0E7A
|
|
From: Bob R. <bob...@co...> - 2006-08-03 19:15:19
|
On Wed, Aug 02, 2006 at 07:43:13PM +0200, Horst Schirmeier wrote: > *sigh* my last try, fixing a SIGSEGV when **argv is NULL when comparing > to "--"... Sorry for the noise. OK, I'll hopefully get a chance to look at this soon. I like the idea. Are you sure that GDB takes the -d option? Thanks, Bob Rossi |
|
From: Mike M. <mi...@su...> - 2006-08-03 19:24:11
|
>From GDB's man page:
-d directory
Add directory to the path to search for source files.
Mike
On 8/3/06, Bob Rossi <bob...@co...> wrote:
> On Wed, Aug 02, 2006 at 07:43:13PM +0200, Horst Schirmeier wrote:
> > *sigh* my last try, fixing a SIGSEGV when **argv is NULL when comparing
> > to "--"... Sorry for the noise.
>
> OK, I'll hopefully get a chance to look at this soon. I like the idea.
>
> Are you sure that GDB takes the -d option?
>
> Thanks,
> Bob Rossi
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Cgdb-devel mailing list
> Cgd...@li...
> https://lists.sourceforge.net/lists/listinfo/cgdb-devel
>
|
|
From: Bob R. <bob...@co...> - 2006-10-04 16:07:51
Attachments:
cgdb.diff
|
On Wed, Aug 02, 2006 at 07:43:13PM +0200, Horst Schirmeier wrote: > *sigh* my last try, fixing a SIGSEGV when **argv is NULL when comparing > to "--"... Sorry for the noise. Sorry for the long delay. I've committed the attached patch. Thanks! Bob Rossi |