On Thu, Oct 6, 2016 at 5:27 PM, Luis Machado <lgustavo@codesourcery.com> wrote:
I noticed that testing aarch64-elf gdb with a physical board
ran into issues with gdb.python/py-value.exp. Further investigation showed
that we were actually trying to dereference a NULL pointer (argv) when trying
to access argv[0].
Being bare-metal, argv is not guaranteed to be there. So we need to make sure
argv is sane before accessing argv[0].
After fixing that, i noticed we were assuming a value of 1 for argc, which is
also not true, as i see 0 in my tests.
If I understand C standard
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf correctly,
"argv" can't be NULL.
5.1.2.2.1 Program startup
...
The value of argc shall be nonnegative.
argv[argc] shall be a null pointer.
The first one implies that argc can be zero, and the second one implies
argv can't be NULL. In this case, argc is zero, so argv[0] can be
dereferenced.