The return address of strtok is out of bounds in gdb

Andreas Schwab schwab@suse.de
Tue Mar 17 11:26:00 GMT 2015


Yao Qi <qiyaoltc@gmail.com> writes:

> In your case, I suspect GDB prepares the incorrect arguments for
> function strtok due to lack of debugging information, so you'll see
> the error.

Probably just the unknown return type, which defaults to int, so you get
truncation to 32 bits.

> You can get your libc debug info installed, or wrap up strktok like
> this in your program,
>
> char *
> my_strtok(char *str, const char *delim)
> {
>   return strtok (str, delim);
> }
>
> and in gdb,
>
> (gdb) p p1 = my_strtok(a0, se)

Or add a cast to the expected type:

(gdb) p p1 = ((char *(*)())strtok)(a0, se)

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Gdb mailing list