Re: Debugging 64-bit programs using 32-bit GDB

Pedro Alves <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
On 07/24/2013 05:09 PM, Doug Evans wrote:
> On Wed, Jul 24, 2013 at 7:33 AM, Pedro Alves <[email protected]> wrote:
>> On 07/09/2013 11:06 AM, Nikita Karetnikov wrote:
>>> Is it possible to debug a 64-bit executable ('bin/guile' [1]) using
>>> 32-bit GDB?  (I use GNU/Linux.)
>>
>> I don't think so.  The ptrace registers interfaces allow retrieving
>> the right register sets (at least the modern interfaces), but
>> things like breakpoints, etc. won't work, as the 32-bit GDB won't
>> be able to handle the inferior's 64-bit addresses (due to how ptrace
>> works).  Last I checked, Power had extra ptrace interfaces for that.
>> Don't know about MIPS.
>>
>> (you can however connect a 32-bit GDB to a 64-bit GDBserver, and use
>> that to debug a 64-bit program, though that's more trouble
>> than just using a 64-bit GDB.).
>>
>>>
>>> I've tried to configure GDB 7.6 with '--enable-64-bit-bfd' (see [2]),
>>> but it still shows "mips-tdep.c:709: internal-error: bad register
>>> size".
>>
>> The x86_64 port catches the case early and bails out (amd64_linux_read_description):
>>
>>   if (sizeof (void *) == 4 && is_64bit && !is_x32)
>>     error (_("Can't debug 64-bit process with 32-bit GDB"));
> 
> [filed for reference sake]
> 
> Alas basic 32-bit linux builds of gdb don't compile amd64-linux-nat.c.
> It would be really nice to print a better error message than the
> following for 32-bit gdb debugging 64-bit executable:
> 
> "/tmp/hello.x64": not in executable format: File format not recognized
> 
> It's a not uncommon failure mode.

Agree, but not sure how much clearer can it get.  Maybe:

 "/tmp/hello.x64": not in recognized executable file format.

?

I'd just suggest building 32-bit GDB with 64-bit support.  Even if
it can't debug 64-bit programs natively, it can remote debug
them, and debug 64-bit cores, in addition to getting rid of that
failure mode.

> Hmmm, amd64-linux-nat.c is not compiled even if I do
> --enable-targets=all --enable-64-bit-bfd.

Oh, you're right, of course.  Guess I was thinking of gdbserver,
where linux-x86.c is shared between 32-bit and 64-bit, and it has
the similar handling:

  if (sizeof (void *) == 4)
    {
      if (is_elf64 > 0)
       error (_("Can't debug 64-bit process with 32-bit GDBserver"));
#ifndef __x86_64__
      else if (machine == EM_X86_64)
       error (_("Can't debug x86-64 process with 32-bit GDBserver"));
#endif
    }

Two weeks vacation can swap out a lot of context.  :-)

> When does the above error get triggered?

Looks like it doesn't.

-- 
Pedro Alves
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.