This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: The return address of strtok is out of bounds in gdb


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.
> 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]