I have a large-ish C/C++/Objective-C project building for OS X in Xcode. The project links to pre-built Qt5 libraries.
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?
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.
How do I tell Xcode/lldb where to find the source for an external library that I'm working with?
EDIT:
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 &);
}"
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?
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.
How does this work with Xcode?
CONFIG += debug
in your.pro
file. Also, related: forum.qt.io/topic/24972/… – Callipygian