为什么gdb认为我的x86-64程序是i386?

为什么gdb认为我的x86-64程序是i386?,gdb,x86-64,freepascal,fpc,Gdb,X86 64,Freepascal,Fpc,我试图调试一个64位程序,但gdb似乎认为它有一个i386架构 # file /usr/local/bin/foo /usr/local/bin/foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped # gdb --args foo bar GNU gdb (GDB) 7.3.1 Cop

我试图调试一个64位程序,但gdb似乎认为它有一个i386架构

# file /usr/local/bin/foo
/usr/local/bin/foo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.4.0, not stripped


# gdb --args foo bar
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/foo...done.
(gdb) set debug arch 1
(gdb) show debug arch
Architecture debugging is 1.
(gdb) info target
Symbols from "/usr/local/bin/foo".
Local exec file:
gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0xaf4a90
gdbarch_find_by_info: info.tdep_info 0x0
gdbarch_find_by_info: Previous architecture 0xb05790 (i386:x86-64) selected
    `/usr/local/bin/foo', file type elf64-x86-64.
    Entry point: 0x419730
    0x00000000004001c8 - 0x00000000004001e4 is .interp
    0x00000000004001e4 - 0x0000000000400204 is .note.ABI-tag
    0x0000000000400208 - 0x0000000000402560 is .hash
    0x0000000000402560 - 0x0000000000409898 is .dynsym
    0x0000000000409898 - 0x0000000000411188 is .dynstr
    0x0000000000411188 - 0x0000000000411b22 is .gnu.version
    0x0000000000411b28 - 0x0000000000411b88 is .gnu.version_r
    0x0000000000411b88 - 0x00000000004181a0 is .rela.dyn
    0x00000000004181a0 - 0x0000000000418e78 is .rela.plt
    0x0000000000418e78 - 0x0000000000418e90 is .init
    0x0000000000418e90 - 0x0000000000419730 is .plt
    0x0000000000419730 - 0x00000000004ede38 is .text
    0x00000000004ede38 - 0x00000000004ede46 is .fini
    0x00000000004ede48 - 0x00000000004ede4c is .eh_frame
    0x00000000006ee000 - 0x00000000006ee010 is .ctors
    0x00000000006ee010 - 0x00000000006ee020 is .dtors
    0x00000000006ee020 - 0x00000000006ee028 is .jcr
    0x00000000006ee028 - 0x00000000006ee1f8 is .dynamic
    0x00000000006ee1f8 - 0x00000000006f07f0 is .got
    0x00000000006f07f0 - 0x00000000006f0c50 is .got.plt
    0x00000000006f0c50 - 0x0000000000736c70 is .data
    0x0000000000736c70 - 0x000000000073b420 is .bss
(gdb) start
Temporary breakpoint 1 at 0x419e70: file foo.lpr, line 69.
Starting program: /usr/local/bin/foo bar
warning: Selected architecture i386:x86-64 is not compatible with reported target architecture i386
gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0xaf4a90
gdbarch_find_by_info: info.tdep_info 0x0
gdbarch_find_by_info: Target rejected architecture
gdbarch_update_p: Architecture not found
warning: Architecture rejected target-supplied description
gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0xd6ce90
gdbarch_find_by_info: info.tdep_info 0x0
gdbarch_find_by_info: Previous architecture 0xb05790 (i386:x86-64) selected
Error in re-setting breakpoint 1: Cannot access memory at address 0x419e60
Error in re-setting breakpoint 1: Cannot access memory at address 0x419e60
process 5299 is executing new program: /usr/local/bin/foo
warning: Selected architecture i386:x86-64 is not compatible with reported target architecture i386
gdbarch_find_by_info: info.bfd_arch_info i386:x86-64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0xb21790
gdbarch_find_by_info: info.tdep_info 0x0
gdbarch_find_by_info: Target rejected architecture
Architecture of file not recognized.
然后:

gdbarch_find_by_info: Target rejected architecture
gdbarch_update_p: Architecture not found
warning: Architecture rejected target-supplied description
在gdb中,如果我键入“set architecture”并点击tab,我会看到以下内容:

(gdb) set architecture 
auto               i386:intel         i386:x64-32:intel  i386:x86-64:intel  
i386               i386:x64-32        i386:x86-64        i8086
我的问题是:为什么gdb认为我的文件有i386架构,尽管它显然是x86-64二进制文件,我可以做些什么来修复它

我的程序是用2.6.0版编译的

更新:
在我的Ubuntu12.04机器(带有3.2.0-31内核)上,使用相同的gdb二进制和相同的freepascal二进制,我没有收到任何警告。我试图调试的服务器正在运行2.6.34.10-24内核。内核或服务器中可能存在会影响gdb的错误配置吗?

您的问题从这里开始:

gdbarch_按_信息查找:目标拒绝架构

这意味着GDB中依赖于目标的代码不喜欢
i386:x86-64
体系结构。不幸的是,没有简单的方法来判断它不喜欢什么——您必须调试GDB本身才能找到答案


你能在GDB失败的机器上调试其他二进制文件(例如,
/bin/date
)吗?

这个二进制文件是如何编译的?!还是编译后手工编辑的?@DavidSchwartz我刚刚更新了这个问题。它是使用FreePascal 2.6.0编译的。我投票决定关闭它,因为它太本地化了,因为我认为这个问题是由于我运行的平台造成的。它是基于Linux的,但不是一个标准发行版,因此我认为这个问题不会对其他人有任何好处。是的,我可以调试/bin/date,但在所讨论的系统上它是32位的。32位应用程序工作正常。我在调试GDB本身时看到了相同的消息。
(gdb) set architecture 
auto               i386:intel         i386:x64-32:intel  i386:x86-64:intel  
i386               i386:x64-32        i386:x86-64        i8086