【问题标题】:Hot to use gdb in macos在 macOS 中使用 gdb 很热门
【发布时间】:2015-12-04 02:59:46
【问题描述】:

我总是在 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.

命令ln好像不能正确执行,请问是什么问题?

这是我的 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)

【问题讨论】:

  • 我建议在 OS X 上使用 lldb。官方的 gdb 从未完全支持 OS X,Apple 的 gdb 已停产。我猜这些警告与您的问题有关。
  • 看起来我应该添加额外的参数-g,但是应该把这个参数放在哪里。
  • 感谢 Alexander,lldb 中的命令是否与 gdb 相同?
  • 有些相同,有些不同。 lldb.llvm.org/lldb-gdb.html

标签: c++ linux macos makefile gdb


【解决方案1】:

这是我的 Makefile:

您将在 Linux 上调试此程序很愉快:您编译它时没有调试符号(-g 标志)。

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

您应该在Makefile 中添加这样的行:

CFLAGS = -g
CXFLAGS = -g  # if building C++

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 2023-03-05
    相关资源
    最近更新 更多