public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Help with cross-compiling GDB
@ 2012-10-08 20:01 Paul Smith
  2012-10-09 19:30 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Smith @ 2012-10-08 20:01 UTC (permalink / raw)
  To: gdb

Hi all.  I'm trying to create a complete toolchain including GCC,
binutils, plus tools like make, fakeroot, bison, flex, m4, and of course
GDB.

What I need to do is have the tools compiled to be able to run on much
older GNU/Linux distributions, even though my build system is very
recent.  So I have a cross-compiler built that uses a sysroot from an
older distribution and I'm using that to compile GDB.  I need to be able
to compile and debug both 32bit and 64bit programs.  Originally I wanted
to have a 32bit version of GDB which could debug both, but that doesn't
appear to be possible.  That's OK, I'm willing to have GDB be a 64bit
application, or else I'll build GDB twice.  For now I'm just trying to
get the 64bit GDB working.

So, I configure GDB with something like this:

  ./configure --disable-nls --disable-werror --prefix=/tmp/invalid/generic \
    --host=x86_64-olddist-linux-gnu --target=x86_64-generic-linux-gnu \
    --with-sysroot=/tmp/invalid/sysroot/generic/sysroot --enable-64-bit-bfd \
    --enable-tui --with-expat --without-python \
    --program-prefix=x86_64-generic-linux-gnu-

So this builds fine, but when I try to debug something I always get
errors:

$ ./obj/cc/generic/bin/x86_64-generic-linux-gnu-gdb foo
GNU gdb (GDB) 7.5
    ...
This GDB was configured as "--host=x86_64-olddist-linux-gnu
--target=x86_64-generic-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from foo...done.

(gdb) run
Starting program: foo 
Don't know how to run.  Try "help target".

(gdb) show arch
The target architecture is set automatically (currently i386)
(gdb) set arch
Requires an argument. Valid arguments are i386, i386:x86-64, i386:x64-32, i8086,
i386:intel, i386:x86-64:intel, i386:x64-32:intel, auto.


This is a 32bit app but I get identical errors (although different show
arch of course) when I try to debug a 64bit app.  I can set breakpoints,
etc. but any attempt to run gives the "don't know how to run" error.

I'm not sure exactly what that means in this context.  It appears to
have the right architecture and that architecture appears to be
supported.  So what does GDB need from me?

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

* Re: Help with cross-compiling GDB
  2012-10-08 20:01 Help with cross-compiling GDB Paul Smith
@ 2012-10-09 19:30 ` Pedro Alves
  2012-10-09 20:19   ` Paul Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2012-10-09 19:30 UTC (permalink / raw)
  To: psmith; +Cc: gdb

On 10/08/2012 09:01 PM, Paul Smith wrote:
> Hi all.  I'm trying to create a complete toolchain including GCC,
> binutils, plus tools like make, fakeroot, bison, flex, m4, and of course
> GDB.
> 
> What I need to do is have the tools compiled to be able to run on much
> older GNU/Linux distributions, even though my build system is very
> recent.  So I have a cross-compiler built that uses a sysroot from an
> older distribution and I'm using that to compile GDB.  I need to be able
> to compile and debug both 32bit and 64bit programs.  Originally I wanted
> to have a 32bit version of GDB which could debug both, but that doesn't
> appear to be possible.  That's OK, I'm willing to have GDB be a 64bit
> application, or else I'll build GDB twice.  For now I'm just trying to
> get the 64bit GDB working.
> 
> So, I configure GDB with something like this:
> 
>   ./configure --disable-nls --disable-werror --prefix=/tmp/invalid/generic \
>     --host=x86_64-olddist-linux-gnu --target=x86_64-generic-linux-gnu \

with --host != --target, you're configuring a cross debugger.  IOW, the
native debug support isn't included (gdb_native in configure.ac).

> (gdb) run
> Starting program: foo 
> Don't know how to run.  Try "help target".

And this means exactly that -- gdb doesn't know how to "run" with the
current target (none or just the executable), and there's no native target
support to default to.  The suggestion kind of hints at connecting with
"target remote" first, for example.

> This is a 32bit app but I get identical errors (although different show
> arch of course) when I try to debug a 64bit app.  I can set breakpoints,
> etc. but any attempt to run gives the "don't know how to run" error.
> 
> I'm not sure exactly what that means in this context.  It appears to
> have the right architecture and that architecture appears to be
> supported.  So what does GDB need from me?

IIUC, you want to use --build to point at x86_64-olddist-linux-gnu,
not --host.

-- 
Pedro Alves

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

* Re: Help with cross-compiling GDB
  2012-10-09 19:30 ` Pedro Alves
@ 2012-10-09 20:19   ` Paul Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Smith @ 2012-10-09 20:19 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb

On Tue, 2012-10-09 at 20:30 +0100, Pedro Alves wrote:
> with --host != --target, you're configuring a cross debugger.  IOW, the
> native debug support isn't included (gdb_native in configure.ac).

Yes; figured it out yesterday thanks!

> IIUC, you want to use --build to point at x86_64-olddist-linux-gnu,
> not --host.

Actually no, FYI.  The --build value should almost never be set
in ./configure.  It specifies the type of host that you're building on
and that should always be auto-detected correctly.  The only time you'd
ever use it is if configure can't determine the correct value itself for
some reason, I suppose.

Here I want to set the --host value (which specifies the system on which
the program will be run).  But I don't want to set the --target value
(or equivalently, I want the --target value to be the same as the --host
value; if you don't specify --target then it defaults to the value of
--host), because I want to debug code on the same target as I'm running
on.


I got it working now, thanks!

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

end of thread, other threads:[~2012-10-09 20:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-08 20:01 Help with cross-compiling GDB Paul Smith
2012-10-09 19:30 ` Pedro Alves
2012-10-09 20:19   ` Paul Smith

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).