From owner-svn-src-all@freebsd.org Wed Dec 14 01:31:12 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D7782C755B2; Wed, 14 Dec 2016 01:31:12 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B7009182C; Wed, 14 Dec 2016 01:31:12 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by mail.baldwin.cx (Postfix) with ESMTPSA id BCAD610AA56; Tue, 13 Dec 2016 20:31:10 -0500 (EST) From: John Baldwin To: src-committers@freebsd.org Cc: svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r310045 - head/sys/ddb Date: Tue, 13 Dec 2016 17:25:42 -0800 Message-ID: <2285301.DAKmd1GIbI@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.0-PRERELEASE; KDE/4.14.10; amd64; ; ) In-Reply-To: <201612140018.uBE0ICrE004686@repo.freebsd.org> References: <201612140018.uBE0ICrE004686@repo.freebsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Tue, 13 Dec 2016 20:31:10 -0500 (EST) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2016 01:31:12 -0000 On Wednesday, December 14, 2016 12:18:12 AM John Baldwin wrote: > Author: jhb > Date: Wed Dec 14 00:18:12 2016 > New Revision: 310045 > URL: https://svnweb.freebsd.org/changeset/base/310045 > > Log: > Use casts to force an unsigned comparison in db_search_symbol(). > > On all of our platforms, db_expr_t is a signed integer while > db_addr_t is an unsigned integer value. db_search_symbol used variables > of type db_expr_t to hold the current offset of the requested address from > the "best" symbol found so far. This value was initialized to '~0'. > When a new symbol is found from a symbol table, the associated diff for the > new symbol is compared against the existing value as 'if (newdiff < diff)' > to determine if the new symbol had a smaller diff and was thus a closer > match. > > On 64-bit MIPS, the '~0' was treated as a negative value (-1). A lookup > that found a perfect match of an address against a symbol returned a diff > of 0. However, in signed comparisons, 0 is not less than -1. As a result, > DDB on 64-bit MIPS never resolved any addresses to symbols. Workaround > this by using casts to force an unsigned comparison. I am somewhat unsure of why this worked on other architectures. amd64 treated ~0 as 0xffffffff which when assigned to a 64-bit register was zero-extended. i386 also used 0xffffffff, but it used an unsigned comparison (jae instead of jge). The kernel linker API returns an unsigned long for the diff, so I do think using db_addr_t for this type is probably the right solution in the long term. > Probably the diff returned from db_search_symbol() and X_db_search_symbol() > should be changed to a db_addr_t instead of a db_expr_t as it is an > unsigned value (and is an offset of an address, so should fit in the same > size as an address). Also, in case it wasn't clear, this fixes resolution of addresses to names in MIPS64 stack traces in DDB as well as when using 'x', etc. -- John Baldwin