Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: jerry85032@gmail.com (Jerry 85032)
Cc: gdb@sourceware.org
Subject: Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
Date: Sat, 19 Jun 2010 03:25:00 -0000	[thread overview]
Message-ID: <201006190325.o5J3PcjC031715@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <28922383.post@talk.nabble.com> from "Jerry 85032" at Jun 17, 2010 11:58:26 PM

> 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


      parent reply	other threads:[~2010-06-19  3:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-18  6:58 Jerry 85032
2010-06-18 16:36 ` Michael Snyder
2010-06-18 18:26   ` Jerry 85032
2010-06-18 18:47     ` Michael Snyder
2010-06-19  3:25 ` Ulrich Weigand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201006190325.o5J3PcjC031715@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb@sourceware.org \
    --cc=jerry85032@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox