From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37862 invoked by alias); 17 Mar 2015 11:26:41 -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 37846 invoked by uid 89); 17 Mar 2015 11:26:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 17 Mar 2015 11:26:39 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4345AABB2; Tue, 17 Mar 2015 11:26:36 +0000 (UTC) From: Andreas Schwab To: Yao Qi Cc: Zhang Zhen , , Subject: Re: The return address of strtok is out of bounds in gdb References: <5507E977.2030003@huawei.com> <86k2yfg9yi.fsf@gmail.com> X-Yow: Where's the Coke machine? Tell me a joke!! Date: Tue, 17 Mar 2015 11:26:00 -0000 In-Reply-To: <86k2yfg9yi.fsf@gmail.com> (Yao Qi's message of "Tue, 17 Mar 2015 11:05:57 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2015-03/txt/msg00060.txt.bz2 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, > > 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."