gpt4 book ai didi

c++ - 在 Xcode 中,如何使用您拥有源代码的外部库进行调试?

转载 作者:太空狗 更新时间:2023-10-29 21:41:13 25 4
gpt4 key购买 nike

我在 Xcode 中为 OS X 构建了一个大型 C/C++/Objective-C 项目。该项目链接到预构建的 Qt5 库。

一切都很好,直到出现崩溃,我得到了一个包含 Qt 函数的堆栈跟踪。如果我单击其中一个 Qt 函数的堆栈帧,Xcode/lldb 会显示程序集而不是源代码——我将 Qt 用作外部库,因此我的项目中没有任何 Qt 源代码。我怎样才能解决这个问题?

我已经尝试将 Qt5 源代码添加到项目中而不将其添加到我的可执行目标中,但是 Xcode/lldb 仍然没有“看到”源代码或弄清楚我添加到项目中的源文件是Qt 调试符号中引用的相同源文件。

我如何告诉 Xcode/lldb 在哪里可以找到我正在使用的外部库的源代码?

编辑:

只是在这里添加更多细节,当我在 Xcode/lldb 控制台中键入“target modules lookup -t QMenuBar”时,这就是我所看到的:

Best match found in /Users/ted/Documents/Projects/XXX/_build_osx/Output/Debug/XXX.app/Contents/MacOS/XXX:
id = {0x7100042d49}, name = "QMenuBar", byte-size = 48, decl = qmenubar.h:57, clang_type = "class QMenuBar : public QWidget {
static const QMetaObject staticMetaObject;
virtual const QMetaObject *metaObject() const;
virtual void *qt_metacast(const char *);
static QString tr(const char *, const char *, int);
static QString trUtf8(const char *, const char *, int);
virtual int qt_metacall(QMetaObject::Call, int, void **);
static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
explicit QMenuBar(QWidget *);
virtual void ~QMenuBar();
QAction *addAction(const QString &);
QAction *addAction(const QString &, const QObject *, const char *);
QAction *addMenu(QMenu *);
QMenu *addMenu(const QString &);
QMenu *addMenu(const QIcon &, const QString &);
QAction *addSeparator();
QAction *insertSeparator(QAction *);
QAction *insertMenu(QAction *, QMenu *);
void clear();
QAction *activeAction() const;
void setActiveAction(QAction *);
void setDefaultUp(bool);
bool isDefaultUp() const;
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
virtual int heightForWidth(int) const;
QRect actionGeometry(QAction *) const;
QAction *actionAt(const QPoint &) const;
void setCornerWidget(QWidget *, Qt::Corner);
QWidget *cornerWidget(Qt::Corner) const;
NSMenu *toNSMenu();
bool isNativeMenuBar() const;
void setNativeMenuBar(bool);
QPlatformMenuBar *platformMenuBar();
virtual void setVisible(bool);
void triggered(QAction *);
void hovered(QAction *);
virtual void changeEvent(QEvent *);
virtual void keyPressEvent(QKeyEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
virtual void mousePressEvent(QMouseEvent *);
virtual void mouseMoveEvent(QMouseEvent *);
virtual void leaveEvent(QEvent *);
virtual void paintEvent(QPaintEvent *);
virtual void resizeEvent(QResizeEvent *);
virtual void actionEvent(QActionEvent *);
virtual void focusOutEvent(QFocusEvent *);
virtual void focusInEvent(QFocusEvent *);
virtual void timerEvent(QTimerEvent *);
virtual bool eventFilter(QObject *, QEvent *);
virtual bool event(QEvent *);
void initStyleOption(QStyleOptionMenuItem *, const QAction *) const;
QMenuBarPrivate *d_func();
const QMenuBarPrivate *d_func() const;
QMenuBar(const QMenuBar &);
QMenuBar &operator=(const QMenuBar &);
}"

很明显,我的可执行文件中包含某种符号。它说这个定义来自 qmenubar.h。我的硬盘驱动器上某处有 qmenubar.h - 我如何告诉 Xcode/lldb 在哪里可以找到它?

在 Windows 中的 Visual Studio 中,如果我单击堆栈跟踪中没有 Visual Studio 可以轻松找到的源的帧,VS 会弹出一个窗口,要求我浏览源文件 - 从那时起, Visual Studio 似乎根据您浏览的源代码的位置凭直觉判断其余源代码的位置。例如,如果我有一个包含 QMenuBar::focusInEvent() 的堆栈跟踪,然后我单击它,Visual Studio 会询问我 qmenubar.cpp 在哪里。我可以浏览到 C:\Users\ted\Downloads\qt5-everywhere-src-5.3.2\qtcore\src\qmenubar.cpp(或任何位置),然后 Visual Studio 假设其他来源可能位于附近。

这如何与 Xcode 一起工作?

最佳答案

我想我已经找到了问题的答案,但它实际上只会引出更多问题。参见 Xcode equivalent of Visual Studio's "Find Source" .

我在想,也许我的程序或我的 Qt 构建没有有符号,或者符号比必要的少。特别是,这里是 target modules lookup --address <address> --verbose 的输出( imagetarget modules 的 lldb 同义词)在那个链接的 SO 问题中:

  (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"

这是来自 LLVM 网页“The LLDB Debugger”(http://lldb.llvm.org/symbolication.html)的示例:

>(lldb) image lookup --address 0x100123aa3 --verbose
Address: a.out[0x0000000100000aa3] (a.out.__TEXT.__text + 110)
Summary: a.out`main + 50 at main.c:13
Module: file = "/tmp/a.out", arch = "x86_64"
CompileUnit: id = {0x00000000}, file = "/tmp/main.c", language = "ISO C:1999"
Function: id = {0x0000004f}, name = "main", range = [0x0000000100000bc0-0x0000000100000dc9)
FuncType: id = {0x0000004f}, decl = main.c:9, clang_type = "int (int, const char **, const char **, const char **)"
Blocks: id = {0x0000004f}, range = [0x100000bc0-0x100000dc9)
id = {0x000000ae}, range = [0x100000bf2-0x100000dc4)
LineEntry: [0x0000000100000bf2-0x0000000100000bfa): /tmp/main.c:13:23
Symbol: id = {0x00000004}, range = [0x0000000100000bc0-0x0000000100000dc9), name="main"
Variable: id = {0x000000bf}, name = "path", type= "char [1024]", location = DW_OP_fbreg(-1072), decl = main.c:28
Variable: id = {0x00000072}, name = "argc", type= "int", location = r13, decl = main.c:8
Variable: id = {0x00000081}, name = "argv", type= "const char **", location = r12, decl = main.c:8
Variable: id = {0x00000090}, name = "envp", type= "const char **", location = r15, decl = main.c:8
Variable: id = {0x0000009f}, name = "aapl", type= "const char **", location = rbx, decl = main.c:8

这是我的 Qt5Widgets QMenuBar 地址的输出:

(lldb) image lookup --address 0x103058d57 --verbose
Address: libQt5Widgets_debug.5.dylib[0x000000000026dd57] (libQt5Widgets_debug.5.dylib.__TEXT.__text + 2525127)
Summary: libQt5Widgets_debug.5.dylib`QMenuBar::actionEvent(QActionEvent*) + 711
Module: file = "/Users/ted/Documents/Projects/work/third_party/qt/5.3.2/osx/x86_64/lib/libQt5Widgets_debug.5.dylib", arch = "x86_64"
Symbol: id = {0x0000c190}, range = [0x0000000103058a90-0x0000000103059260), name="QMenuBar::actionEvent(QActionEvent*)", mangled="_ZN8QMenuBar11actionEventEP12QActionEvent"

确认!源文件 (CompileUnit) 引用在哪里?感谢@vsoftco 的建议以及看到此问题的任何其他人。我将不得不深入研究 Qt5 构建系统并找出这些符号的去向。

关于c++ - 在 Xcode 中,如何使用您拥有源代码的外部库进行调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29477206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com