From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106310 invoked by alias); 18 Mar 2015 03:09:11 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 106293 invoked by uid 89); 18 Mar 2015 03:09:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: szxga02-in.huawei.com Received: from szxga02-in.huawei.com (HELO szxga02-in.huawei.com) (119.145.14.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 18 Mar 2015 03:09:08 +0000 Received: from 172.24.2.119 (EHLO szxeml431-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CIQ37367; Wed, 18 Mar 2015 11:08:56 +0800 (CST) Received: from [127.0.0.1] (10.111.68.57) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.158.1; Wed, 18 Mar 2015 11:08:47 +0800 Message-ID: <5508EC3B.6080701@huawei.com> Date: Wed, 18 Mar 2015 03:09:00 -0000 From: Zhang Zhen User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: Andreas Schwab CC: Yao Qi , , Subject: Re: The return address of strtok is out of bounds in gdb References: <5507E977.2030003@huawei.com> <86k2yfg9yi.fsf@gmail.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-CFilter-Loop: Reflected X-SW-Source: 2015-03/txt/msg00061.txt.bz2 On 2015/3/17 19:26, Andreas Schwab wrote: > Yao Qi 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. >