很高兴在macos中使用gdb

时间:2015-12-04 02:59:47

标签: c++ linux macos makefile gdb

我总是在Linux中使用gdb,它运行正常,这是我第一次在mac中使用gdb,这与Linux不同。

(gdb) b main
Breakpoint 1 at 0x100000ec4
(gdb) r
Starting program: /Users/vinllen/code/tmp/lhm/homework
warning: Could not open OSO archive file "/BinaryCache/corecrypto/corecrypto-233.1.2~26/Symbols/BuiltProducts/libcorecrypto_static.a"
warning: `/BinaryCache/coreTLS/coreTLS-35.20.2~10/Objects/coretls.build/coretls.build/Objects-normal/x86_64/system_coretls_vers.o': can't open to read symbols: No such file or directory.
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.20.2~10/Symbols/BuiltProducts/libcoretls_ciphersuites.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.20.2~10/Symbols/BuiltProducts/libcoretls_handshake.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.20.2~10/Symbols/BuiltProducts/libcoretls_record.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.20.2~10/Symbols/BuiltProducts/libcoretls_stream_parser.a"

Breakpoint 1, 0x0000000100000ec4 in main ()
(gdb) l
No symbol table is loaded.  Use the "file" command.
(gdb) n
Single stepping until exit from function main,
which has no line number information.

看起来命令 l n 无法正确执行,有什么问题?

这是我的Makefile:

objects = main.o conversion.o slitemlist.o uims.o testdrivers.o

homework:$(objects)
    g++ -o homework $(objects)

conversion.o: conversion.h base.h
slitemlist.o: slitemlist.h base.h
uims.o: conversion.h base.h conversion.h slitemlist.h
testdrivers.o: testdrivers.h

.PHONY: clean
clean:
    rm homework $(objects)

1 个答案:

答案 0 :(得分:0)

  

这是我的Makefile:

在Linux上调试这个程序也很愉快:你编译它没有调试符号(-g标志)。

你真正的问题不是“我如何在MacOS上使用GDB”,而是“如何编写Makefile以便我可以调试”。

您应该在Makefile

中添加这样的行
CFLAGS = -g
CXFLAGS = -g  # if building C++