* Re: gdb hijacks my argument list
@ 2010-01-05 1:06 Leslie
2010-01-05 11:39 ` Niklas Holsti
0 siblings, 1 reply; 9+ messages in thread
From: Leslie @ 2010-01-05 1:06 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 2089 bytes --]
Hi,
Has anyone else seen this problem with gdb? I had originally
posted it to bug-gdb@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
[-- Attachment #2: gdbSession.txt --]
[-- Type: text/plain, Size: 6463 bytes --]
15:48:37 turriff@pinto
~/Documents/SourceCode$
uname -a
Linux pinto 2.6.25.20-0.5-pae #1 SMP 2009-08-14 01:48:11 +0200 i686 i686 i386 GNU/Linux
15:48:39 turriff@pinto
~/Documents/SourceCode$
cat /etc/SuSE-release
openSUSE 11.0 (i586)
VERSION = 11.0
15:48:46 turriff@pinto
~/Documents/SourceCode$
gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --with-slibdir=/lib --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.3 --enable-version-specific-runtime-libs --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=i586-suse-linux
Thread model: posix
gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux)
15:48:50 turriff@pinto
~/Documents/SourceCode$
gnat
GNAT 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]
Copyright 1996-2007, Free Software Foundation, Inc.
List of available commands
gnat bind gnatbind
gnat chop gnatchop
gnat clean gnatclean
gnat compile gnatmake -f -u -c
gnat check gnatcheck
gnat elim gnatelim
gnat find gnatfind
gnat krunch gnatkr
gnat link gnatlink
gnat list gnatls
gnat make gnatmake
gnat metric gnatmetric
gnat name gnatname
gnat preprocess gnatprep
gnat pretty gnatpp
gnat stack gnatstack
gnat stub gnatstub
gnat xref gnatxref
Commands find, list, metric, pretty, stack, stub and xref accept project file switches -vPx, -Pprj and -Xnam=val
15:48:54 turriff@pinto
~/Documents/SourceCode$
ll testcmdline*
-rw-r--r-- 1 turriff users 379 2009-12-19 14:27 testcmdline.adb
15:49:00 turriff@pinto
~/Documents/SourceCode$
gcc -c -g testcmdline.adb && gnatmake -g testcmdline
gnatbind -x testcmdline.ali
gnatlink testcmdline.ali -g
15:49:19 turriff@pinto
~/Documents/SourceCode$
./testcmdline with an arbitrary command string
with
15:49:35 turriff@pinto
~/Documents/SourceCode$
./testcmdline 'with an arbitrary command string'
with an arbitrary command string
15:49:44 turriff@pinto
~/Documents/SourceCode$
gdb -v
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".
15:49:55 turriff@pinto
~/Documents/SourceCode$
gdb --quiet testcmdline
(gdb) break testcmdline
Breakpoint 1 at 0x8049bdb: file testcmdline.adb, line 5.
(gdb) set args 'with an arbitrary command string'
(gdb) run
Starting program: /home/turriff/Documents/SourceCode/testcmdline 'with an arbitrary command string'
unable to open script file 'exec /home/turriff/Documents/SourceCode/testcmdline 'with an arbitrary command string'' : file not found
Program exited with code 01.
You can't do that without a process to debug.
(gdb) quit
15:50:36 turriff@pinto
~/Documents/SourceCode$
gdb --quiet --args testcmdline 'with an arbitrary command string'
(gdb) break testcmdline
Breakpoint 1 at 0x8049bdb: file testcmdline.adb, line 5.
(gdb) show args
Argument list to give program being debugged when it is started is "".
(gdb) run
Starting program: /home/turriff/Documents/SourceCode/testcmdline with\ an\ arbitrary\ command\ string
unable to open script file 'exec /home/turriff/Documents/SourceCode/testcmdline with\ an\ arbitrary\ command\ string' : file not found
Program exited with code 01.
You can't do that without a process to debug.
(gdb) quit
15:51:40 turriff@pinto
~/Documents/SourceCode$
gdb --help
This is the GNU debugger. Usage:
gdb [options] [executable-file [core-file or process-id]]
gdb [options] --args executable-file [inferior-arguments ...]
Options:
--args Arguments after executable-file are passed to inferior
-b BAUDRATE Set serial port baud rate used for remote debugging.
--batch Exit after processing options.
--batch-silent As for --batch, but suppress all gdb stdout output.
--return-child-result
GDB exit code will be the child's exit code.
--cd=DIR Change current directory to DIR.
--command=FILE, -x Execute GDB commands from FILE.
--eval-command=COMMAND, -ex
Execute a single GDB command.
May be used multiple times and in conjunction
with --command.
--core=COREFILE Analyze the core dump COREFILE.
--pid=PID Attach to running process PID.
--dbx DBX compatibility mode.
--directory=DIR Search for source files in DIR.
--epoch Output information used by epoch emacs-GDB interface.
--exec=EXECFILE Use EXECFILE as the executable.
--fullname Output information used by emacs-GDB interface.
--help Print this message.
--interpreter=INTERP
Select a specific interpreter / user interface
-l TIMEOUT Set timeout in seconds for remote debugging.
--nw Do not use a window interface.
--nx Do not read .gdbinit file.
--quiet Do not print version number on startup.
--readnow Fully read symbol files on first access.
--se=FILE Use FILE as symbol file and executable file.
--symbols=SYMFILE Read symbols from SYMFILE.
--tty=TTY Use TTY for input/output by the program being debugged.
--tui Use a terminal user interface.
--version Print version information and then exit.
-w Use a window interface.
--write Set writing into executable and core files.
--xdb XDB compatibility mode.
For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "bug-gdb@gnu.org".
[-- Attachment #3: testcmdline.adb --]
[-- Type: text/plain, Size: 380 bytes --]
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings; use Ada.Strings;
with Ada.Text_IO; use Ada.Text_IO;
procedure testcmdline is
TextLine : unbounded_string;
begin
TextLine := to_unbounded_string(argument(1));
put_line(to_string(TextLine));
end testcmdline;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 1:06 gdb hijacks my argument list Leslie
@ 2010-01-05 11:39 ` Niklas Holsti
2010-01-05 15:21 ` Leslie
0 siblings, 1 reply; 9+ messages in thread
From: Niklas Holsti @ 2010-01-05 11:39 UTC (permalink / raw)
Leslie wrote:
> Hi,
> Has anyone else seen this problem with gdb? I had originally
> posted it to bug-gdb@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
. @ .
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 11:39 ` Niklas Holsti
@ 2010-01-05 15:21 ` Leslie
2010-01-05 16:15 ` John B. Matthews
2010-01-05 17:34 ` Niklas Holsti
0 siblings, 2 replies; 9+ messages in thread
From: Leslie @ 2010-01-05 15:21 UTC (permalink / raw)
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)
========================
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 15:21 ` Leslie
@ 2010-01-05 16:15 ` John B. Matthews
2010-01-05 19:25 ` Leslie
2010-01-05 17:34 ` Niklas Holsti
1 sibling, 1 reply; 9+ messages in thread
From: John B. Matthews @ 2010-01-05 16:15 UTC (permalink / raw)
In article <hhvlc7$nc8$1@news.albasani.net>,
Leslie <jlturriff@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>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 15:21 ` Leslie
2010-01-05 16:15 ` John B. Matthews
@ 2010-01-05 17:34 ` Niklas Holsti
2010-01-05 19:18 ` Leslie
1 sibling, 1 reply; 9+ messages in thread
From: Niklas Holsti @ 2010-01-05 17:34 UTC (permalink / raw)
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@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
. @ .
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 17:34 ` Niklas Holsti
@ 2010-01-05 19:18 ` Leslie
2010-01-05 19:36 ` Niklas Holsti
0 siblings, 1 reply; 9+ messages in thread
From: Leslie @ 2010-01-05 19:18 UTC (permalink / raw)
Niklas Holsti wrote:
> 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":
>
Ack! You're right; I changed the name of the program between
times. But it does the same thing with the correct program
name:
================================
gdb --args testcmdline ' (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"...
(gdb)
===============================
Leslie
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 16:15 ` John B. Matthews
@ 2010-01-05 19:25 ` Leslie
2010-01-05 21:19 ` John B. Matthews
0 siblings, 1 reply; 9+ messages in thread
From: Leslie @ 2010-01-05 19:25 UTC (permalink / raw)
John B. Matthews wrote:
> In article <hhvlc7$nc8$1@news.albasani.net>,
> Leslie <jlturriff@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.
>
The single quotes should deactivate the "specialness" of those
operators. In any case, the entire string is being rejected,
not just parts of it, and no substitutions are made by shell.
However, I must say 'thank you very much,' because 'set args'
does the trick.
Thank you very much.
Leslie
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 19:18 ` Leslie
@ 2010-01-05 19:36 ` Niklas Holsti
0 siblings, 0 replies; 9+ messages in thread
From: Niklas Holsti @ 2010-01-05 19:36 UTC (permalink / raw)
Leslie wrote:
> Niklas Holsti wrote:
>
>> 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":
>>
> Ack! You're right; I changed the name of the program between
> times. But it does the same thing with the correct program
> name:
> ================================
> gdb --args testcmdline ' (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"...
> (gdb)
You must also tell GDB to "run" the program at this point. So far, it
has only read the program file (testcmdline) but has not started to
execute the program. So type "run" to the "(gdb)" prompt.
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: gdb hijacks my argument list
2010-01-05 19:25 ` Leslie
@ 2010-01-05 21:19 ` John B. Matthews
0 siblings, 0 replies; 9+ messages in thread
From: John B. Matthews @ 2010-01-05 21:19 UTC (permalink / raw)
In article <hi03m6$fsl$1@news.albasani.net>,
Leslie <jlturriff@centurytel.net> wrote:
> John B. Matthews wrote:
>
> > In article <hhvlc7$nc8$1@news.albasani.net>,
> > Leslie <jlturriff@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,
Looking again, my gdb has an --args option; it just doesn't work. :-)
> > 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.
>
> The single quotes should deactivate the "specialness" of those
> operators. In any case, the entire string is being rejected,
> not just parts of it, and no substitutions are made by shell.
You're right about the quotes, but I was mistaken about shell expansion.
It seems gdb uses the environments $SHELL (or /bin/sh) to expand args:
<http://sourceware.org/gdb/current/onlinedocs/gdb/Arguments.html>
(gdb) set args $((7 * 6))
(gdb) r
Starting program: argtest $((7 * 6))
42
> However, I must say 'thank you very much,' because 'set args'
> does the trick.
>
> Thank you very much.
Excellent!
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-01-05 21:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-05 1:06 gdb hijacks my argument list Leslie
2010-01-05 11:39 ` Niklas Holsti
2010-01-05 15:21 ` Leslie
2010-01-05 16:15 ` John B. Matthews
2010-01-05 19:25 ` Leslie
2010-01-05 21:19 ` John B. Matthews
2010-01-05 17:34 ` Niklas Holsti
2010-01-05 19:18 ` Leslie
2010-01-05 19:36 ` Niklas Holsti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox