From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12238 invoked by alias); 19 Jun 2010 03:25:49 -0000 Received: (qmail 12162 invoked by uid 22791); 19 Jun 2010 03:25:48 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,MSGID_FROM_MTA_HEADER,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate4.de.ibm.com (HELO mtagate4.de.ibm.com) (195.212.17.164) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 19 Jun 2010 03:25:42 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate4.de.ibm.com (8.13.1/8.13.1) with ESMTP id o5J3Pdab021556 for ; Sat, 19 Jun 2010 03:25:39 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5J3PdTF1114184 for ; Sat, 19 Jun 2010 05:25:39 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o5J3PdGb031726 for ; Sat, 19 Jun 2010 05:25:39 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id o5J3PcjC031715; Sat, 19 Jun 2010 05:25:38 +0200 Message-Id: <201006190325.o5J3PcjC031715@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Sat, 19 Jun 2010 05:25:38 +0200 Subject: Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness To: jerry85032@gmail.com (Jerry 85032) Date: Sat, 19 Jun 2010 03:25:00 -0000 From: "Ulrich Weigand" Cc: gdb@sourceware.org In-Reply-To: <28922383.post@talk.nabble.com> from "Jerry 85032" at Jun 17, 2010 11:58:26 PM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2010-06/txt/msg00077.txt.bz2 > But if I compile it with -m32, and repeat the process, then the two systems > seem to be fighting over architecture issues. I receive messages like > register badly formatted. Or "warning: Selected architecture i386 is not > compatible with reported target architecture i386:x86-64". This seems to > happen regardless of how I tell gdb to set the architecture, either i386 or > i386:x86-64. > > g++ -g -m32 hello.cpp -o hello > > So I gather much of my problem is because I'm ignorant. And I don't really > understand what -m32 does, although I know our hideously complex system IS > compiled that way. > > Apart from that, I am using: > > $ g++ --version > g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46) > > $ gdbserver --version > GNU gdbserver Fedora (6.8-37.el5) > This gdbserver was configured as "x86_64-redhat-linux-gnu" On Linux on x86-64, the compiler will by default generate binaries for the (64-bit) x86-64 architecture. However, if you use the -m32 command line argument, you tell the compiler to generate binaries for the (32-bit) i386 architecture instead. As the operating system will transparently execute binaries for either of the two architectures, and also GDB will debug either in native mode, you probably don't see much difference. However, the *gdbserver* version you are using can only operate on binaries of the x86-64 architecture, it simply will not work with i386 binaries. In fact, the message above arises because gdbserver tells gdb that the target process is 64-bit (which it does because this is hard-coded as the only architecture this version of gdbserver ever supports), but gdb notices that the executable file it is looking at itself is 32-bit, and thus does not match the reported target process architecture. To fix this, you can do either of the following: 1. Install a separate 32-bit gdbserver on the target machine, e.g. from the i386 CentOS build. Whenever you want to debug a 32-bit application, you'll need to use this new gdbserver; whenever you want to debug a 64-bit application, you'll need to use your current gdbserver. Note that you can always use the same 64-bit gdb on the host side. 2. Upgrade gdbserver to a recent version (i.e. 7.1), e.g. from a recent Fedora. This version supports both 32-bit and 64-bit process debugging in a single gdbserver binary, just like gdb does. Bye, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com