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: Zhang Zhen <zhenzhang dot zhang at huawei dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Yao Qi <qiyaoltc at gmail dot com>, <gdb at sourceware dot org>, <xuhanbing at huawei dot com>
- Date: Wed, 18 Mar 2015 11:08:43 +0800
- 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> <mvmtwxj6f0z dot fsf at hawking dot suse dot de>
On 2015/3/17 19:26, Andreas Schwab wrote:
> 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,
I have tried install libc6-dbg, but the error still exist.
root@sandybridge:/tmp# ls /lib64/.debug/
ld-2.18.so libm-2.18.so libnss_nis-2.18.so
libBrokenLocale-2.18.so libmemusage.so libnss_nisplus-2.18.so
libSegFault.so libnsl-2.18.so libpcprofile.so
libanl-2.18.so libnss_compat-2.18.so libpthread-2.18.so
libc-2.18.so libnss_db-2.18.so libresolv-2.18.so
libcidn-2.18.so libnss_dns-2.18.so librt-2.18.so
libcrypt-2.18.so libnss_files-2.18.so libthread_db-1.0.so
libdl-2.18.so libnss_hesiod-2.18.so libutil-2.18.so
>>
>> 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)
>
Yeah, i tried to wrap up strktok and add a cast.
They both work well.
But i want to know how can i get the correct return type of strtok in gdb.
Thanks for your and Yao Qi's reply.
> Andreas.
>