Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Zhang Zhen <zhenzhang.zhang@huawei.com>
To: Andreas Schwab <schwab@suse.de>
Cc: Yao Qi <qiyaoltc@gmail.com>, <gdb@sourceware.org>,
	<xuhanbing@huawei.com>
Subject: Re: The return address of strtok is out of bounds in gdb
Date: Wed, 18 Mar 2015 03:09:00 -0000	[thread overview]
Message-ID: <5508EC3B.6080701@huawei.com> (raw)
In-Reply-To: <mvmtwxj6f0z.fsf@hawking.suse.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.
> 



  reply	other threads:[~2015-03-18  3:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17  8:47 Zhang Zhen
2015-03-17 11:06 ` Yao Qi
2015-03-17 11:26   ` Andreas Schwab
2015-03-18  3:09     ` Zhang Zhen [this message]
2015-03-19 15:15       ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5508EC3B.6080701@huawei.com \
    --to=zhenzhang.zhang@huawei.com \
    --cc=gdb@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    --cc=schwab@suse.de \
    --cc=xuhanbing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox