Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: Zhang Zhen <zhenzhang.zhang@huawei.com>,  <gdb@sourceware.org>,
	 <xuhanbing@huawei.com>
Subject: Re: The return address of strtok is out of bounds in gdb
Date: Tue, 17 Mar 2015 11:26:00 -0000	[thread overview]
Message-ID: <mvmtwxj6f0z.fsf@hawking.suse.de> (raw)
In-Reply-To: <86k2yfg9yi.fsf@gmail.com> (Yao Qi's message of "Tue, 17 Mar 2015	11:05:57 +0000")

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


  reply	other threads:[~2015-03-17 11:26 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 [this message]
2015-03-18  3:09     ` Zhang Zhen
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=mvmtwxj6f0z.fsf@hawking.suse.de \
    --to=schwab@suse.de \
    --cc=gdb@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    --cc=xuhanbing@huawei.com \
    --cc=zhenzhang.zhang@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