This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: The return address of strtok is out of bounds in gdb
- From: Andreas Schwab <schwab at suse dot de>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: Zhang Zhen <zhenzhang dot zhang at huawei dot com>, <gdb at sourceware dot org>, <xuhanbing at huawei dot com>
- Date: Tue, 17 Mar 2015 12:26:36 +0100
- Subject: Re: The return address of strtok is out of bounds in gdb
- Authentication-results: sourceware.org; auth=none
- References: <5507E977 dot 2030003 at huawei dot com> <86k2yfg9yi dot fsf at gmail dot com>
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."