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: Yao Qi <qiyaoltc at gmail dot com>
- To: Zhang Zhen <zhenzhang dot zhang at huawei dot com>
- Cc: <gdb at sourceware dot org>, <xuhanbing at huawei dot com>
- Date: Tue, 17 Mar 2015 11:05:57 +0000
- 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>
Zhang Zhen <zhenzhang.zhang@huawei.com> writes:
> I found a problem with gdb-7.9 on my x86_64 machine.
> The return address is out of bounds by calling call strtok in gdb.
> But if we enter 'n', the return address is correct.
> I want to know this is a bug ? If so, how to resolve it ?
It is not a bug, IMO.
>
> It is easily reproduced as follows:
>
> Fs-Server:/opt/zhangzhen/gdb-7.9 # ./gdb/gdb -q ../strtok_test
> Reading symbols from ../strtok_test...done.
> (gdb) b 12
> Breakpoint 1 at 0x4005c7: file strtok_test.c, line 12.
> (gdb) r
> Starting program: /opt/zhangzhen/strtok_test
>
> Breakpoint 1, main (argc=1, argv=0x7fffffffe358) at strtok_test.c:12
> 12 p1 = strtok(a0, se);
> (gdb) p p1
> $1 = 0x0
> (gdb) p p1 = strtok(a0, se)
> $2 = 0xffffffffffffe260 <error: Cannot access memory at address 0xffffffffffffe260>
You are doing an "inferior call"
https://sourceware.org/gdb/onlinedocs/gdb/Calling.html here. In order
to support inferior call, GDB needs to create a new frame, get the
function's signature (return value and arguments), prepare the
arguments in the right place (registers or stack) as well as return
address, and resume the programme, wait for the function call finished.
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.
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)
--
Yao (éå)