Re: How to pass empty string to program's argv[0] ?

Paul Pluzhnikov <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CALoOobPu0A5_4+xNFAQLELzZe0uoyPp8uDxLcyrQJgpiti6n_w@mail.gmail.com>
On Fri, Jan 7, 2011 at 9:11 AM, Paul Pluzhnikov <[email protected]> wrote:
> On Wed, Jan 5, 2011 at 2:45 AM, Ilya Basin <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.