This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]