在Xcode中,如何使用外部库来调试你的源代码? [英] In Xcode, how to debug with external libraries that you have the source for?

查看:475
本文介绍了在Xcode中,如何使用外部库来调试你的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a large-ish C/C++/Objective-C project building for OS X in Xcode. The project links to pre-built Qt5 libraries.

这一切都很好,直到事情崩溃,我得到一个堆栈跟踪与Qt函数。如果我单击一个Qt函数的堆栈框架,Xcode / lldb显示汇编而不是源 - 我使用Qt作为外部库,所以我没有任何Qt源在我的项目。如何解决这个问题?

That all works very nicely, until something crashes and I get a stack trace with Qt functions in it. If I click on the stack frame for one of the Qt functions, Xcode/lldb displays assembly rather than source - I'm using Qt as an external library, so I don't have any of the Qt source in my project. How can I fix this?

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

I've tried adding the Qt5 source to the project without adding it to my executable target, but Xcode/lldb still doesn't 'see' the source or figure out that the source files that I added to the project are the same source files referenced in the Qt debug symbols.

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

How do I tell Xcode/lldb where to find the source for an external library that I'm working with?

编辑:

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

Just to add a bit more detail here, when I type 'target modules lookup -t QMenuBar' in the Xcode/lldb console, this is what I see:

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在哪里可以找到它?

Clearly my executable has some sort of symbols in it. It's saying that this definition came from qmenubar.h. I have qmenubar.h on my hard drive somewhere - how do I tell Xcode/lldb where to find it?

在Visual Studio在Windows ,如果我点击堆栈跟踪中没有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然后假设

In Visual Studio in Windows, if I click on a frame in the stack trace that doesn't have source that Visual Studio can easily find, VS pops up a window asking me to browse for the source file - from then on, Visual Studio seems to intuit where the rest of the source is based on the location of the source you browsed for. For example, if I had a stack trace with QMenuBar::focusInEvent() in it, and I clicked on it, Visual Studio would ask me where qmenubar.cpp is. I could browse to C:\Users\ted\Downloads\qt5-everywhere-src-5.3.2\qtcore\src\qmenubar.cpp (or wherever it is) and Visual Studio then assumes that other sources might be located nearby.

推荐答案

我认为我找到了我的问题的答案,但它实际上只是导致更多的问题。请参见与Visual Studio的查找来源等效的Xcode

I think I've found the answer to my question, but it actually just leads to more questions. See Xcode equivalent of Visual Studio's "Find Source".

我想我的程序或我的Qt 构建不会有符号或少于必要的符号。特别是,这里是目标模块查找的输出 - 地址< address> --verbose image 目标模块的lldb同义词)问题:

I'm thinking that perhaps my program or my build of Qt doesn't have symbols, or fewer symbols than is necessary. In particular, here's the output of target modules lookup --address <address> --verbose (image is a lldb synonym for target modules) in that linked SO question:

  (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调试器上LLVM网页的示例( http://lldb.llvm.org/symbolication.html ):

here's an example from the LLVM webpage on "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地址的输出:

and here's the output of my Qt5Widgets QMenuBar address:

(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构建系统,并找出这些符号去哪里。

Ack! Where's the source file (CompileUnit) reference? Thanks to @vsoftco for the suggestion and anyone else who saw this question. I'm going to have to dig a bit into the Qt5 build system and figure out where those symbols went.

这篇关于在Xcode中,如何使用外部库来调试你的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