public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
@ 2010-06-18  6:58 Jerry 85032
  2010-06-18 16:36 ` Michael Snyder
  2010-06-19  3:25 ` Ulrich Weigand
  0 siblings, 2 replies; 5+ messages in thread
From: Jerry 85032 @ 2010-06-18  6:58 UTC (permalink / raw)
  To: gdb


So I am new to using gdb and gdbserver.  And I'm trying to use it on a pretty
complex program.  But that's okay, I can't get it to run on a simple system,
so let's talk about that.

I created the usual c++ Hello World.  I have access to two identical Centos
5 development systems connected with tcp.

#include <iostream>
int main(int argc, char *argv[])
{
    std::cout << "Hello World." << std::endl;
    return -1;

}


If I compile my hello world with:

$ g++ -g hello.cpp -o hello

Then everything works pretty much as expected.  I can run it on either
system.  I can use gdb on one system, connect to gdbserver on the other
system, and everything seems to work fine.  I set a break at main on my
local system, gdbserver the program on the target, use gdb to tell it to
run, and Hello World prints out on the gdbserver system.

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"

$ cat /etc/redhat-release 
CentOS release 5.4 (Final)

Can someone help clue me in?

Thank you
-- 
View this message in context: http://old.nabble.com/Newbie-gdb---gdbserver-question-with-x86-64-and--m32-g%2B%2B-goodness-tp28922383p28922383.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
  2010-06-18  6:58 Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness Jerry 85032
@ 2010-06-18 16:36 ` Michael Snyder
  2010-06-18 18:26   ` Jerry 85032
  2010-06-19  3:25 ` Ulrich Weigand
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Snyder @ 2010-06-18 16:36 UTC (permalink / raw)
  To: Jerry 85032; +Cc: gdb

Jerry 85032 wrote:
> So I am new to using gdb and gdbserver.  And I'm trying to use it on a pretty
> complex program.  But that's okay, I can't get it to run on a simple system,
> so let's talk about that.
> 
> I created the usual c++ Hello World.  I have access to two identical Centos
> 5 development systems connected with tcp.
> 
> #include &lt;iostream&gt;
> int main(int argc, char *argv[])
> {
>     std::cout << "Hello World." << std::endl;
>     return -1;
> 
> }
> 
> 
> If I compile my hello world with:
> 
> $ g++ -g hello.cpp -o hello
> 
> Then everything works pretty much as expected.  I can run it on either
> system.  I can use gdb on one system, connect to gdbserver on the other
> system, and everything seems to work fine.  I set a break at main on my
> local system, gdbserver the program on the target, use gdb to tell it to
> run, and Hello World prints out on the gdbserver system.
> 
> 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.

I believe you need to give the "set architecture" command
before the "target remote" command.  This should work...


> 
> 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"
> 
> $ cat /etc/redhat-release 
> CentOS release 5.4 (Final)
> 
> Can someone help clue me in?
> 
> Thank you

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
  2010-06-18 16:36 ` Michael Snyder
@ 2010-06-18 18:26   ` Jerry 85032
  2010-06-18 18:47     ` Michael Snyder
  0 siblings, 1 reply; 5+ messages in thread
From: Jerry 85032 @ 2010-06-18 18:26 UTC (permalink / raw)
  To: gdb



Michael Snyder-6 wrote:
> 
> Jerry 85032 wrote:
>> So I am new to using gdb and gdbserver.  And I'm trying to use it on a
>> pretty
>> complex program.  But that's okay, I can't get it to run on a simple
>> system,
>> so let's talk about that.
>> 
>> I created the usual c++ Hello World.  I have access to two identical
>> Centos
>> 5 development systems connected with tcp.
> ... 
>> If I compile my hello world with:
>> 
>> $ g++ -g hello.cpp -o hello
>> 
>> Then everything works pretty much as expected.  I can run it on either
>> system.  I can use gdb on one system, connect to gdbserver on the other
>> system, and everything seems to work fine.  I set a break at main on my
>> local system, gdbserver the program on the target, use gdb to tell it to
>> run, and Hello World prints out on the gdbserver system.
>> 
>> 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.
> 
> I believe you need to give the "set architecture" command
> before the "target remote" command.  This should work...
> 
> 

