简体   繁体   中英

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

I'm working from an example in a book, where the author writes a short, flawed C program to demonstrate debugging with 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;
}

After compiling with gcc -g program.c , he runs gdb ./a.out and calls run from within gdb. When it hits the flaw in the program, he calls,

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

When I try the same, I get,

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

I did some digging and it sounds like the fact that I'm only being shown the memory address is related to the message beneath about "Current language".

I compiled and ran the above C program like so,

❯ 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 then outputs a bunch of lines about unsupported "indirect" references,

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

...followed by warnings about not being able to find object files (all of which look related to 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

...then finally it stops at the expected (flawed) line of the program:

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];

I'm on OS X Yosemite, with the following versions of gcc and 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".

What do I need to do to get GDB to recognize this as a C program?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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