我总是在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)
最佳答案
这是我的Makefile:
在Linux上调试这个程序也不会很愉快:编译它时没有调试符号(标志-g
)。
你真正的问题不是“如何在MacOS上使用GDB”,而是“如何编写Makefile以便调试”。
您应该在Makefile
中添加这样的行:
CFLAGS = -g
CXFLAGS = -g # if building C++
关于c++ - 热门在macOS中使用gdb,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34080178/