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

问题描述 投票:0回答:2

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

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

我尝试将 Qt5 源添加到项目中,而不将其添加到我的可执行目标中,但 Xcode/lldb 仍然无法“看到”源或发现我添加到项目中的源文件是相同的源Qt 调试符号中引用的文件。

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

编辑:

只是为了在这里添加更多细节,当我在 Xcode/lldb 控制台中输入“目标模块查找 -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 ed\Downloads\qt5-everywhere-src-5.3.2\qtcore\src\qmenubar.cpp (或任何位置),然后 Visual Studio 假设其他源可能位于附近。

这如何与 Xcode 配合使用?

c++ c xcode qt lldb
2个回答
2
投票

我想我已经找到了问题的答案,但实际上只会引发更多问题。请参阅 Xcode 相当于 Visual Studio 的“查找源”

我在想,也许我的程序或我的 Qt 构建没有有符号,或者符号少于必要的符号。特别是,这是链接 SO 问题中

target modules lookup --address <address> --verbose
的输出(
image
target modules
的 lldb 同义词):

  (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 网页上“LLDB 调试器”的示例 (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 构建系统并找出这些符号的去向。


0
投票

我在尝试进入 Qt 源代码时遇到了类似的问题。我的项目使用的是预构建的、剥离的二进制文件,不包含源代码。

我解决这个问题的方法是在我的机器上从here构建Qt-everywhere源代码(记住使用调试标志进行配置),并将我的项目指向这些二进制文件。然后 Xcode / lldb 就能够找到调试源了。

>(lldb) image lookup -vn QWidget::showFullScreen
1 match found in /path/to/framework/libQt6Widgets_debug.6.7.0.dylib:
        Address: libQt6Widgets_debug.6.7.0.dylib[0x00000000000b0dc4] (libQt6Widgets_debug.6.7.0.dylib.__TEXT.__text + 700576)
        Summary: libQt6Widgets_debug.6.7.0.dylib`QWidget::showFullScreen() at qwidget.cpp:3033
         Module: file = "/path/to/framework/libQt6Widgets_debug.6.7.0.dylib", arch = "arm64"
    CompileUnit: id = {0x00000000}, file = "/path/to/sources/qt-everywhere-src-6.7.0/qtbase/src/widgets/kernel/qwidget.cpp", language = "c++14"
       Function: id = {0x120012e0cf}, name = "QWidget::showFullScreen()", mangled = "_ZN7QWidget14showFullScreenEv", range = [0x0000000107a90dc4-0x0000000107a90e84)
       FuncType: id = {0x120012e0cf}, byte-size = 0, decl = qwidget.h:489, compiler_type = "void (void)"
         Blocks: id = {0x120012e0cf}, range = [0x107a90dc4-0x107a90e84)
      LineEntry: [0x0000000107a90dc4-0x0000000107a90ddc): /path/to/sources/qt-everywhere-src-6.7.0/qtbase/src/widgets/kernel/qwidget.cpp:3033
         Symbol: id = {0x00014866}, range = [0x0000000107a90dc4-0x0000000107a90e84), name="QWidget::showFullScreen()", mangled="_ZN7QWidget14showFullScreenEv"
       Variable: id = {0x120012e0ea}, name = "this", type = "QWidget *", valid ranges = <block>, location = DW_OP_fbreg -8, decl = 

使用此方法时会包含 CompileUnit 信息。似乎预构建的 Qt 二进制文件以某种方式被剥离了。

© www.soinside.com 2019 - 2024. All rights reserved.