Thanks for the response.  But I tried to follow your suggestions, and still
I'm not seeing it work.  If you have any more suggestions, I am certainly
interested in hearing them.

Thanks,

Jerry

Here are three runs:
==============================

For each run, the remote gdbserver said:

$ gdbserver --multi rdev6:2010 hello
Process hello created; pid = 32603
Listening on port 2010
Remote debugging from host 134.51.26.149
readchar: Got EOF
Remote side has terminated connection.  GDBserver will reopen the
connection.
Listening on port 2010

And on our local:

==============================
Assuming it is i386, 32 bit setting archi to i386, then connecting
note: on the gdb side, the executable hasn't been specified or loaded

$ gdb
GNU gdb Fedora (6.8-37.el5)
his GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386
The target architecture is assumed to be i386
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
warning: Selected architecture i386 is not compatible with reported target
architecture i386:x86-64
Remote register badly formatted:
T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
Try to load the executable by `file' first,
you may also check `set/show architecture'.
(gdb) 

==============================

Assuming it is i386 32 bit, setting archi to i386, then connecting
note: on the gdb side, the executable has been loaded with file

$ gdb
GNU gdb Fedora (6.8-37.el5)
his GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386
The target architecture is assumed to be i386
(gdb) file hello
Reading symbols from /home/j/hello...done.
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
warning: Selected architecture i386 is not compatible with reported target
architecture i386:x86-64
Remote register badly formatted:
T0506:0000000000000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
here: 0000000;07:b0dcdfff00000000;10:1018620000000000;thread:7f5b;
Try to load the executable by `file' first,
you may also check `set/show architecture'.
(gdb) sho archi
The target architecture is assumed to be i386
(gdb) 

==============================

Assuming it is i386:x86-64, setting archi to i386, then connecting
note: on the gdb side, the executable has been loaded with file

$ gdb 
GNU gdb Fedora (6.8-37.el5)
This GDB was configured as "x86_64-redhat-linux-gnu".
(gdb) set archi i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) file hello
Reading symbols from /home/j/hello...done.
(gdb) show archi
The target architecture is assumed to be i386:x86-64
(gdb) target extended-remote rdev6:2010
Remote debugging using rdev6:2010
[New Thread 32667]
Cannot access memory at address 0x800000008
(gdb) 



-- 
View this message in context: http://old.nabble.com/Newbie-gdb---gdbserver-question-with-x86-64-and--m32-g%2B%2B-goodness-tp28922383p28929351.html
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
  2010-06-18 18:26   ` Jerry 85032
@ 2010-06-18 18:47     ` Michael Snyder
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Snyder @ 2010-06-18 18:47 UTC (permalink / raw)
  To: Jerry 85032; +Cc: gdb


> ==============================
> 
> Assuming it is i386:x86-64, setting archi to i386, then connecting
> note: on the gdb side, the executable has been loaded with file
> 
> $ gdb 
> GNU gdb Fedora (6.8-37.el5)
> This GDB was configured as "x86_64-redhat-linux-gnu".
> (gdb) set archi i386:x86-64
> The target architecture is assumed to be i386:x86-64
> (gdb) file hello
> Reading symbols from /home/j/hello...done.
> (gdb) show archi
> The target architecture is assumed to be i386:x86-64
> (gdb) target extended-remote rdev6:2010
> Remote debugging using rdev6:2010
> [New Thread 32667]
> Cannot access memory at address 0x800000008
> (gdb) 

This is the closest to success.  So use this "set archi" setting.

At this point you are running into a second failure:

	Cannot access memory at address 0x800000008

I don't know what that one is about.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness
  2010-06-18  6:58 Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness Jerry 85032
  2010-06-18 16:36 ` Michael Snyder
@ 2010-06-19  3:25 ` Ulrich Weigand
  1 sibling, 0 replies; 5+ messages in thread
From: Ulrich Weigand @ 2010-06-19  3:25 UTC (permalink / raw)
  To: Jerry 85032; +Cc: gdb

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-06-19  3:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-18  6:58 Newbie gdb / gdbserver question with x86-64 and -m32 g++ goodness 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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).