我正在开发一个 Qt 项目,并已将 Qt 从他们的安装程序安装到我的计算机上。在 Visual Studio 中调试 Qt 源代码很简单:当我在未知文件中输入一个函数时,它会打开一个文件浏览器让我找到原始 Qt 源代码。
Xcode 或 LLDB 中是否有等效的函数?
最佳答案
调试信息记录了QT源文件在构建时的位置。您可以通过执行以下操作找到此信息:
(lldb) image lookup -va main
Address: hello[0x0000000100000f40] (hello.__TEXT.__text + 0)
Summary: hello`main at hello.c:5
Module: file = "/private/tmp/hello", arch = "x86_64"
CompileUnit: id = {0x00000000}, file = "/tmp/hello.c", language = "ISO C:1999"
Function: id = {0x00000026}, name = "main", range = [0x0000000100000f40-0x0000000100000f6d)
FuncType: id = {0x00000026}, decl = hello.c:4, clang_type = "int (void)"
Blocks: id = {0x00000026}, range = [0x100000f40-0x100000f6d)
LineEntry: [0x0000000100000f40-0x0000000100000f56): /tmp/hello.c:5
Symbol: id = {0x00000004}, range = [0x0000000100000f40-0x0000000100000f6d), name="main"
但用一些 QT 函数代替“main”。然后查看 CompileUnit 行并查看"file"条目的内容。假设它说
"/BuildDirectory/sources/SomeSubdirectory/SomeFile.cpp"
现在大概您已经下载了 QT 源代码,它们位于您本地计算机的某个位置,比如
"/Users/ME/QT/sources"
所以你想要做的是告诉 lldb:“当你看到根目录在/BuildDirectory/sources 的源文件时,请改为查看/Users/ME/QT/sources。”您可以使用 lldb“target.source-map”设置来做到这一点。在这个例子中,你会说:
(lldb) settings set target.source-map /BuildDirectory/sources /Users/ME/QT/sources
您可以在命令行中键入它或将其放入您的 .lldbinit 文件中以供更一般的使用。 lldb 将自动更新其源映射,但如果您在 Xcode 中运行,则必须在发出命令后执行一次步骤以使其更新。
关于Xcode 相当于 Visual Studio 的 "Find Source",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25376333/