繁体   English   中英

GDB为什么不识别我的C程序的语言?

[英]Why doesn't GDB recognize the language of my C program?

我正在写一本书中的示例,作者在其中编写了一个简短的,有缺陷的C程序,以演示如何使用GDB进行调试。

#include <stdio.h>

int main (void)
{
    const int data[5] = {1, 2, 3, 4, 5};
    int i, sum;

    for (i = 0; i >= 0; ++i)
        sum += data[i];

    printf ("sum = %i\n", sum);

    return 0;
}

gcc -g program.c编译后,他运行gdb ./a.out并从gdb内部run调用。 当程序出现问题时,他打电话说,

(gdb) print data
$1 = {1, 2, 3, 4, 5}

当我尝试相同时,我得到

(gdb) print data
$1 = 0x100000f80
Current language:  auto; currently minimal

我做了一些挖掘,这听起来像是我只看到内存地址与下面有关“当前语言”的消息有关。

我像这样编译并运行了上面的C程序,

❯ gcc -g program.c
❯ gdb ./a.out
Reading symbols for shared libraries .. done
(gdb) run
Starting program: /Users/ivan/Development/books/c/programming-in-c/a.out

然后,GDB输出一堆关于不受支持的“间接”引用的行,

Reading symbols for shared libraries +..............bfd_mach_o_scan_read_symtab_symbol: symbol "_bzero" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memccpy" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memchr" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memcmp" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memcpy" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memmove" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_memset" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_strchr" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_strcmp" is unsupported 'indirect' reference: setting to undefined
bfd_mach_o_scan_read_symtab_symbol: symbol "_strncmp" is unsupported 'indirect' reference: setting to undefined

...之后是关于无法找到目标文件的警告(所有看起来与ssl / tls有关的警告):

...warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Objects/coretls.build/coretls.build/Objects-normal/x86_64/system_coretls_vers.o" - no debug information available for "system_coretls_vers.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_ciphersuites.a(tls_ciphersuites.o)" - no debug information available for "tls_ciphersuites.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslSession.o)" - no debug information available for "sslSession.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslCipherSpecs.o)" - no debug information available for "sslCipherSpecs.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslDigests.o)" - no debug information available for "sslDigests.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslCrypto.o)" - no debug information available for "sslCrypto.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslChangeCipher.o)" - no debug information available for "sslChangeCipher.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslCert.o)" - no debug information available for "sslCert.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslKeyExchange.o)" - no debug information available for "sslKeyExchange.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslAlertMessage.o)" - no debug information available for "sslAlertMessage.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslHandshake.o)" - no debug information available for "sslHandshake.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslHandshakeFinish.o)" - no debug information available for "sslHandshakeFinish.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(tls1Callouts.o)" - no debug information available for "tls1Callouts.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(sslHandshakeHello.o)" - no debug information available for "sslHandshakeHello.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(tls_handshake.o)" - no debug information available for "tls_handshake.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a(ssl3Callouts.o)" - no debug information available for "ssl3Callouts.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(tls1RecordCallouts.o)" - no debug information available for "tls1RecordCallouts.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(ssl3RecordCallouts.o)" - no debug information available for "ssl3RecordCallouts.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(tls_record.o)" - no debug information available for "tls_record.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(sslRc4Cipher.o)" - no debug information available for "sslRc4Cipher.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(sslMemory.o)" - no debug information available for "sslMemory.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(sslUtils.o)" - no debug information available for "sslUtils.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(symCipherParams.o)" - no debug information available for "symCipherParams.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(sslNullCipher.o)" - no debug information available for "sslNullCipher.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(symCipher.o)" - no debug information available for "symCipher.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(tls_digest.o)" - no debug information available for "tls_digest.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(tls_hashhmac.o)" - no debug information available for "tls_hashhmac.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a(tls_hmac.o)" - no debug information available for "tls_hmac.c".
warning: Could not find object file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_stream_parser.a(tls_stream_parser.o)" - no debug information available for "tls_stream_parser.c".
....................... done

...然后最终它停止在程序的预期行(有缺陷的行):

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100006000
0x0000000100000f1e in main () at prog.18.4.c:9
9                       sum += data[i];

我在OS X Yosemite上,具有以下版本的gcc和gdb:

❯ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

❯ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Wed Feb  6 22:51:23 UTC 2013)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

我需要做些什么才能使GDB将其识别为C程序?

您必须使用-g选项编译并链接程序,以包含调试信息,例如函数和变量名,源语言和位置...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM