0

I am debugging with arguments in gdb:

gdb --args ./buildData data/test.data features/testFeatures.txt test

Then in gdb I set a break point in the 'main' function and want to print out the argv's value:

print *argv

But this only displays the first argument, not all:

print *argv
$2 = 0x7fffffffe4f0 "/src/tools/./buildData"

Shouldn't it print out all 3 arguments?

marlon
  • 6,029
  • 8
  • 42
  • 76
  • 2
    https://stackoverflow.com/a/14502287/4655217 p argv@argc – geobreze Nov 23 '21 at 17:08
  • No, argv is a pointer. try `print argv[1]`, `print argv[2]`, etc? – user253751 Nov 23 '21 at 17:12
  • @geobreze but in other cases, print *someObject can always print out the pointer's value. Why can't it do for *argv? Is that because *argv is a pointer to an array? – marlon Nov 23 '21 at 17:35
  • 1
    @marlon array is just a pointer to the first element. When you're accessing *array it's the same as *(array + 0) which is equal to array[0]. Same with other indexes: *(array + 1) equal to array[1] and so on. – geobreze Nov 23 '21 at 17:39
  • Anyway linked answear is perfect solution, just do `p *argv@argc` [gdb doc](https://sourceware.org/gdb/current/onlinedocs/gdb/Arrays.html). – Marek R Nov 23 '21 at 17:48

0 Answers0