From: Leslie on
Hi,
Has anyone else seen this problem with gdb? I had originally
posted it to bug-gdb(a)gnu.org, but got no useful response.
Original post:

I'm writing a package that accepts arbitrary character
strings from the command line, and I'm trying to debug it with
gdb.

When run without gdb the command line string is passed
directly to my program, but when I tell gdb to pass it, gdb
insists on interpreting it as a filename, and won't pass it
through.

Example without gdb:
=================================================
../testtoken ' (name testtoken endchar \) < testtoken.adb |
(trace) count lines|cons '

Input string is:
.....+....1....+....2....+....3....+....4....+....5....+....6
(name testtoken endchar \) < testtoken.adb | (trace) count lines
cons

Before: TokenFrom = 1
TextLeft = 71
After: TokenFrom = 1
TextLeft = 71
Token 1 is: ' (name testtoken endchar \) < testtoken.adb |
(trace) count lines|cons '

End of tokens reached.

=================================================

Example with gdb:
=================================================
gdb testtoken --args ' (name testtoken endchar \) <
testtoken.adb | (trace) count lines|cons '
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html> This is free software: you are
free to change and redistribute it. There is NO WARRANTY, to the
extent permitted by law. Type "show copying" and "show
warranty" for details.
This GDB was configured as "i586-suse-linux"...
(name testtoken endchar \) < testtoken.adb | (trace) count lines
cons : No such file or directory.
(gdb)
=================================================

I have tried using the 'run PROGNAME ARGUMENTS...' method, but
it gives
me the same results. I have attached the source code and a
terminal session showing exactly what I have tried, so that you
can (presumably) duplicate my results. Perhaps I am
misunderstanding somehow the proper gdb syntax to be used, or
have wrong versions of tools?

Leslie
From: Niklas Holsti on
Leslie wrote:
> Hi,
> Has anyone else seen this problem with gdb? I had originally
> posted it to bug-gdb(a)gnu.org, but got no useful response.
> Original post:
>
...
> Example with gdb:
> =================================================
> gdb testtoken --args ' (name testtoken endchar \) <
> testtoken.adb | (trace) count lines|cons '

According to "man gdb", the syntax for --args is:

gdb [options] --args prog [arguments]

So the first thing after "--args" is the program name (prog), and *then*
come the programs' arguments. Try this:

gdb --args testtoken ' (name testtoken endchar \) <
> testtoken.adb | (trace) count lines|cons '


--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
From: Leslie on
Niklas Holsti wrote:

> gdb --args testtoken ' (name testtoken endchar \) <
> > testtoken.adb | (trace) count lines|cons '

I get exactly the same result as before:
==================================
gdb --args testtoken ' (name testtoken endchar \) <
testtoken.adb | (trace) count lines|cons '
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute
it.
There is NO WARRANTY, to the extent permitted by law. Type "show
copying"
and "show warranty" for details.
This GDB was configured as "i586-suse-linux"...
testtoken: No such file or directory.
(gdb)
========================
From: John B. Matthews on
In article <hhvlc7$nc8$1(a)news.albasani.net>,
Leslie <jlturriff(a)centurytel.net> wrote:

> Niklas Holsti wrote:
>
> > gdb --args testtoken ' (name testtoken endchar \) <
> > > testtoken.adb | (trace) count lines|cons '
>
> I get exactly the same result as before:

This older version of gdb lacks the --args feature, but `set args` and
`show args` seem to work. Some of the tokens in your arg string appear
to be shell operators and commands. You may have to evaluate the string
in a shell and feed the result to args.

<transcript>
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40
UTC 2008) Copyright 2004 Free Software Foundation, Inc. GDB is free
software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions. Type "show copying" to see the conditions. There is
absolutely no warranty for GDB. Type "show warranty" for details. This
GDB was configured as "i386-apple-darwin"...Reading symbols for shared
libraries .. done

(gdb) set args ' (name testtoken endchar \) < testtoken.adb | (trace) count lines|cons '
(gdb) show args
Argument list to give program being debugged when it is started is
"' (name testtoken endchar \) < testtoken.adb | (trace) count lines|cons '".
(gdb)
</transcript>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Niklas Holsti on
Leslie wrote:
> Niklas Holsti wrote:
>
>> gdb --args testtoken ' (name testtoken endchar \) <
>>> testtoken.adb | (trace) count lines|cons '
>
> I get exactly the same result as before:
> ==================================
> gdb --args testtoken ' (name testtoken endchar \) <
> testtoken.adb | (trace) count lines|cons '
....
> This GDB was configured as "i586-suse-linux"...
> testtoken: No such file or directory.

Well, perhaps GDB is right and there is no such file?

Looking more carefully at your original question, at the attached
terminal session, it seems that your program is really named
"testcmdline", not "testtoken":

> 15:49:35 turriff(a)pinto
> ~/Documents/SourceCode$
> ./testcmdline 'with an arbitrary command string'
> with an arbitrary command string

Perhaps you should use

gdb --args testcmdline ' (name testtoken endchar \) <
testtoken.adb | (trace) count lines|cons '

The GDB command "set args" as suggested by John Matthews is also a good
method, and the one I have used until now.

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .