This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: How to pass empty string to program's argv[0] ?
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: Ilya Basin <basinilya at gmail dot com>
- Cc: gdb at sourceware dot org, Daniel Jacobowitz <dmj at google dot com>
- Date: Wed, 8 May 2013 23:41:25 -0700
- Subject: Re: How to pass empty string to program's argv[0] ?
- References: <653669235 dot 20110105134547 at gmail dot com> <AANLkTikCfPnn+dckNKbxMS4y+gdirZgrHRhD6=NkL28W at mail dot gmail dot com>
On Fri, Jan 7, 2011 at 9:11 AM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> On Wed, Jan 5, 2011 at 2:45 AM, Ilya Basin <basinilya@gmail.com> wrote:
>> $ sh -c "exec -a '' bash -s a b c"
>> echo "0: '$0'"; echo "1: '$1'"
>> 0: ''
>> 1: 'a'
>>
>> I want similar output from bash under gdb
>
> FWIW, gdb insists on setting argv[0] to full path of the executable.
Following up. It turns out this is trivially achievable with 'set
exec-wrapper' (which I just discovered; thanks, Daniel :-)
For example:
cat wrapper.sh
#!/bin/bash
exec -a "$ARG0" "$@"
$ gdb -q ./echo-args
Reading symbols from /tmp/exec-wrapper/echo-args...done.
(gdb) r foo bar
Starting program: /tmp/exec-wrapper/echo-args foo bar
0: /tmp/exec-wrapper/echo-args
1: foo
2: bar
[Inferior 1 (process 14051) exited normally]
(gdb) set exec-wrapper ./wrapper.sh
(gdb) r
Starting program: /tmp/exec-wrapper/echo-args foo bar
0:
1: foo
2: bar
[Inferior 1 (process 14218) exited normally]
--
Paul Pluzhnikov